Aks*_*til 0 c linux mongoose-web-server
简介: - (GCC版本4.6.3,OS-Ubuntu 12.04,解决mongoose Web服务器程序,所以当我运行"make"命令来编译和安装mongoose时,它完成了任务很好).
[问题的第1部分] 这个问题是关于stackowerflow的这篇文章.
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:~$
Run Code Online (Sandbox Code Playgroud)
[问题的第2部分]
现在,我在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
Run Code Online (Sandbox Code Playgroud)
另外,当我在不使用libmongoose.so的情况下编译时,我继续得到^^错误
[编辑]:在gcc上添加-pthread选项,仍然显示错误: - mongoose.o:在函数load_dll':
mongoose.c:(.text+0xa955): undefined reference todlopen'mongoose.c :(.text + 0xa9b4)中:未定义引用`dlsym'colle2:ld返回1退出状态
对于我的问题的第1部分和第2部分:我想摆脱这些错误并成功运行hello.c程序示例.提前致谢 .
小智 5
该-L选项不用于链接库,它用于指定动态库的搜索路径.要链接特定库,请使用-l.但是,你并不需要对双方的联系mongoose.o和libmongoose.so,任何一个就足够了.
在Linux上,您还必须链接到pthread和动态加载库,因为尽管它们是C标准库的一部分,但它们并不存在libc.so.还有一件需要注意的事情是,最近版本的binutils(特别是ld)需要按照符号相互依赖的顺序指定库和目标文件,即库必须到命令行的末尾.
总而言之,请使用以下命令之一:
gcc -o hello hello.o mongoose.o -ldl -lpthread
Run Code Online (Sandbox Code Playgroud)
要么
gcc -L. -o hello hello.o -lmongoose -ldl -lpthread
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2948 次 |
| 最近记录: |