2017-07-20 74 views
1

我對當前的C++ Linux項目有疑問。 我正在構建源代碼並將其鏈接(IDE是QtCreator)到供應商提供的.o(不是.lib)文件。 在構建源文件時,似乎everythig很好,但是當達到鏈接時間時,命令行輸出顯示很多未定義的引用錯誤。 下面是使用CLI和它的輸出:無法鏈接「.o」目標文件

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爲了搜索 「未定義參考`mrs_flasher :: scan_module_wait」 scan_module_wait命令輸出是:

scan_module_wait

_ZN11mrs_flasher16scan_module_waitEliiRhRSs

_ZN11mrs_flasher16scan_module_waitEliiRhRSs )

有沒有人可以幫助我進一步調查此問題?有什麼我可以發佈以幫助解決問題? 謝謝喬瓦尼

回答

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 

其中demangles爲:

$ 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 < 5.1構建了目標文件。除非你想建立自己的代碼陳舊ABI,我以爲你不這樣做 - 這個對象 文件與您的編譯器內置那些你無法鏈接。你應該讓你的供應商提供一個新的,符合 的C++ 11 ABI。

+0

謝謝麥克,我會給一個嘗試將舊ABI辦法(爲了驗證供應商庫)。 然後,我會問他用我的編譯器重建的.o。 現在我已經明白如何在QTCreator使用舊的ABI – Giox79