无法在CentOS7上构建32位库

Unable to build 32bit library on Centos7

本文关键字:构建 32位库 CentOS7      更新时间:2023-10-16

我有具有'devtoolset-7'的centos7 vagrant框。

我使用" 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

/opt/opt/rh/devToolset-7/root/usr/libexec/libexec/gcc/x86_64-redhat-linux/7/ld:跳过/opt/opt/opt/rh/devtoolset-7/root/usr/usr/lib/lib/lib/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

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