本文介绍了与 glib-2.0 链接时,cygwin gcc 4.3 中的参数顺序很重要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 cygwin 编译在 os x 和 linux 上运行的代码.但是,我发现 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

有人可以解释一下这是如何工作的吗?另外,是否有我可以查看的技术或代码来让 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'

谢谢,

设置Jmp(gcc 4.3.4)

SetJmp(gcc 4.3.4)

推荐答案

GCC 文档说:

-l

-l

链接时搜索名为library的库.(将库作为单独参数的第二种选择仅适用于 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' 在文件 foo.o 之后但在 之前搜索库`z'>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-Wl,--end-group 选项有时对于避免此类问题很有用.


-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.

这篇关于与 glib-2.0 链接时,cygwin gcc 4.3 中的参数顺序很重要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 14:08
查看更多