|
-
May 8th, 2011, 04:19 AM
#1
Linking a static library with a shared library.
Hey,
How would I go about linking my static library with a shared library?
Here's an example:
Say I have a simple static library that provides one method:
Code:
#include <GL/gl.h>
void bar()
{
glFlush();
}
All it does is call glFlush.
For this, the library needs to link to libGL. So this is what my Makefile looks like:
Code:
all : foo.o
ar cq libfoo.a foo.o
foo.o : foo.cpp
g++ -Wall -pedantic foo.cpp -o foo.o -lGL
clean:
rm -f *.o
rm -f *.a
But what happens when i make this, is getting a nice undefined reference to 'main' error.
I guess this is because I would normally would provide g++ with the -c option to skip linking, but this time I want to link with libGL so I had to remove it...and I am guessing this causes g++ to link with a number of default libraries, which expect my code to define a main function. Just guessing.
Another solution I have found is to not link with libGL at that stage, instead add the -c option, and then when the static library in turn is linked with the final executable I link with libGL. This works. However, I am really hoping I can avoid this because I dont want my "end users" to have to link with every single shared library that my static library refers to.
I hope this question makes sense, if not, tell me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|