1

I built my own gcc from source using

/configure --host=x86_64-linux-gnu --target=x86_64-linux-gnu --enable-checking=release --enable-languages=c,c++ --disable-multilib --program-suffix=-6.4 --prefix=/home/martin/devel/gcc-6.4.0-build
make

Everything went well except when I want to build my shared library with static runtime using cmake like this:

cmake_minimum_required(VERSION 2.6)

SET(CMAKE_C_COMPILER /home/martin/devel/gcc-6.4.0-build/bin/gcc-6.4)
SET(CMAKE_CXX_COMPILER /home/martin/devel/gcc-6.4.0-build/bin/g++-6.4)
project(Foo)
add_library(FooLib SHARED main.cpp)
target_link_libraries(FooLib -static-libgcc -static-libstdc++ -static)

When I try to make this I get the following error:

/usr/bin/ld: /home/martin/devel/gcc-6.4.0-build/lib/gcc/x86_64-linux-gnu/6.4.0/crtbeginT.o: relocation R_X86_64_32 against `__TMC_END__' can not be used when making a shared object; recompile with -fPIC
/home/martin/devel/gcc-6.4.0-build/lib/gcc/x86_64-linux-gnu/6.4.0/crtbeginT.o: error adding symbols: Bad value

So I suspected that the gcc wasn't been built properly, don't know how to do that.

1
  • I'd suggest you first pick a single programming language, either C or C++. Commented Mar 25, 2018 at 10:40

1 Answer 1

1

You are missing --with-pic in your GCC configure line. Though apparently there are some bugs sometimes: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58638 so you should add CFLAGS="-fPIC" CXXFLAGS="-fPIC" for safety.

Sign up to request clarification or add additional context in comments.

5 Comments

I'll try. The only thing I don't get is where is this from. The --with-pic is never mentioned when I type ./configure --help
it's from libstdc++'s configure. GCC's build system is basically a good dozen distinct software / libraries : the top level configure passes all the options it gets to all the "child" configure : libstdc++, binutils, GMP, MPFR, etc. But all the options of the child scripts aren't repertoried in the top-level one (sadly).
Well... the good news is that it compiled. The bad news is that ldd is showing a bunch of .sos ... in case I am reading it correctly. I assume that list should be empty when I link a shared library with the -static... but I guess this question is solved
> "I assume that list should be empty when I link a shared library with the -static..." : I don't think this is possible: at the bare minimum, shared libraries must link to linux-vdso and ld-linux-$PLATFORM IIRC.
but when I deleted the entire -static-libgcc -static-libstdc++ -static from the cmake line and the ldd was the same as with it... I am trying to add also the --disable-shared as mentioned in the link... I'll let know how it finished. Btw the ldd list was linux-vdso.so.1,libstdc++.so.6 ,libm.so.6,libgcc_s.so.1 ,libc.so.6 ,/lib64/ld-linux-x86-64.so.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.