[英]Undefined reference to 'dlsym'
我看過很多類似的帖子,但在書中嘗試了每一個技巧,我仍然在苦苦掙扎。 一切都工作正常,但在安裝/刪除wireshark與一些組件/解析器后,它們都搞砸了。 我不記得確切地卸載了哪些庫/軟件包,但可能比我注意到的要多得多。
如果我像這樣創建一個簡單的main.cpp文件:
#include <SQLAPI.h>
int main()
{
SAConnection con;
return 0;
}
並嘗試
g ++ main.cpp -lsqlapi -ldl
它給我以下錯誤消息:
/usr/local/lib/libsqlapi.so: undefined reference to `dlsym'
/usr/local/lib/libsqlapi.so: undefined reference to `dlerror'
/usr/local/lib/libsqlapi.so: undefined reference to `dlopen'
/usr/local/lib/libsqlapi.so: undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
我試圖在-lsqlapi之前放-ldl,因為有些人認為訂單很重要。 如果我使用gcc而不是g ++,錯誤是:
/usr/bin/ld: /tmp/ccwBI4tj.o: undefined reference to symbol '__gxx_personality_v0@@CXXABI_1.3'
/usr/lib/x86_64-linux-gnu/libstdc++.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
如果刪除了SAConnection,我可以編譯並運行該文件。
我不認為它與SQLAPI有任何關系,因為我遇到了與libboost類似的問題。 我沒有一個小代碼示例,但是當我編譯上周成功編譯的項目時,我得到錯誤:
/usr/bin/ld: debug/components/helloworld/HelloWorld.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.53.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
這個項目正在使用一個未更改的Makefile,因此它必須是我的系統上不正確的東西。 我試圖重新安裝build-essential。
使用Ubuntu 64位13.10和g ++版本4.8.1。
我找到了解決方案; 在-ldl之前設置-Wl, - no-as-needed新的編譯命令是
gcc main.cpp -lsqlapi -lstdc ++ -Wl, - no-as-needed -ldl
顯然它與最近版本的gcc / ld默認與--as-needed鏈接有關。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.