This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: One interesting question !?


On Wed, Jan 01, 2003 at 11:40:36AM +0800, Louie Chan wrote:
> Dear Sir/Madam,
> 
> Do you know why only the method #2 listed below can work ?
> Nevertheless, some other library like "mysqlclient" can work without any problem although I put it like "cc -I./ -L/usr/lib/mysql -lmysqlclient testc.c -o test -laaa" or "cc -I./ -L/usr/lib/mysql testc.c -o test -laaa  -lmysqlclient ".
> 
> Method #1:
> [root@etc-server temp]# cc -I./ -L./ -lmylib testc.c -o test
> /tmp/ccIJ9zcX.o: In function `main':
> /tmp/ccIJ9zcX.o(.text+0x7): undefined reference to `testlib'	<-- "testlib" is one function in this library for testing !!
> collect2: ld returned 1 exit status
> 
> Method #2:
> [root@etc-server temp]# cc -I./ -L./ -lmylib testc.c -o test -laaa
> 
> Remark: I used the commands "ar qa libmylib.a myobject1.o myobjectn.o; ranlib libmylib.a" to create my library.
> 
> THANKS !!

Probably mysqlclient on your system is a shared library.  It doesn't
matter what order shared libraries are listed on the command line; but
static libraries (.a) must be listed after whatever references them.

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]