Sign in to follow this  

Dynamically linking into static object files?

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, -o foo.o
And use it in another program with something like this
const char * (*fn)();
lib_handle = dlopen("", 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this