3

Possible Duplicate:
Linking C++ code with 'gcc' (without g++)

GCC provides the -x lang option, which allows you to modify the assumed language during compilation. What is the equivalent for the link step? I wish to link a program that has C++ dependencies via the gcc command.

Community
  • 1
  • 1
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526

3 Answers3

3

You need to link against libstdc++ by passing -lstdc++.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

Using the -lstdc++ flag should do the job.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
0

You need to run the g++ frontend instead. (automake also does that as you will see - it calls CXXLD instead of CCLD when one of the source files is .cpp.) [Just using gcc with -lstdc++ won't help, because the gcc and g++ frontends can use different linker commands. On mine, gcc adds --as-needed when calling the linker, while g++ doesn't.]

user502515
  • 4,346
  • 24
  • 20