C native binaries are linked to C++ runtime

(Terry Poulin) #1

It seems that gcc is being used for compilation of object files and g++ for linking. This results in the C++ runtime library being linked in. You can verify this buy doing a build on Linux with gcc toolchain and run the ldd program on a compiled binary.

$ ldd build/install/mainExecutable/lib/main

linux-vdso.so.1 => (0x00007fff389c4000)

libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa938f53000)

libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa938cd1000)

libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa938aba000)

libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa938730000)

/lib64/ld-linux-x86-64.so.2 (0x00007fa93926d000)


In the GCC universe, it is not normal to link the C++ runtime library (normally libstdc++) into a C program! The correct output would be more like this:

$ gcc -o main build/objectFiles/mainExecutable/mainC/hello_gradle.o

$ ldd main

linux-vdso.so.1 => (0x00007ffffe3ff000)

libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f84af516000)

/lib64/ld-linux-x86-64.so.2 (0x00007f84af8b3000)


I’ve found this both in a simple example C project and in more complex C projects.

Note: This is all using Gradle 1.11 on Debian stable (amd64) and stock gcc (4.7.2).

(René Groeschke) #2

Hello Terry, thanks for this report. you’re right, in gradle 1.11 g++ is used for linking c and cpp programms. You should be able to workaround this issue by verifying the linker used for the gcc toolchain:

  model {

toolChains {

 gcc(Gcc) {

  linker.executable = 'gcc'


}  }  

cheers, René

(Terry Poulin) #3

Work around confirmed, good stuff Rene. Do you know if this may be fixed in a later release?

(René Groeschke) #4

We’re currently in the process of finalizing gradle 1.12 so the fix won’t be in there I think. But I’ve exported the bug to our issue tracker. We’ll definitely want to fix this. you can vote and track this issue at GRADLE-3055

cheers, René

(Terry Poulin) #5