开发者

Instruct GCC to link as C++ [duplicate]

This question already has answers here: Closed 12 years ago.

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.]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜