top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to compile glibc with -fPIC?

+2 votes
1,396 views

I want to build a 'static toolchain', with option --disable-shared, for no shared library include/depend in the toolchain-self

cause I don't want the target binary runs depend on the toolchain, such as libc.so, ld-xxx.so.

But when the target binary need the function dlopen, it give a build error that libc.a need to recompile with -fPIC

So, how to compile glibc with -fPIC? or maybe I should ask is it possible to gen a shared library with
static toolchain?

posted Oct 7, 2013 by Naveena Garg

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

or maybe i should ask is it possible to gen a shared library with static toolchain?

Yes, it is. To say a "static toolchain" effectively just means using different defaults. In fact you could probably do what you want with just a minor edit of gcc/gcc.c to add -static to LINK_COMMAND_SPEC. Although you would only want to add it if some option (perhaps --no-static?) where not present.

answer Oct 7, 2013 by Sanketi Garg
Similar Questions
+1 vote

I am building a shared library which will be distributed to clients in binary form only. I am attempting to make the same binary run on as many Linux variants as possible, and so when I build it I specify the
options -shared and -fPIC. As part of the effort of making the library as independent as possible, I also link both the C and C++ standard libraries statically into the final shared library. I want to do this because I use
C++11 features internally, and I don't want to force the users of my library to have a C++11 compiler handy.

When doing this, do I need to build libstdc++ and libgcc from source with -fPIC as well? Or is it okay to link with the static versions of these libraries that are provided in my Ubuntu 13.04 gcc package?

To clarify, no exceptions are thrown over library boundaries; all exceptions used internally in the library are caught and processed behind the scenes. None of them ever reach the client code, as the client communicates with the library using a plain C interface.

My exact build flags are as follows:

g++ -fvisibility=hidden -fvisibility-inlines-hidden -static-libstdc++ -static-libgcc -s -DNDEBUG -std=c++11 -Wall -shared -fPIC -o libtest.so test.cpp -lpthread -O2

+2 votes

I need to use microhttpd.a and pthread.a to build a cross-compiled program to be deployed on an arm-linux-gnueabihf device.

Where can I find instructions on how to do this? Or, is this simply a matter of downloading the source code and compiling (on a 64 bit UbuntuPC) to a library with my existing gcc-arm-linux-gnueabihf-4.8 cross-compiler?

While I may be able to find microhttpd.a and pthread.a binaries for an arm-linux-gnueabihf device, they will likely have been built with a different version of gcc-arm-linux-gnueabihf, which, I fear, could open up a can of worms.

0 votes

I'm studying about C compiler for increasing software quality. So I want to get all of compile error message list of gcc about C language. I was trying to find it. But I can't find it anywhere. How can I find it?

Please help?

+1 vote

Is there a conditional define that expands to a string of the full gcc command-line used to compile the given .c/.cc file? I'd like to embed in the executable the exact compilation options used to build it.

0 votes

How can we debug the segmentation fault in a program which has been compiled without "-g" option?

...