Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

c++ - When is it necessary to use the flag -stdlib=libstdc++?

When is it necessary to use use the flag -stdlib=libstdc++ for the compiler and linker when compiling with gcc?

Does the compiler automatically use libstdc++?

I am using gcc4.8.2 on Ubuntu 13.10 and I would like to use the c++11 standard. I already pass -std=c++11 to the compiler.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

On Linux: In general, all commonly available linux distributions will use libstdc++ by default, and all modern versions of GCC come with a libstdc++ that supports C++11. If you want to compile c++11 code here, use one of:

  • g++ -std=c++11 input.cxx -o a.out (usually GNU compiler)
  • g++ -std=gnu++11 input.cxx -o a.out

On OS X before Mavericks: g++ was actually an alias for clang++ and Apple's old version of libstdc++ was the default. You could use libc++ (which included c++11 library support) by passing -stdlib=libc++. If you want to compile c++11 code here, use one of:

  • g++ -std=c++11 -stdlib=libc++ input.cxx -o a.out (clang, not GNU compiler!)
  • g++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out (clang, not GNU compiler!)
  • clang++ -std=c++11 -stdlib=libc++ input.cxx -o a.out
  • clang++ -std=gnu++11 -stdlib=libc++ input.cxx -o a.out

On OS X since Mavericks: libc++ is the default. You can use Apple's old version of libstdc++ (which does not include c++11 library support) by passing -stdlib=libstdc++

  • clang++ -std=c++11 input.cxx -o a.out
  • clang++ -std=gnu++11 input.cxx -o a.out

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...