![]() |
How to link a library to gcc?
I have installed Libnet (some network library), I have to compile a file wrote in c (server.c), this file uses Libnet. Using gcc how can i link the file server.c to Libnet?
P.S. the file server.c is located in home/andrea/ Libnet is located in home/andrea/libnet |
depends on libnet's configuration. some libs come with scripts that you specify on the command line and they do the work for you, some rely on programs like pkg-config, others you have to do everything manually. for the linker to pick up the libs, you will either have to set LDFLAGS or LD_LIBRARY_PATH to point to the libnet install directory ( probably /home/andrea/libnet/lib). for the includes, if libnet doesn't have a method like above, you will have to set the CFLAGS varable. try this and see if it helps:
(note this is for bash and zsh) export CFLAGS="-I/home/andrea/libnet/include" export LDFLAGS="-L/home/andrea/libnet/lib" or export LD_LIBRARY_PATH=/home/andrea/libnet/lib:$LD_LIBRARY_PATH you may have to possibly tell the linker explicitly which lib to link against, for instance if the lib is called libnet.so ( or libnet.so.1.2.1 or whatever): gcc blah blah blah -lnet tells the linker to link with libnet |
I have wrote this:
[andrea@localhost chat]$ gcc -o server -lnet -L /home/andrea/libnet/include server.c but there is this error: server.c:14:20: libnet.h: No such file or directory P.S. the file libnet.h is in the directory file:/home/andrea/libnet/include |
did you set the CFLAGS environmental variable or just pass -I/home/andrea/libnet/include on the gcc command line
gcc -I/home/andrea/libnet/include -L/home/andrea/libnet/lib server.c -o server try that out and see if it helps |
I'have exported CFLAGS and LDFLAGS then i wrote:
gcc -I/home/andrea/libnet/include -L/home/andrea/libnet/lib server.c -o server but are appeared a lot of errors like this : /home/andrea/tmp/cclqmr4a.o(.text+0x7): In function `conio_init': : undefined reference to `initscr' what thoes it means? |
Quote:
|
Quote:
gcc -I/home/andrea/libnet/include -L/home/andrea/libnet/lib server.c -o server -lnet if you pass the whole path to gcc ( the -I/home/an... and -L/home/an....) you shouldn't need to export CFLAGS and LDFLAGS. as with all things in *nix, there are multiple ways of doing what you want. |
All times are GMT -5. The time now is 08:23 PM. |