Reputation: 337
When I set a new project in CodeBlocks and specific C
as language, it use g++
as linker.
inside settings there is :
Linker for Dynamic libs : g++
What's difference between gcc
and g++
as linker?
Upvotes: 2
Views: 1560
Reputation: 61337
Any of the GCC language frontends (gcc
, g++
, gfortran
, etc.), when
invoked for linkage will delegate to the system linker, ld
, and will
silently pass to the linker the boilerplate options for the language
associated with that frontend (C
,C++
,Fortran
, etc).
What those boilerplate options are is determined by the builder
of the toolchain (typically, your distro). The salient difference is
between the standard libraries that are linked for the different
languages. You can inspect the differences in full by directing the
frontend to request verbose mode from the linker: pass -Wl,-v
.
Why does Code::Blocks by default use g++
as the linker even for C language
projects? It's the simplest default: the resulting linkage options will work
for exclusively C++ projects of course; they'll also work for exclusively
C language projects (albeit with some redundancy), and they'll also work for mixed C/C++ language projects.
This decision does have a flaw if you program in C and not all all in C++
and therefore have - economically - installed gcc
but not g++
on your
system. Then you'll find that out-of-the-box your Code::Blocks C projects can't link
because you haven't got the default linker. But you can fix this in
a jiffy by changing the Linker for Dynamic libs from g++
to gcc
in the global Compiler settings of the toolchain.
Upvotes: 4