Creating UserLibraries: Linker Problem

Just starting out? Need help? Post your questions and find answers here.
Violet
Enthusiast
Enthusiast
Posts: 106
Joined: Sun Dec 23, 2007 6:30 pm

Creating UserLibraries: Linker Problem

Post by Violet »

So far, so good, I created my UserLibrary using SDL and it compiles without Problems. But if I try to compile a PureBasic Code using those Functions, I get a Linker error.
pulsar.a(pulsar.o): In function `PB_InitPulsar':
pulsar.c:(.text+0xe): undefined reference to `SDL_Init'
pulsar.c:(.text+0x20): undefined reference to `SDL_GetVideoInfo'
collect2: ld gab 1 als Ende Status zurÃCEck
I don't understand that, I already linked the SDL stuff when compiling the C Source, or do I have to do that again now? How can I do that? I bet it's something simple...

Note: Operating System is Ubuntu 8.10 32-Bit

And by the way, how can I access PureBasic internal functions in my own UserLibraries (Maybe again something to link)?
best regards,

Violet
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You need to add it at the linking stage as well (sdl-config --clibs).
Violet
Enthusiast
Enthusiast
Posts: 106
Joined: Sun Dec 23, 2007 6:30 pm

Post by Violet »

Like this? (Extraction of Makefile)

Code: Select all

gcc -c -DLINUX pulsar.c -lSDL -lSDL_image -lGL -lGLU `sdl-config --clibs`
I just ask because that didn't work that way. And I have to say that I am not so experienced in C yet. The Linking stuff is something new to learn...
best regards,

Violet
Violet
Enthusiast
Enthusiast
Posts: 106
Joined: Sun Dec 23, 2007 6:30 pm

Linker Problem

Post by Violet »

*Bump*

Damn Telekom, didn't had Internet the last days...

I tried the stuff with sdl-config (Googled and so on) but that also doesn't work. When I try to compile the UserLibrary with the line of the makefile (calling gcc with parameters), it just waits for further input.

I examined the sdl-config script, and saw that "--clibs" is not a valid parameter, only "--libs" or "--cflags". But I tried every parameter. It always returns Include Paths, so I tried to compile the Library directly with those parameters. But never worked, as before, the linker problem.

Can anyone tell me how to do that? (Or a knowledge source for the whole linking stuff?)
best regards,

Violet
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

You are right it's: `sdl-config --libs`

It works for us (you can try putting an InitSprite() in your code, it should add it automatically).

Note: using '-c' is to create a object (.o)

The sdl-config needs to be specified at the linking stage (ie: when creating the final exe, not when creating a .o). If you do an user lib, your .Desc should look like this:

Code: Select all

; Langage used to code th library: ASM or C
;
C

; Number of windows DLL than the library need
;
1
`sdl-config --libs` -lgcc

; Library type (Can be OBJ or LIB)
;
LIB

; Number of PureBasic library needed by the library
;
0

; Help directory name
;
YourLibName

; Library functions (FunctionName, Arg1, Arg2, ...)
;
[Yourfunction here]

Violet
Enthusiast
Enthusiast
Posts: 106
Joined: Sun Dec 23, 2007 6:30 pm

Post by Violet »

Thanks, that worked! :D

I just didn't thought about that in the *.desc file, because there it's called "Windows DLLs needed by the library (and I am working on Linux).
best regards,

Violet
Violet
Enthusiast
Enthusiast
Posts: 106
Joined: Sun Dec 23, 2007 6:30 pm

Post by Violet »

But isn't there any documentation about that whole thing anywhere? Something like an How-To? Because I am surely not the first one trying to make UserLibraries (compiling but not linking source code a.s.o.).

Because now I have the Problem, I get Linker Errors with the OpenGL Functions. :lol:

I already tried many ways to link OpenGL (When compiling C(++) Source with GNU GCC in Commandline these parameters are needed: "-lGL -lGLU") in the *.desc file, but won't work. And something similar like "sdl-config" for the OpenGL Library isn't there. :?
best regards,

Violet
User avatar
viiartz
User
User
Posts: 70
Joined: Tue Mar 28, 2006 2:00 am

Re:

Post by viiartz »

Violet wrote:But isn't there any documentation about that whole thing anywhere? Something like an How-To? Because I am surely not the first one trying to make UserLibraries (compiling but not linking source code a.s.o.).
I would also like to find any information on compiling and specification of userlibs. I've been searching the forums for hours but don't seem to find anything on the subject.

Any help would be much appreciated.
Thanks,
ViiArtz
Post Reply