Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Make QtCreator, QMake and clang3.2 work with c++11

[SOLVED]Make QtCreator, QMake and clang3.2 work with c++11

Scheduled Pinned Locked Moved General and Desktop
28 Posts 3 Posters 33.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #4

    I tried it, both
    CXXFLAGS += -std=c++11
    CONFIG += -std=c++11
    or
    CONFIG += -std=gnu++11

    I also execute the clang++ directly

    clang++ -stdlib=libstdc++ -std=c++11 main.cpp

    @
    //
    // 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>

    int main(int argc, const char * argv[])
    {

    // insert code here...
    std::cout << "Hello, World!\n";
    std::unique_ptr<int> A(new int(3)); //generate errors on this line
    

    //but this is fine
    auto func = { std::cout << "hahaha\n"; };
    func();

    return 0;
    

    }
    @

    error messages

    main.cpp:20:10: error: no member named 'unique_ptr' in namespace 'std'
    std::unique_ptr<int> A(new int(3));
    ~~~~~^
    main.cpp:20:24: error: expected '(' for function-style cast or type construction
    std::unique_ptr<int> A(new int(3));
    ~~~^
    main.cpp:20:26: error: use of undeclared identifier 'A'
    std::unique_ptr<int> A(new int(3));

    1 Reply Last reply
    0
    • O Offline
      O Offline
      ogoffart
      wrote on last edited by
      #5

      What is the compiler command?

      Also, unique_ptr is part of the standard library. Are you using the stdlib from gcc or the libcpp?
      If you are using the one from gcc, you need to have a recent version of GCC.

      If you are on mac, it is better to use libcpp, then you need to use -stdlib=libc++
      But I think is not binary compatible with GCC's library.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stereomatching
        wrote on last edited by
        #6

        bq. What is the compiler command?

        clang++ -stdlib=libstdc++ -std=c++11 main.cpp -o test

        Now I get rid of those errors by using the default compiler on OS X 10.8.1
        I downloaded the command line tools by XCODE

        but when I compile it by QtCreator
        It can't work

        .pro
        @
        TEMPLATE = app
        CONFIG += console
        CONFIG -= app_bundle
        CONFIG -= qt
        CONFIG += -std=c++11

        SOURCES += main.cpp

        @

        @
        #include <iostream>

        using namespace std;

        int main()
        {
        cout << "Hello World2!" << endl;

        auto func = [](){cout << "wahaha"<<endl; };
        
        return 0;
        

        }
        @

        the compiler of the QtCreator refer to is usr/bin/clang++

        I don't know this is the same compiler of the command line refer to or not?
        How could I check the path of the "clang++" of the terminal refer to?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alexisdm
          wrote on last edited by
          #7

          [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++@

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stereomatching
            wrote on last edited by
            #8

            [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++11

            the 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;
            

            }
            @

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alexisdm
              wrote on last edited by
              #9

              You should add:
              @QMAKE_CXXFLAGS += -std=c++11@

              The previously given variable, CXXFLAGS, doesn't do anything.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                stereomatching
                wrote on last edited by
                #10

                Thanks, QMAKE_CXXFLAGS += -std=c++11 did make c++11 features pass

                @
                TEMPLATE = app
                CONFIG += console
                CONFIG -= app_bundle
                CONFIG -= qt

                SOURCES += 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_list

                Under command line, stdlib=libstdc++ should play the trick
                How about QtCreator?Even it pass, could it work with Qt?

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alexisdm
                  wrote on last edited by
                  #11

                  You can add "-stdlib=libstdc++" to QMAKE_CXXFLAGS too.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    stereomatching
                    wrote on last edited by
                    #12

                    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 -= qt

                    SOURCES += 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++?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      stereomatching
                      wrote on last edited by
                      #13

                      combinations of the .pro file

                      @
                      TEMPLATE = app
                      CONFIG += console
                      CONFIG -= app_bundle
                      CONFIG -= qt

                      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++
                      @

                      @
                      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

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        stereomatching
                        wrote on last edited by
                        #14

                        The make file generated by this .pro

                        @
                        TEMPLATE = app
                        CONFIG += console
                        CONFIG -= app_bundle
                        CONFIG -= qt

                        SOURCES += 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?

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          stereomatching
                          wrote on last edited by
                          #15

                          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 test

                          command 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 1

                          But my OS number is 10.8.1

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            alexisdm
                            wrote on last edited by
                            #16

                            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.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              stereomatching
                              wrote on last edited by
                              #17

                              @
                              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)

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                alexisdm
                                wrote on last edited by
                                #18

                                Try this: http://qt-project.org/forums/viewthread/17150

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  stereomatching
                                  wrote on last edited by
                                  #19

                                  [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 post

                                  But 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/CaiFdNtF

                                  Apparently, it do not link to the proper library
                                  Where is the proper library?

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    alexisdm
                                    wrote on last edited by
                                    #20

                                    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.

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      stereomatching
                                      wrote on last edited by
                                      #21

                                      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 recompile

                                      Whatever, 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.

                                      1 Reply Last reply
                                      0
                                      • S Offline
                                        S Offline
                                        stereomatching
                                        wrote on last edited by
                                        #22

                                        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

                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          stereomatching
                                          wrote on last edited by
                                          #23

                                          I am thinking of using gcc4.7 to replace clang3.2
                                          Compile with gcc come from the osx is fine with Qt4.8.4

                                          But Qt5.0.1 would generate a warning message no matter it is
                                          clang or gcc

                                          ld: warning: directory not found for option '-F/Users/yyyy/Qt5.0.1/5.0.1/clang_64/qtbase/lib'

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved