• Advertisement
Sign in to follow this  

Dynamically linking into static object files?

This topic is 3347 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
Sign in to follow this  

  • Advertisement