与巧舌如簧-2.0连接的时候在Cygwin的gcc的参数顺序4.3事宜 [英] argument order in cygwin gcc 4.3 matters when linking with glib-2.0
问题描述
我试图编译code,关于OS X和Linux使用的cygwin的作品。然而,我发现该参数为GCC提供不可预知的结果。
I am trying to compile code that works on os x and linux using cygwin. However, I am finding that the argument order to gcc gives unanticipated results.
例如,下面的失败:
gcc -std=gnu99 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 -lintl -liconv -fgnu89-inline -fno-leading-underscore -o nb-learn.exe nb-learn.c
但以下工作:
gcc -std=gnu99 -fgnu89-inline -fno-leading-underscore -o nb-learn.exe nb-learn.c -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -lglib-2.0 -lintl -liconv
有人可以解释这是如何工作?此外,是否有技术或code我可以看看获取autoconf的改变参数顺序取决于平台?
Can someone explains how this works? Also, are there techniques or code I can look at for getting autoconf to change the argument order depending on the platform?
下面是错误消息的前两行:
Here are the first two lines of the error message:
/cygdrive/c/Users/aischein/AppData/Local/Temp/cc9MvUsf.o:nb-learn.c:(.text+0x260): undefined reference to `_g_hash_table_size'
/cygdrive/c/Users/aischein/AppData/Local/Temp/cc9MvUsf.o:nb-learn.c:(.text+0x29c): undefined reference to `_g_hash_table_get_keys'
谢谢,
的setjmp
(GCC 4.3.4)
SetJmp (gcc 4.3.4)
推荐答案
的 GCC文档说:
-l </ code> 库
-l </ code> 库
搜索名为库的链接时库。 (与库作为一个单独的参数的第二个选择是仅适用于符合POSIX标准,不建议使用。)
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)
这使得其中的命令,你写这个选项是有所不同;链接器搜索和处理库和目标文件中它们被指定的顺序。
It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified.
因此,`文件foo.o -lz文件bar.o
'搜索库'以Z
文件后, foo.o的
但在此之前文件bar.o
。如果文件bar.o
指的是在功能`以Z
',这些功能可能不会被加载。
Thus, `foo.o -lz bar.o
' searches library `z
' after file foo.o
but before bar.o
. If bar.o
refers to functions in `z
', those functions may not be loaded.
结果轮候册, - 启动组
和轮候册, - 端基
选项很有有时避免这种的问题。
-Wl,--start-group
and -Wl,--end-group
options are useful sometimes for avoiding such problems.
结果
如果仅使用共享库,这一切都不是问题。
All this isn't a problem if you use only shared libraries.
这篇关于与巧舌如簧-2.0连接的时候在Cygwin的gcc的参数顺序4.3事宜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!