[SOLVED]Make QtCreator, QMake and clang3.2 work with c++11
-
[quote author="alexisdm" date="1360197491"][quote author="stereomatching" date="1360195754"]How could I check the path of the "clang++" of the terminal refer to?[/quote]
Try typing that in the terminal:
@which clang++@[/quote]
Thanks, it is same as the QtCreator refer to
/usr/bin/clang++So the problem is how could I make that QtCreator
know I need c++11 support just like the command line do?command input from the terminal
clang++ -stdlib=libstdc++ -std=c++11the codes with c++11 library also pass if it is compile by command line
@
//
// main.cpp
// yyyy
//
// Created by yyyy on 2/6/13.
// Copyright (c) 2013 yyyy. All rights reserved.
//#include <functional>
#include <iostream>
#include <memory>
#include <string>
#include <vector>template<typename T>
void print_comma_separated_list(T value)
{
std::cout<<value<<std::endl;
}template<typename First,typename ... Rest>
void print_comma_separated_list(First first,Rest ... rest)
{
std::cout<<first<<",";
print_comma_separated_list(rest...);
}int main(int argc, const char * argv[])
{// insert code here... std::cout << "Hello, World!\n"; auto func = [](){ std::cout << "hahaha\n"; }; func(); 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); for(auto const &data : strs2){ std::cout<<data<<std::endl; } std::unique_ptr<int> A(new int(3)); std::cout<<*A<<std::endl; print_comma_separated_list(32, "444", 34.564564, "lalamimilolipo"); return 0;
}
@ -
Thanks, QMAKE_CXXFLAGS += -std=c++11 did make c++11 features pass
@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qtSOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++11
@But it can't compile when I use something related to the library
like unique_ptr or initialise_listUnder command line, stdlib=libstdc++ should play the trick
How about QtCreator?Even it pass, could it work with Qt? -
bq. You can add “-stdlib=libstdc++” to QMAKE_CXXFLAGS too.
I tried it, but can't work
@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qtSOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -stdlib=libstdc++
@part of the error messages
@
In file included from /usr/include/c++/4.2.1/ostream:44:
In file included from /usr/include/c++/4.2.1/ios:47:
In file included from /usr/include/c++/4.2.1/bits/ios_base.h:46:
In file included from /usr/include/c++/4.2.1/bits/locale_classes.h:46:
In file included from /usr/include/c++/4.2.1/string:47:
In file included from /usr/include/c++/4.2.1/memory:54:
@compiler do not connect to libstdc++?
-
combinations of the .pro file
@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qtSOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -stdlib=libstdc++
@@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += -stdlib=libstdc++SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -stdlib=libstdc++
@@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += -stdlib=libstdc++SOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++11
#QMAKE_CXXFLAGS += -stdlib=libstdc++
@All of them can't work
-
The make file generated by this .pro
@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qtSOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -stdlib=libstdc++
@"makefile":http://pastebin.com/2E6xMRL6
The flags -stdlib=libstdc++ and -std=c++11
are added into the Compiler, tools and options part
CXXFLAGS = -pipe -std=c++11 -stdlib=libstdc++ -O2 -arch x86_64 -Wall -W $(DEFINES)what is the problem of the makefile generated by qmake?
-
Sorry, I did a mistake, the command should be
-stdlib=libc++ but not -stdlib=libstdc++The correct command line :
clang++ -stdlib=libc++ -std=c++11 main.cpp -o testcommand line work fine, but QtCreator still generate error message
QtCreator setting :
"setting":http://www.flickr.com/photos/92283971@N04/8453188038/in/photostream.pro file after change
@TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += -stdlib=libc++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 1But my OS number is 10.8.1
-
The version is taken from the "QMAKE_MACOSX_DEPLOYMENT_TARGET":http://qt-project.org/doc/qt-4.8/qmake-variable-reference.html#qmake-macosx-deployment-target variable, so if it wouldn't work with that version, you get an error.
-
@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += -stdlib=libc++SOURCES += main.cpp
#QMAKE_LFLAGS += -nodefaultlibs /usr/lib/libstdc++.dylib /usr/lib/libgcc_s.1.dylib
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -std=c++11
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
#QMAKE_CXXFLAGS += -mmacosx-version-min=10.7 #this line also give the same error message
@error message
clang: error: linker command failed with exit code 1 (use -v to see invocation) -
-
[quote author="alexisdm" date="1360245040"]Try this: http://qt-project.org/forums/viewthread/17150[/quote]
According to the informations of the link, I add
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
just as the previous postBut I get another error message
clang: error: linker command failed with exit code 1 (use -v to see invocation)The contents of the makefile
"makefile":http://pastebin.com/CaiFdNtFApparently, it do not link to the proper library
Where is the proper library? -
According to the generated makefile, the target is still 10.4.
Can you show the compilation output to see how clang++ is invoked ?If you have to add -stdlib=libc++, that means the current Qt installation uses libstdc++, and you won't be able to compile anything with both Qt and libc++, unless you recompile Qt.
-
Sorry, looks like I posted a wrong makefile
This time I'm sure the target is 10.7
"makefile":http://pastebin.com/SqG8hyPZ.pro
@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
#CONFIG += -stdlib=libc++SOURCES += main.cpp
#QMAKE_LFLAGS += -nodefaultlibs /usr/lib/libstdc++.dylib /usr/lib/libgcc_s.1.dylib
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -std=c++11
#QMAKE_CXXFLAGS += -mmacosx-version-min=10.7
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7#LIBS += /usr/lib/libstdc++.dylib /usr/lib/libgcc_s.1.dylib
@
"error messages":http://pastebin.com/0RahN86i
bq. If you have to add -stdlib=libc++, that means the current Qt installation uses libstdc++, and you won’t be able to compile anything with both Qt and libc++, unless you recompile Qt.
How about Qt5?Do I need to add -stdlib=libc++ if it is Qt5?
I would upgrade my projects to Qt5 if I could skip the pain of recompileWhatever, now the problem is how to make QtCreator could work with clang++
and c++11.Command line can make the job done but the makefile generated
by qmake can't compile. -
I give Qt5.0.1 a try, it has a same problem too
But this is expectable since the codes have nothing
to do with Qt but QtCreator and clang++.I install Qt5.0.1 and Qt4.8.4 on mac together
Not sure this could be a problem or not.pro of Qt5
@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
CONFIG += c++11
#CONFIG += -stdlib=libc++SOURCES += main.cpp
#QMAKE_LFLAGS += -nodefaultlibs /usr/lib/libstdc++.dylib /usr/lib/libgcc_s.1.dylib
QMAKE_CXXFLAGS += -stdlib=libc++
#QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7
#QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7#LIBS += /usr/lib/libstdc++.dylib /usr/lib/libgcc_s.1.dylib
@"makefile":http://pastebin.com/76PUzw2u
"error messages":http://pastebin.com/WTWrwm8d
-
I am thinking of using gcc4.7 to replace clang3.2
Compile with gcc come from the osx is fine with Qt4.8.4But Qt5.0.1 would generate a warning message no matter it is
clang or gccld: warning: directory not found for option '-F/Users/yyyy/Qt5.0.1/5.0.1/clang_64/qtbase/lib'
-
I download gcc4.8 by macport
//install gcc48
sudo port install gcc48//set gcc48 as the default compiler
sudo port select --set gcc mp-gcc48set the compiler under /opt/local/bin/g++ for Qt5.0.1
.pro file
@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qtSOURCES += main.cpp
QMAKE_CXXFLAGS += -std=c++0x
@codes
@
//
// main.cpp
// yyyy
//
// Created by yyyy on 2/6/13.
// Copyright (c) 2013 yyyy. All rights reserved.
//#include <functional>
#include <iostream>
#include <memory>
#include <string>
#include <vector>template<typename T>
inline void print_comma_separated_list(T value)
{
std::cout<<value<<std::endl;
}template<typename First,typename ... Rest>
void print_comma_separated_list(First first,Rest ... rest)
{
std::cout<<first<<",";
print_comma_separated_list(rest...);
}constexpr int multiply_two(int a)
{
return a * 2;
}int main()
{// insert code here... std::cout << "Hello, World!"<<std::endl; auto func = [](){ std::cout << "hahaha\n"; }; func(); 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); for(auto const &data : strs2){ std::cout<<data<<std::endl; } std::unique_ptr<int> A(new int(3)); std::cout<<*A<<std::endl; print_comma_separated_list(32, "444", 34.564564, "lalamimilolipo"); return 0;
}
@without any warning or errors
but it will pop out warning if I use Qt5ld: warning: directory not found for option ‘-F/Users/yyyy/Qt5.0.1/5.0.1/clang_64/qtbase/lib’
-
With clang, the linker doesn't get the -stdlib=libc++ option, so it was trying to link with libstdc++:
@clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o test01 main.o @Try adding:
@LIBS += -stdlib=libc++ -std=c++11@I'm not sure if -std=c++11 is needed for the linker.
-
[quote author="alexisdm" date="1360328228"]With clang, the linker doesn't get the -stdlib=libc++ option, so it was trying to link with libstdc++:
@clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o test01 main.o @Try adding:
@LIBS += -stdlib=libc++ -std=c++11@I'm not sure if -std=c++11 is needed for the linker.[/quote]
Thanks, the problem finally solved(half)
The .pro file
@
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
#CONFIG += c++11SOURCES += main.cpp
LIBS += -stdlib=libc++ #don't need -std=c++11
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7
@Not done yet, we have to change the parameters of the makefile too
@
####### Compiler, tools and optionsCC = clang
CXX = clang++
DEFINES =
CFLAGS = -pipe -mmacosx-version-min=10.7 -O2 -Wall -W -fPIE $(DEFINES)
CXXFLAGS = -pipe -mmacosx-version-min=10.7 -stdlib=libc++ -std=c++11 -mmacosx-version-min=10.7 -O2 -Wall -W -fPIE $(DEFINES)
INCPATH = -I../../../yyyy/Qt5.0.1/5.0.1/clang_64/mkspecs/macx-clang -I.
LINK = clang++
LFLAGS = -headerpad_max_install_names -mmacosx-version-min=10.7
LIBS = $(SUBLIBS) -stdlib=libc++
AR = ar cq
RANLIB = ranlib -s
QMAKE = /Users/yyyy/Qt5.0.1/5.0.1/clang_64/bin/qmake
@change 10.6 to 10.7 since
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7 or
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.7
would not change the mmacosx-version-min to 10.7Thanks for your big helps, If I am familiar with makefile
This problem could be solved fasterBut it would generate the warning message
ld: warning: directory not found for option '-F/Users/yyyy/Qt5.0.1/5.0.1/clang_64/qtbase/lib'After I go into the path and type ls -al, I really don't have anything called /qtbase/lib