User forums > Using Code::Blocks
Unnecessary default linking to libstdc++ and libgcc for C code
Avidanborisov:
Code::Blocks links to libstdc++ and libgcc by default when compiling C code. That's really unnecessary for a default behavior I think.
Test:
--- Code: ---avidan@avidebian:~$ cat hello.c
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
avidan@avidebian:~$ codeblocks --build hello.c
Compiling: /home/avidan/hello.c
Linking console executable: /home/avidan/hello
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
avidan@avidebian:~$ ldd hello
linux-vdso.so.1 => (0x00007fffe18c6000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f6cc090f000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6cc068d000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6cc0476000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6cc00ef000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6cc0c39000)
avidan@avidebian:~$ # Build manually using GCC
avidan@avidebian:~$ gcc hello.c -o hello
avidan@avidebian:~$ ldd hello
linux-vdso.so.1 => (0x00007fff9b537000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f98e5ade000)
/lib64/ld-linux-x86-64.so.2 (0x00007f98e5e88000)
avidan@avidebian:~$ rm hello*
avidan@avidebian:~$
--- End code ---
It also links to libm, but that's perhaps good to avoid confusion, and because the math library is just used too often. I can't understand why it links to libgcc and especially libstdc++ by default when compiling C code. Is there any way to disable the linking of these libraries?
stahta01:
http://wiki.codeblocks.org/index.php?title=FAQ
Read the first 2 General FAQs.
Tim S.
oBFusCATed:
This happens because C::B uses g++ to do linking, if you think that you won't do any c++ programming you can change it to gcc.
Avidanborisov:
--- Quote from: stahta01 on October 21, 2012, 03:49:48 pm ---http://wiki.codeblocks.org/index.php?title=FAQ
Read the first 2 General FAQs.
Tim S.
--- End quote ---
That's not new to me. I know that Code::Blocks isn't a compiler or something like that. I did notice that it linked unnecessary libraries as part of it's usual building procedure for C code.
--- Quote from: oBFusCATed on October 21, 2012, 04:11:15 pm ---This happens because C::B uses g++ to do linking, if you think that you won't do any c++ programming you can change it to gcc.
--- End quote ---
Thanks, I now found that I could change the "Linker for dynamic libs:" to gcc instead of g++ in the "Compiler and debugger settings" dialog and it won't link any additional libraries. Shouldn't that be the default behavior? I mean, when compiling C use gcc as the linker and when compiling C++ use g++ as the linker.
oBFusCATed:
No, because C::B doesn't do natively multi-compiler project. It support mixed C/C++ projects using only and it is always in this mode.
Navigation
[0] Message Index
[#] Next page
Go to full version