CMake and make practice record

Source: Internet
Author: User

Debian operating system

Pre-operation:

Installing GCC g++ make CMake

Open Terminal

Switch to Super User download install above software

[Email protected]:~$ supassword: [email protected]:/home/a# apt-get install gcc g++ make cmakereading package lists ... Donebuilding Dependency Tree       Reading State information ... Donemake is already the newest VERSION.GCC are already the newest version.g++ is already the newest version.cmake is alread Y the newest version.0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

//==========================================================

Makefile content is as follows

target= maincpp_files = $ (Shell ls *.cpp) BASE = $ (basename $ (cpp_files)) Objs = $ (addsuffix. O, $ (addprefix obj/,$ (BASE)))  $ (target): $ (OBJS)-rm-f [email protected]g++-O $ (TARGET) $ (OBJS) obj/%.o:%.cpp@if test-d "obj"; thenmkdir-p obj;fi;g++-C -O [email protected] $< clean:-rm-f $ (TARGET)-rm-f OBJ/*.O

Three files in the same directory main.cpp Test1.cpp Test1.h Test2.cpp Test2.h

Final Result:

# makerm-f maing++-o main obj/main.o obj/test1.o obj/test2.o

Content Interpretation Reference

http://blog.csdn.net/wcl199274/article/details/39140459

Due to the page layout makefile content please pay attention to re-use tab layout may not compile but

//=============================================================

The test environment for CMake is as follows

A main.cpp content can be compiled arbitrarily

A CMakeLists.txt

The contents are as follows:

PROJECT (Main) cmake_minimum_required (VERSION 2.6) aux_source_directory (. DIR_SRCS) add_executable (main ${dir_srcs})

The compilation results are as follows

CMake.--Configuring done--generating done--Build files has been written to:/HOME/A/DESKTOP/3

  

make[100%] Building CXX object cmakefiles/main.dir/main.cpp.olinking CXX executable main[100%] Built target Main

//===================================================

Further down the root directory into main.cpp CMakeLists.txt

Place Test1.cpp Test1.h CMakeLists.txt in the new subdirectory of the SRC sub-directory

The root directory CMakeLists.txt content is as follows:

PROJECT (Main) cmake_minimum_required (VERSION 2.6) add_subdirectory (SRC) aux_source_directory (. DIR_SRCS) add_executable (main ${dir_srcs}  ) target_link_libraries (main Test)

The contents of the subdirectory CMakeLists.txt are as follows:

Aux_source_directory (. DIR_TEST1_SRCS) add_library (Test ${dir_test1_srcs})

The compilation is displayed as follows:

CMake.--The C compiler identification is GNU 4.9.2--The CXX compiler identification are GNU 4.9.2--Check for working C Compiler:/usr/bin/cc--Check for working C compiler:/USR/BIN/CC--works--detecting C compiler ABI info--detecting c C Ompiler ABI info-done--Check for working CXX compiler:/usr/bin/c++--Check for working CXX compiler:/usr/bin/c++--W orks--detecting CXX compiler ABI info--detecting CXX compiler ABI info-done--configuring done--generating done--Bui LD files has been written to:/HOME/A/DESKTOP/2

  

makescanning dependencies of Target test[50%] Building CXX object src/cmakefiles/test.dir/test1.cpp.olinking CXX static L Ibrary libtest.a[50%] Built target testscanning dependencies of target main[100%] Building CXX Object Cmakefiles/main.dir /main.cpp.olinking CXX executable main[100%] Built target Main

Content Interpretation Reference

http://www.ibm.com/developerworks/cn/linux/l-cn-cmake/

CMake and make practice record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.