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
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
28 Posts 3 Posters 32.3k 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
    #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
                      • S Offline
                        S Offline
                        stereomatching
                        wrote on last edited by
                        #24

                        I download gcc4.8 by macport

                        //install gcc48
                        sudo port install gcc48

                        //set gcc48 as the default compiler
                        sudo port select --set gcc mp-gcc48

                        set the compiler under /opt/local/bin/g++ for Qt5.0.1

                        .pro file

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

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

                        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
                        • A Offline
                          A Offline
                          alexisdm
                          wrote on last edited by
                          #25

                          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.

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

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

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

                            CC = 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.7

                            Thanks for your big helps, If I am familiar with makefile
                            This problem could be solved faster

                            But 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

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

                              Do some change on .pro file

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

                              Don't need to alter the makefile by hand

                              The warning still exist, do I need to solve the warning message?
                              Or I could simply ignore it?

                              Oh man, I hope that the support of c++11 could become mature ASAP
                              then all of us don't need to go through so many trouble
                              when we want to use it.

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

                                According to the sites
                                "Qt bug":https://bugreports.qt-project.org/browse/QTBUG-28336

                                This warning could be ignored, let us hope that Qt5.1 will fixe this bug

                                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