Jump to content
  • Advertisement
Sign in to follow this  
spraff

Dynamically linking into static object files?

This topic is 3618 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there. If I were making a dynamic link library (*nix-style), I would do something like
extern "C" { const char * foo(); }
and compile this with something like
g++ -fPIC -c foo.c
g++ -shared -soname,libfoo.so.1 -o libfoo.so.1.0 foo.o
And use it in another program with something like this
const char * (*fn)();
lib_handle = dlopen("libfoo.so.1", RTLD_LAZY);
fn = dlsym(lib_handle, "foo");
std::cout << (*fn)();
However, I want foo to be in a standalone executable. Can I dlopen("a.out") and do the same? Is there standard, defined behaviour? Do I need to keep the -fPIC and -shared compiler flags when I build the standalone executable or will this mess things up?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!