This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: One interesting question !?
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: Louie Chan <louie at unitednet dot com dot hk>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 31 Dec 2002 23:21:50 -0500
- Subject: Re: One interesting question !?
- References: <NFBBLFAPGLMOLOBBMKDDCEPEDOAA.louie@unitednet.com.hk>
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