To use the templatealiases feature, GCC4.7. and do not want to compile the source code, so install it as follows. Sudoadd-apt-repositoryppa: Ubuntu-toolchain-r/testsudoapt-getupdatesudoapt-get
To use the template aliases feature, GCC4.7.
And do not want to compile the source code, so follow the method below to install.
- Sudo add-apt-repository ppa: Ubuntu-toolchain-r/test
- Sudo apt-get update
- Sudo apt-get install gcc-4.7
- Sudo apt-get install g ++-4.7
If multiple containers exist in the Ubuntu 12.04 system, you can configure them in the cmakelists.txt at the top of the cmakeproject:
- Cmake_minimum_required (VERSION 2.8.7)
- Set (CMAKE_C_COMPILER "/usr/bin/gcc-4.7 ")
- Set (CMAKE_CXX_COMPILER "/usr/bin/g ++-4.7 ")
- Project (sample)
- Add_subdirectory (src bin)
Then run cmake In the build directory. You can see:
- Chenshu @ chenshu-beijing :~ /Work/research/tree/normal_tree/build $ cmake ..
- -- The C compiler identification is GNU
- -- The CXX compiler identification is GNU
- -- Check for working C compiler:/usr/bin/gcc-4.7
- -- Check for working C compiler:/usr/bin/gcc-4.7 -- works
- -- Detecting C compiler ABI info
- -- Detecting C compiler ABI info-done
- -- Check for working CXX compiler:/usr/bin/g +++-4.7
- -- Check for working CXX compiler:/usr/bin/g ++-4.7 -- works
- -- Detecting CXX compiler ABI info
- -- Detecting CXX compiler ABI info-done
- -- Processing ing done
- -- Generating done
- -- Build files have been written to:/home/chenshu/work/research/tree/normal_tree/build
However, my method is not the best method recommended by CMake. There are three methods available for reference:
Http://www.cmake.org/Wiki/CMake_FAQ#Method_3_.28avoid.29:_use_set.28.29
- How do I use a different compiler?
- [Edit] Method 1: use environment variables
- For C and C ++, set the CC and CXX environment variables. this method is not guaranteed to work for all generators. (Specifically, if you are trying to set Xcode's GCC_VERSION, this method confuses Xcode .)
- For example:
- CC = gcc-4.2 CXX =/usr/bin/g + +-4.2 cmake-G "Your Generator" path/to/your/source
- [Edit] Method 2: use cmake-D
- Set the appropriate CMAKE_FOO_COMPILER variable (s) to a valid compiler name or full path on the command-line using cmake-D.
- For example:
- Cmake-G "Your Generator"-D CMAKE_C_COMPILER = gcc-4.2-D CMAKE_CXX_COMPILER = g ++-4.2 path/to/your/source
- [Edit] Method 3 (avoid): use set ()
- Set the appropriate CMAKE_FOO_COMPILER variable (s) to a valid compiler name or full path in a list file using set (). this must be done before any language is set (ie before any project () or enable_language () command ).
- For example:
- Set (CMAKE_C_COMPILER "gcc-4.2 ")
- Set (CMAKE_CXX_COMPILER "/usr/bin/g ++-4.2 ")
-
- Project ("YourProjectName ")
- [Edit]
C ++ 11 is disabled by default. Add this line to the src/CMakeLists.txt file:
- SET (CMAKE_CXX_FLAGS "-std = c ++ 11") # Add c ++ 11 functionality
Then run
Cmake ..
Make VERBOSE = 1
You will see that the compiled g ++ command is followed:
- /Usr/bin/g ++-4.7-std = c ++ 11
Now we have succeeded. Enjoy C ++ 11.
For more information about Ubuntu, see Ubuntu special page http://www.linuxidc.com/topicnews.aspx? Tid = 2