可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
OS : OS X 10.8.1 QtCreator : 2.6.2
Command line is fine, but QtCreator fail to compile the codes.
#include <functional> #include <iostream> #include <memory> #include <string> #include <vector> int main(int argc, const char * argv[]) { std::vector<std::string> strs{"yahoo", "haha"}; for(auto const &data : strs){ std::cout<<data<<std::endl; } std::vector<std::string> strs2 = std::move(strs); std::unique_ptr<int> A(new int(3)); std::cout<<*A<<std::endl; return 0; }
Command line :
clang++ -stdlib=libc++ -std=c++11 main.cpp -o test
Compiler setting of QtCreator http://www.flickr.com/photos/92283971@N04/8453188038/in/photostream
Qt .pro file
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp QMAKE_CXXFLAGS += -std=c++11 QMAKE_CXXFLAGS += -stdlib=libc++
Error message:
clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later) make: *** [main.o] Error 1
But my OS number is 10.8.1
回答1:
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp LIBS += -stdlib=libc++ QMAKE_CXXFLAGS += -stdlib=libc++ QMAKE_CXXFLAGS += -std=c++11 QMAKE_CXXFLAGS += -mmacosx-version-min=10.7 QMAKE_LFLAGS += -mmacosx-version-min=10.7
I can compile the codes by this .pro file But there are warning when you play with Qt library
ld: warning: directory not found for option ‘-F/Users/yyyy/Qt5.0.1/5.0.1/clang_64/qtbase/lib’ After some research, I find out this is a bug of Qt5 It is ok if you ignore this warning message even it is annoying
回答2:
After some research, I find out that the error messages could be solved by adding a flag to the .pro file
TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp QMAKE_CXXFLAGS += -stdlib=libc++ QMAKE_CXXFLAGS += -std=c++11 #QMAKE_CXXFLAGS += -mmacosx-version-min=10.7 #1 QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7 #2
1 and #2 do get rid of the error message
error message clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later) but they also generate another error message
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
symbol not found, but I have no idea what which .a should I link to?
回答3:
This seemed to do the trick for me.
CONFIG += c++11
It correctly put -std=c++11 in the command line and I didn't get any compiler or linker errors.
Using Qt 5.2.