ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
Originally posted by Andrea_81 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?
it means the linker cannot find the function "initscr" to link into the program. do you know where this function comes from ( is it one of your own)? if you declared a function called "Initscr" in a header somewhere and accidentally called it by "initscr" this error will happen. or if it's part of another library you are using and you accidentally misspelled it this will happen. if it's part of libnet you may need to explicitly declare it on the command line:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.