Instruct GCC to link as C++ [duplicate]
Possible Duplicate:
Linking C++ code with 'gcc开发者_开发百科9; (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.
You need to link against libstdc++ by passing -lstdc++
.
Using the -lstdc++
flag should do the job.
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.]
精彩评论