LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Library help (https://www.linuxquestions.org/questions/linux-software-2/library-help-312828/)

fisban 04-13-2005 11:12 AM

Library help
 
Ok Im having problems loading libraries into my programs using #include <libhere> with all non-standard libraries (like stdlib). Problem libs include sdl/libsdl and ncurses.
Im using simplymepis with the kde desktop.:confused:

perfect_circle 04-14-2005 04:31 AM

Re: Library help
 
Quote:

Originally posted by fisban
Ok Im having problems loading libraries into my programs using #include <libhere> with all non-standard libraries (like stdlib). Problem libs include sdl/libsdl and ncurses.
Im using simplymepis with the kde desktop.:confused:

What exactly is your problem. The include command does not load a library. It includes a header file.
If you have a header file in /usr/include/something/name.h

You may include it with #include <something/name.h>
If the header is not under a standard include path, you may need to use the -I option in gcc
If you have a header is /my_headers/header.h

you need to #include <header.h>
and on compilation gcc -I/my_headers/

But by including a header you will only have the definition of a function. That does not mean that that your executables will be linked against the library were the body those functions is implemented. You need the -l (tha's a small L not a 1) to use those functions. So to develop with ncurses library you need to include <curses.h> and link the programs against libncurses.so with -lncurses (you always ommit the lib and the extension). If you get undefined reference errors , the -l is your problem.

Hope it helps

perfect_circle 04-14-2005 04:43 AM

Also, this thread is more suitable in the programming forum of LQ.
Dear moderator, can you plase move this thread to the programming forum?

MA_D 04-14-2005 10:06 AM

I'd guess you are either
1.) Forgetting that you include c libraries this way <library.h>, the key being the .h part that you disclude for ansi c++ libs.
2.) The headers aren't in /usr/include, so you have to tell g++/gcc/make where your other include dirs are. I forget how to do this, but it's not too bad.

fisban 04-15-2005 10:37 AM

ok
 
ive tried all the stuff you said already and it hasnt helped my. The program will not compile because the function from the librarys (non-standard) are "undefined". for example say i included sdl_initiate() during compile time gcc says something like sdl_initiate() funtion undefined.
im beginning to think asking for help from anyone is a waste of time.

perfect_circle 04-15-2005 03:07 PM

Re: ok
 
Quote:

Originally posted by fisban
ive tried all the stuff you said already and it hasnt helped my. The program will not compile because the function from the librarys (non-standard) are "undefined". for example say i included sdl_initiate() during compile time gcc says something like sdl_initiate() funtion undefined.
im beginning to think asking for help from anyone is a waste of time.

This is a typical SDL compilation line:
Code:

gcc -DPACKAGE=\"parallax-4\" -DVERSION=\"1.0.0\"  -I. -I.    -g -O2 -I/usr/include/SDL -D_REENTRANT -c `test -f parallax4.c || echo './'`parallax4.c
gcc  -g -O2 -I/usr/include/SDL -D_REENTRANT  -o parallax4  parallax4.o  -L/usr/lib -Wl,-rpath,/usr/lib -lSDL -lpthread

DO you use -lSDL ?
Is libSDL installed?

Try to compile an SDL demo from http://olofson.net/examples.html
If it compiles you are just forgettimg something
Look at the makefiles of the demos.

fisban 04-18-2005 10:22 AM

wow
 
this is getting kind of sad

perfect_circle 04-18-2005 11:23 AM

Re: wow
 
Quote:

Originally posted by fisban
this is getting kind of sad
What do you mean?
THats what Makefiles are for, try something like
gcc -g -O2 -I/usr/include/SDL -L/usr/lib -lSDL -lpthread your_filename.c
or
gcc -g -O2 -I/usr/local/include/SDL -L/usr/local/lib -lSDL -lpthread your_filename.c

fisban 04-18-2005 08:12 PM

grr
 
no wonder no one uses linux!
even though its good its a complete nightmare to use

MA_D 04-18-2005 08:33 PM

Everything is a bugger to develop for. Unless you are writing PASCAL's or something else with a very complete library.
Makefiles can be a bit of a pain, but I recommend getting a program like anjuta or kdevelop to help you manage them easily. And read up on using things like pkg-config; it's not that hard once you learn it.

The same things happen on all systems; some just automate more of it for certain things.

Oh, I guess Java has the most complete library.

jtshaw 05-13-2005 02:25 PM

Re: grr
 
Quote:

Originally posted by fisban
no wonder no one uses linux!
even though its good its a complete nightmare to use

This is rediculous.. if you are asking for help, perhaps you should listen to what people tell you.

Are you linking in the libraries when you compile the program? Do you even know what we mean by linking in the libraries?

I am well aware you use makefiles to include things like -lSDL to your compile line... but did you write a makefile to do that?

I assure you this is not a linux problem, it is a user problem.


All times are GMT -5. The time now is 02:13 PM.