无法链接“.o”目标文件

时间:2017-07-20 07:09:39

标签: c++ linux linker linker-errors

我对我当前的C ++ Linux项目有疑问。 我正在构建源代码并将其链接(IDE是QtCreator)到供应商提供的.o(非.lib)文件。 在构建源文件时,似乎everythig很好,但是当我到达链接时,命令行输出表明许多未定义的引用错误。 这是使用过的cli及其输出:

arm-nobuos-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/opt/nobu-x11/4.1.15-1.1.1/sysroots/cortexa9hf-vfp-neon-nobuos-linux-gnueabi -c -pipe  -O2 -pipe -g -feliminate-unused-debug-types -g -DLINUX=1 -Wall -W -D_REENTRANT -fPIC -DQT_QML_DEBUG -DQT_CORE_LIB -I../qt_selexes_test2 -I. -isystem /opt/nobu-x11/4.1.15-1.1.1/sysroots/cortexa9hf-vfp-neon-nobuos-linux-gnueabi/usr/include -isystem /opt/nobu-x11/4.1.15-1.1.1/sysroots/cortexa9hf-vfp-neon-nobuos-linux-gnueabi/usr/include/qt5 -isystem /opt/nobu-x11/4.1.15-1.1.1/sysroots/cortexa9hf-vfp-neon-nobuos-linux-gnueabi/usr/include/qt5/QtCore -I. -I/opt/nobu-x11/4.1.15-1.1.1/sysroots/cortexa9hf-vfp-neon-nobuos-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++ -o moc_mrs_flasher.o moc_mrs_flasher.cpp
arm-nobuos-linux-gnueabi-g++  -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 --sysroot=/opt/nobu-x11/4.1.15-1.1.1/sysroots/cortexa9hf-vfp-neon-nobuos-linux-gnueabi -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -o qt_selexes_test2 main.o dcan.o moc_dcan.o moc_mrs_flasher.o   /SviluppoCodice/parodi/SW/updateAnalogCan_Wurth/qt_selexes_test2_20170511/qt_selexes_test2/mrs_flasher.o -lQt5Core -lpthread 
main.o: In function `main':
main.cpp:26: undefined reference to `mrs_flasher::scan_module_wait(long, int, int, unsigned char&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
main.cpp:37: undefined reference to `mrs_flasher::select_module(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'
main.cpp:41: undefined reference to `mrs_flasher::download_s19_wait(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)'

查看.o文件似乎:

  • 编译器的目标机器是相同的(通过调用我的cpp文件和供应商提供的文件生成的.o文件上的命令文件,它们都生成以下输出“ ELF 32位LSB可重定位,ARM,EABI5版本1(SYSV),未剥离

  • .o文件包含未定义的引用对象(我使用命令 strings mrs_flasher.o | grep scan_module_wait 以搜索 “对mrs_flasher :: scan_module_wait的未定义引用”命令输出为:

  

scan_module_wait

     

_ZN11mrs_flasher16scan_module_waitEliiRhRSs

     

_ZN11mrs_flasher16scan_module_waitEliiRhRSs   )

是否有人可以帮助我进一步调查此问题?有什么东西可以发布,以帮助面对问题? 谢谢Giovanni

1 个答案:

答案 0 :(得分:1)

解释是供应商提供的目标文件 - 我猜是/SviluppoCodice/parodi/SW/updateAnalogCan_Wurth/qt_selexes_test2_20170511/qt_selexes_test2/mrs_flasher.o - 没有使用您使用的相同编译器或与ABI兼容的编译器编译。

您可以从您的编译器发出调用:

的事实中看到这一点
mrs_flasher::scan_module_wait(long, int, int, unsigned char&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&)

而您的目标文件定义了错位符号:

_ZN11mrs_flasher16scan_module_waitEliiRhRSs

哪个消解为:

$ c++filt _ZN11mrs_flasher16scan_module_waitEliiRhRSs
mrs_flasher::scan_module_wait(long, int, int, unsigned char&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)

请注意,编译器请求的函数具有类型的第四个参数:

std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&

而目标文件定义的那个具有不同类型的第四个参数:

std::basic_string<char, std::char_traits<char>, std::allocator<char> >&

因此函数签名不匹配,链接器找不到您的函数的定义 编译器调用。

两个功能签名之间的区别:

std::__cxx11::basic_string

std::basic_string

告诉我们你的编译器编译成C++11 ABI, 与GCC 5.1一起介绍,但构建目标文件的编译器没有。

最有可能的原因是您的提供商使用GCC&lt; 5.1。您无法链接此对象 使用您的编译器构建的文件 - 除非您想要为过时的ABI构建自己的代码,我假设您没有。您应该让您的提供商提供符合的新提供商 C ++ 11 ABI。

相关问题