dlsym() fails with an executable shared library

Ian Lance Taylor iant@google.com
Fri Dec 9 05:38:00 GMT 2011

Mayank Kaushik <mayank.utexas@gmail.com> writes:

>> Worked fine when I tried it.  I built your source code using
>> gcc -fPIE -pie -o foo.so foo.c -rdynamic
> Thanks, it indeed does. I had to leave out -fPIC. I'm curious, why did
> that cause a problem?

I don't know.  It works for me when I use -fPIC.  There is no particular
reason to specify both -fPIC and -fPIE.

> Last question; is the first method expected to also work on Mac, with
> the linker replaced by the appropriate linker for Mac, if I'm using
> gcc et al to build? I.e.:
> const char my_interp[] __attribute__((section(".interp"))) = "<dyld path>";
> (...)
> gcc -Wall -fPIC -shared -o library.so test.c -lc -Wl,-e,my_main
> In other words, does gcc on Mac support executable shared libraries?

I have no idea, sorry.  It's not a matter of whether gcc supports it;
it's whether the Mach-O supports it.


More information about the Gcc-help mailing list