Argument order in cygwin gcc 4.3 matters when linking with glib-2.0
I am trying to compile code that works on os x and linux using cygwin. However, I find that the order of the gcc arguments gives unexpected results.
For example, the following is true:
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
but the following works:
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
Can anyone explain how this works? Also, are there methods or code I can look at to force autoconf to change the order of its arguments based on 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'
Thank,
SetJmp (gcc 4.3.4)
a source to share
-l
<i> Library
-l
librarySearches a library named library when linking. (The second alternative, with the library as a separate argument, is for POSIX compliance only and is not recommended.)
It matters when you write this option in a command; the linker searches for and processes libraries and object files in the order in which they are listed.
Thus, '
foo.o -lz bar.o
' searches for a libraryz
'' after the filefoo.o
, but beforebar.o
. If itbar.o
refers to functions in `z
', these functions may not be loaded.
Options -Wl,--start-group
and are -Wl,--end-group
sometimes useful to prevent such problems.
None of this is a problem if you only use shared libraries.
a source to share