Fw: [問題] dlopen load shared object seg fault

看板LinuxDev作者 (~ SNSD & KARA ~ )時間6年前 (2018/02/12 01:30), 6年前編輯推噓1(102)
留言3則, 3人參與, 6年前最新討論串1/1
※ [本文轉錄自 C_and_CPP 看板 #1QW7qvs9 ] 作者: antirazin (~ SNSD & KARA ~ ) 看板: C_and_CPP 標題: [問題] dlopen load shared object seg fault 時間: Mon Feb 12 01:28:21 2018 開發平台(Platform): (Ex: Win10, Linux, ...) CentOS 7 (VMware) 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) g++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 手邊有一個.so檔,想透過dlopen使用裡面的function, 雖然編譯過了,但是執行時出現segmentation fault。 初步排錯,改餵/usr/lib64下的內建library的.so沒問題, 這樣是表示這.so檔有問題嗎? 但我用nm print是沒問題的。 目前沒什麼頭緒,因此在這邊請教各位大大了 m(_ _)m 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 執行後Segmentation fault 程式碼(Code):(請善用置底文網頁, 記得排版) #include <iostream> #include <dlfcn.h> int main(int argc, const char * argv[]) { void* func = dlopen("/home/test/libtest.so", RTLD_LAZY); //隨便換成內建的 /usr/lib64/libz.so.1.2.7 的話就能跑完 if (!func) { std::cerr << "Cannot load library: " << dlerror() << '\n'; return 1; } return 0; } 補充說明(Supplement): --

10/11 21:45,
其中這男子為什麼在對方說不後 仍強行撫摸對方下體
10/11 21:45

10/11 21:46,
而裡面有沒有什麼秘密? 好!我們今天也請到了五位來賓
10/11 21:46

10/11 21:46,
皓平:其實馬雅人早就預言到了
10/11 21:46

皓平 我還沒叫到你
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.24.151.163 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1518370105.A.D89.html ※ 發信站: 批踢踢實業坊(ptt.cc) ※ 轉錄者: antirazin (114.24.151.163), 02/12/2018 01:30:16

02/12 07:50, 6年前 , 1F
貼程式和結果
02/12 07:50, 1F
晚上回去會補上 ※ 編輯: antirazin (125.227.2.182), 02/12/2018 10:36:37 ※ 編輯: antirazin (114.24.189.45), 02/12/2018 22:21:35 ※ 編輯: antirazin (114.24.189.45), 02/12/2018 22:23:14

02/15 07:40, 6年前 , 2F
你的.so檔是怎麼產生,感覺是toolchain不一樣所導致的
02/15 07:40, 2F

02/22 09:47, 6年前 , 3F
用 file 先查一下 mime ?
02/22 09:47, 3F
後來編譯時我加上-L/home/test -ltest 時出現 /home/test/libtest.so: 未定義的參考到「SSL_connect」 /home/test/libtest.so: 未定義的參考到「TLSv1_client_method」 /home/test/libtest.so: 未定義的參考到「SSL_CTX_set_verify」 /home/test/libtest.so: 未定義的參考到「SSL_CTX_check_private_key」 /home/test/libtest.so: 未定義的參考到「SSL_get_peer_certificate」 發現可能是openssl沒有安裝的關係, 安裝完並且在編譯時加上-lssl -lcrypto 編譯過了但執行時出現錯誤: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory 看起來executable找不到libssl, 所以我再加上-Wl,-rpath,/usr/local/lib 執行就正常了! 還是謝謝各位大大的意見~ ※ 編輯: antirazin (114.24.156.179), 02/25/2018 22:20:05
文章代碼(AID): #1QW7sgPh (LinuxDev)