簡短介紹: - (GCC版本4.6.3,OS-Ubuntu 12.04,解決貓鼬網絡服務器程序,所以當我運行「make」命令編譯和安裝貓鼬,它已經完成了任務)。我無法編譯這個貓鼬網絡服務器的示例代碼
[問題的第一部分] 這個問題是參考這個帖子在stackowerflow。
mongoose web server helloworld program
Valenok已經通過給一個鏈接到Hello示例程序回答了這個職位。
基本上,我試圖編譯此鏈接中給出的示例招呼程序代碼: - 。
http://code.google.com/p/mongoose/source/browse/examples/hello.c
,並把這個代碼在貓鼬的已編譯的目錄(目錄中有mongoose.h文件)
以下是用於編譯hello程序的命令行輸出。
[email protected]:~$ gcc mongoose/hello.c -o mongoose/hello
/tmp/ccroC5Z6.o: In function `callback':
hello.c:(.text+0x32): undefined reference to `mg_get_request_info'
hello.c:(.text+0x96): undefined reference to `mg_printf'
/tmp/ccroC5Z6.o: In function `main':
hello.c:(.text+0xee): undefined reference to `mg_start'
hello.c:(.text+0x103): undefined reference to `mg_stop'
collect2: ld returned 1 exit status
[email protected]:~$
[問題的第2部分]
現在,我發現mg_stop,mg_start,mg_printf和mongoose.c文件mg_get_request_info的實現,所以我編譯-c選項爲mongoose.c文件: 的gcc -o -c mongoose.o mongoose.c
我想我的問題是相似的: -
undefined reference to function declared in *.h file
但後來當我在GCC libmongoose.so與-L選項鍊接我收到以下錯誤: - (libmongoose.so存在於同一個目錄,我的CWD)
[email protected]:~/mongoose$ gcc -L libmongoose.so -o hello hello.o mongoose.o
mongoose.o: In function `mg_start_thread':
mongoose.c:(.text+0x1369): undefined reference to `pthread_create'
mongoose.o: In function `load_dll':
mongoose.c:(.text+0xa955): undefined reference to `dlopen'
mongoose.c:(.text+0xa9b4): undefined reference to `dlsym'
collect2: ld returned 1 exit status
也,我繼續得到^^誤差以上當我編譯而不使用libmongoose.so
[編輯]:上的gcc加入-pthread選項,仍顯示錯誤: - mongoose.o:在功能load_dll': mongoose.c:(.text+0xa955): undefined reference to
的dlopen」 mongoose.c :(.text + 0xa9b4):未定義的引用'dlsym' collect2:ld返回1退出狀態
對於我的問題的第1部分和第2部分:我想擺脫這些錯誤併成功運行hello.c程序示例。 在此先感謝。
@ H2CO3非常感謝!你提到的第一個命令工作正常。 但對於第二個命令出現以下錯誤 當我通過./hello運行它: - 「錯誤而載入共享庫:libmongoose.so:無法打開共享對象文件:沒有這樣的文件或目錄‘’ –
@AkshayPatil是,這就是它的工作原理,請閱讀一下動態加載。 – 2012-12-28 10:28:52
好的!再次感謝 –