【问题标题】:Unable to build 32bit library on Centos7无法在 Centos7 上构建 32 位库
【发布时间】:2019-10-03 16:27:40
【问题描述】:

我有 Centos7 Vagrant 盒子,里面有 'devtoolset-7'。

我使用“CMake”来构建和编译我的库。这是 CMakeLists.txt 文件

set(CMAKE_BUILD_TYPE Release)
include_directories("../Include" "/usr/include/libusb-1.0")
add_library(CXIOInterface SHARED 
        CXIOInterface.cpp
        HidInterface_Linux.cpp
        HidDevice_Linux.cpp
        ../Include/Debug.cpp
        app.cpp
        CrcLibrary.cpp
        ContextFunctions.cpp)
set(PROJECT_LINK_LIBS -ludev -lusb-1.0)
target_link_libraries(CXIOInterface LINK_PUBLIC ${PROJECT_LINK_LIBS})
set(CMAKE_CXX_FLAGS "-m32")

当我将它编译为 64 位时,一切正常。但是当我将它编译为 32 位时,我收到错误消息:

/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: skipping incompatible /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/libstdc++_nonshared.a when searching for -lstdc++_nonshared
/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld: cannot find -lstdc++_nonshared
collect2: error: ld returned 1 exit status
make[2]: *** [CXIOInterface/libCXIOInterface.so] Error 1 

你们能帮帮我吗,我无法理解这里该怎么做。

已经有一个链接告诉我安装 rpm,但我是 ubuntu 用户而不是 Centos。第一次使用。

https://www.centos.org/forums/viewtopic.php?t=64011

【问题讨论】:

  • 您需要较旧的开发工具集。尝试在 Centos 中使用默认的 g++ 5.x 进行编译(scl disable devtoolset)。无论如何,您都可以使用 yum 安装 rpm 包。
  • 我说 source scl_source disable devtoolset-7 并运行 make 命令,它给出了同样的错误
  • 能否显示yum repolistrpm -qa | grep devtoolset的输出

标签: c++ linux cmake centos centos7


【解决方案1】:

/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/ld:跳过不兼容的/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64 -redhat-linux/7/libstdc++_nonshared.a 时搜索 -lstdc++_nonshared

表示链接器找到的库与 ABI 不兼容,在这种情况下,它不兼容 32 位。

发生这种情况是因为您缺少所需的包,就像您添加的链接状态一样。

首先,找出你安装的devtoolset的当前版本:

rpm -qa | grep devtoolset-7

从输出中,您应该能够轻松确定您现在使用的版本。

然后,尝试运行:

yum install devtoolset-7-libstdc++-devel-7.2.1-1.el7.x86_64.rpm

注意:我使用的是 7.2.1-1,因为这是我在 Google 中搜索时发现的,如果您安装了其他版本,请改用它。

【讨论】:

  • 我收到以下错误:没有包 devtoolset-7-libstdc++-devel-7.2.1-1.el7.x86_64.rpm 可用。
  • 如何知道我应该安装什么版本
猜你喜欢
  • 2012-11-26
  • 1970-01-01
  • 2014-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-18
  • 2015-09-14
  • 2021-11-18
相关资源
最近更新 更多