LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   error in compiling SDL code using gcc (https://www.linuxquestions.org/questions/programming-9/error-in-compiling-sdl-code-using-gcc-824428/)

richman1234 08-05-2010 02:09 PM

error in compiling SDL code using gcc
 
Hello all,

I'm a newbie with linux and I'm getting an error when I try to compile my SDL program with gcc. Here's the command line I'm using to compile it:

$ gcc -o comp fosdl9_3.c -lSDL_ttf -lSDL -I/usr/include/SDL -I/usr/local/include/SDL

And here is the error message it's giving me:

/usr/bin/ld: /tmp/ccr3zqbS.o: undefined reference to symbol 'sin@@GLIBC_2.0'
/usr/bin/ld: not: 'sin@@GLIBC_2.0' is defined in DSO /lib/libm.so.6 so try adding it to the linker command line
/lib/libm.so.6: could not read symbols: Invalid operation
collect2: ld returned 1 exit status

I'm assuming this means I have to add "libm.so.6 to the compile command line, but I'm not sure how to do that. Any help or advice would be greatly appreciated!

Thanks in advance!

David1357 08-05-2010 05:10 PM

Quote:

Originally Posted by richman1234 (Post 4057142)
I'm assuming this means I have to add "libm.so.6 to the compile command line, but I'm not sure how to do that.

Try
Code:

$ gcc -o comp fosdl9_3.c -lm -lSDL_ttf -lSDL -I/usr/include/SDL -I/usr/local/include/SDL

psionl0 01-30-2013 09:00 AM

Quote:

Originally Posted by David1357 (Post 4057271)
Try
Code:

$ gcc -o comp fosdl9_3.c -lm -lSDL_ttf -lSDL -I/usr/include/SDL -I/usr/local/include/SDL

Thanks for that suggestion it worked for me. I had the same problem when I was trying to make a package for cwstation - a morse code sound generator (http://cwstation.sourceforge.net/).

src2pkg aborted without giving any useful error messages. So I made a slackbuild script and when I ran it, I got the same error message as in the OP. The problem was to include the "-lm" without patching the Makefile or config file.

The solution was to modify cwstation.SlackBuild as follows:
Code:

make LDFLAGS="-lm" || exit

MrCode 02-01-2013 06:56 PM

More generally, if ld is spitting out "undefined reference to symbol 'foo'" "'foo' is defined in DSO 'libbar.so'", you want to add -lbar to your linking options, assuming the library actually exists.


All times are GMT -5. The time now is 05:07 AM.