简短介绍:-(GCC 版本 4.6.3,OS-Ubuntu 12.04,围绕 mongoose Web 服务器程序工作,所以当我运行“make”命令编译和安装 mongoose 时,它已经完成了任务)。
[问题的第 1 部分] 这个问题参考了 stackowerflow 上的这篇文章。
mongoose web 服务器 helloworld 程序
Valenok 通过提供 hello 示例程序的链接来回答这篇文章。
基本上,我正在尝试编译此链接上给出的示例 hello 程序代码:-
http://code.google.com/p/mongoose/source/browse/examples/hello.c
并将这段代码放在已经编译好的 mongoose 目录中。(目录有 mongoose.h 文件)
以下是我编译 hello 程序的命令行输出。
akshay@akshay-Inspiron-N5010:~$ 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
akshay@akshay-Inspiron-N5010:~$
[问题的第二部分]
现在,我在 mongoose.c 文件中找到了 mg_stop、mg_start、mg_printf 和 mg_get_request_info 的实现,所以我使用 -c 选项编译 mongoose.c 文件:gcc -c -o mongoose.o mongoose.c
我认为我的问题类似于:-
但是当我在 gcc 上将 libmongoose.so 与 -L 选项链接时,出现以下错误:-(libmongoose.so 存在于同一目录中,我的 cwd)
akshay@akshay-Inspiron-N5010:~/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: 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
对于我的问题的第 1 部分和第 2 部分:我想摆脱这些错误并成功运行 hello.c 程序示例。提前致谢 。