gcc / g ++参数顺序 [英] gcc/g++ parameter order

查看:216
本文介绍了gcc / g ++参数顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚在新的ubuntu 12.10服务器上编译了chironfs,并得到以下错误:

  gcc -Wall -W -Wmissing -prototypes -g -O2 -DFUSE_USE_VERSION = 25 -D_FILE_OFFSET_BITS = 64 -I / usr / local / include -g -O2 -lm -lfuse -o chironfs chironfs.o chiron-conf.o chirondbg.o chironfn.o 
chironfs.o:在函数`chiron_init'中:
/root/chironfs-1.1.1/src/chironfs.c:2000:对`pthread_create'的未定义引用
chironfs.o:在函数`get_rights_by_name ':
/root/chironfs-1.1.1/src/chironfs.c:452:对`fuse_get_context'的未定义引用

pthread错误告诉我-lpthread丢失了,但是保险丝错误有点奇怪,因为-lfuse正在被使用



我发现解决方案此处建议放置图书馆在对象文件之后



所以我删除了-lfuse并添加了-lfuse -lpth阅读最后一行



现在它编译时没有错误,它看起来应该是这样的:库在目标文件之后



我的问题是:
为什么参数顺序与gcc / ld相关?我希望gcc只是像其他应用程序一样解析参数,并且可能会将必要的参数转发给ld或其他类似的

:任何人都知道gcc参数排序的事实或提示,或许有点背景
有关为什么需要这种方式的信息?

谢谢

解决方案

对象和库的顺序与链接器相关(编译器在创建可执行文件时隐式调用)。当链接器在其从左到右的扫描中找到一个不知道它的名称的用法时,它就开始从这一点开始寻找一个定义 。如果定义通过,它不会记住它以备后用。


i just compiled chironfs on my new ubuntu 12.10 server and got the following error:

gcc  -Wall -W -Wmissing-prototypes -g -O2 -DFUSE_USE_VERSION=25 -D_FILE_OFFSET_BITS=64 -I/usr/local/include -g -O2 -lm -lfuse  -o chironfs chironfs.o chiron-conf.o chirondbg.o chironfn.o  
chironfs.o: In function `chiron_init':
/root/chironfs-1.1.1/src/chironfs.c:2000: undefined reference to `pthread_create'
chironfs.o: In function `get_rights_by_name':
/root/chironfs-1.1.1/src/chironfs.c:452: undefined reference to `fuse_get_context'

the pthread error tells me that -lpthread is missing, but the fuse error is kinda weird cause -lfuse is being used

i found a solution here which suggests to put libraries after object files

so i removed -lfuse and added -lfuse -lpthread at the very end of the line

now it compiles without an error and it seems that this is the way it should be: library after object files

my question is: why is the parameter order relevant for gcc/ld? i tought gcc just parses the params like every other application and may forward the necessary params to ld or such

in general: anyone knows facts or tips for gcc parameter ordering and maybe a bit background information about why it is needed this way?

thanks

解决方案

The order of objects and libraries is relevant to the linker (called implicitly by the compiler when creating an executable). When the linker, in its left-to-right scan, finds a use of a name it doesn't know about it starts looking for a definition from that point on. If a definition passes by, it doesn't remember it for later use.

这篇关于gcc / g ++参数顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆