how to link library for linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

1) If you want create "hello word" program compiling from command line should 
be good but for bigger project it's nonsense. 
You can write own makefile or use some IDE e.g. kdevelop, eclips ..etc

2) as you know parameters:
-I: is include path ..path where are headers files
-L: library path ..path where is library (static or dynamic)
-l: is parameter for linker which tell which library will be linking with 
aplication/library. Linker expected library name without prefix [lib] and suffix 
[.so] or [.a]
So when you have library libpj.so and you want add this library you have to 
add library follow:
-lpj

for you example:
gcc -Wall -I/usr/local/include -L/usr/local/lib -lpj exec.c

About you confusion with home path or system path.. No matter where you 
library is. If you have correct path all will be work fine. But if you have 
dynamick library (with suffix .so) you application will be need run-time 
library. Path where "application" will be library search is save in file: 
/etc/ld.so.conf or you can hack this with enviroment variable
LD_LIBRARY_PATH=/you/path/to/library or best solution you can 
"link" path with parameter -Wl,-rpath

gcc -Wall  -Wl,-rpath,/you/path/to/library/ -I/usr/local/include -
L/usr/local/lib -lpj exec.c

On internet is lot of stuff about this. And look at:

http://trac.pjsip.org/repos/wiki/Getting-Started


regards



On Wednesday 24 March 2010 09:45:07 am pranoti nandurkar wrote:
> Hi,
> Thanks Peter,
>
> these are the various ways i had try.
> please tell me where i am going wrong...
>
> [pranoti at pranoti p]$ gcc -Wall -I/usr/local/include -L/usr/local/lib exec.c
> -llibpj
> /usr/bin/ld: cannot find -llibpj
> collect2: ld returned 1 exit status
>
>
> [pranoti at pranoti p]$ gcc -Wall -I/home/pranoti/pjproject/pjlib/include
> -L/home/pranoti/pjproject/pjlib/lib exec.c -llibpj
> /usr/bin/ld: cannot find -llibpj
> collect2: ld returned 1 exit status
>
>
> [pranoti at pranoti p]$ gcc -Wall -I/usr/local/include exec.c
> /usr/local/lib/libpj.a
> /usr/local/lib/libpj.a(os_core_unix.o): In function `pj_sem_destroy':
> os_core_unix.c:(.text+0x429): undefined reference to `sem_destroy'
> /usr/local/lib/libpj.a(os_core_unix.o): In function `pj_sem_post':
> os_core_unix.c:(.text+0x494): undefined reference to `sem_post'
> /usr/local/lib/libpj.a(os_core_unix.o): In function `pj_sem_trywait':
> os_core_unix.c:(.text+0x4d3): undefined reference to `sem_trywait'
> [and so on....]
>
>
>
> [pranoti at pranoti p]$ gcc -Wall -I/usr/local/include -L/usr/local/lib exec.c
> -llibpj.a
> /usr/bin/ld: cannot find -llibpj.a
> collect2: ld returned 1 exit status
> [pranoti at pranoti p]$ gcc -Wall exec.c /usr/local/lib/libpj.a -o exec
> /usr/local/lib/libpj.a(os_core_unix.o): In function `pj_sem_destroy':
> os_core_unix.c:(.text+0x429): undefined reference to `sem_destroy'
> [and so on..]
>
> I had another confusion, that which path should give to gcc, where i stored
> library eg. /home/.../....
> or user path i.e usr/local/include.
>
> I did not have much knowledge of linux
> Please help.
> Thanks
> Pranoti




[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux