Cmake-boost
Last update date:2014-04-25by kagula
Prerequisites: Introduction to cmake (II) and basic Linux operations
Environment:Windows 8.1 64bit English version, Visual Studio 203 update1 English version, cmake 2.8.12.2, cent OS 6.5, cent OS 6.5 comes with GCC 4.4.7, ICU 4.2.1
Introduction
This section describes how to use the cmake tool to move projects on cent OS if projects on Visual Studio depend on the boost library.
Body
Install boost in centos
[S1] download and decompress the package to the current directory
# Tar-zxvf boost_1_55_0.tar.gz
[S2] install boost. RegEx dependent ICU
# Yum install ICU libicu-devel
[S3] enter the boost decompression directory, compile and install
#./Bootstrap. Sh
#./B2 install -- prefix =/usr/local
In this way, the boost header file will be copied to the/usr/local/include path, and the boost static library file will be copied to the/usr/local/lib path.
How to install boost in Windows [1]
Create a test project on Visual Studio 2013
Create a [visual c ++]-> [Win32]-> [win32project] project, set application type to console application, and set additional options to empty project. This test project only contains two files: source.cppand cmakelists.txt
Now add source. cpp, source code list:
include <iostream>#include <boost/thread.hpp>using namespace std;void mythread(){cout << "Hello,thread!" << endl;}int main(){boost::function<void()> f(mythread);boost::thread t(f);t.join();cout << "thread is over" << endl;getchar();return 0;}
Cmakelists.txt. The source code list is as follows:
# Set the project name Project (cmake_tutori_3) # The minimum cmake version is 2.8cmake _ minimum_required (version 2.8) # Add the header file search path include_directories (/usr/local/include) # Add the library file search path link_directories (/usr/local/LIB) # store the names of all source files in the current directory in the variable dir_srcs aux_source_directory (. dir_srcs) # used to specify the source file source1 source2... Sourcen (defined in the dir_srcs variable) # compile an executable file and name it cmake_tutorial1add_executable (cmake_tutori_3 $ {dir_srcs }) # Add the Link Library required to compile the executable program, and separate multiple links with spaces. # The first parameter is the name of the executable program, the second start is the dependent library # search for the libboost_thread.a file target_link_libraries (cmake_tutori_3 boost_thread) based on the name boost_thread)
Test Project on cent OS
Assume that the project directory cmake_tutori_3 on win is copied to the/home/kagula/downloads path.
Enter the path,
$ CD cmake_tutori_3
$ Mkdir build
$ CD build
Read the cmakelists.txt file of the parent directory and generate the MAKEFILE file.
$ Cmake ..
Read makefile, compile the project, and generate the cmake_tutori_3 executable file in the current directory.
$ Make
Run the compiled program
$./Cmake_tutori_3
The advantage of static links is that the deployment is simple and there is no need to worry about the target environment. The dependent libraries do not exist or the versions do not match. So far, our executable programs are static link dependent libraries, the disadvantage is that it results in a waste of storage space, so it is not suitable for some large projects. The next article will introduce how to use the cmake tool to compile dynamic link libraries on cent OS.
Why is the default project on visualstudio2013 Win32 project rather than win64? [1] few projects require more than 2 GB of memory. [2] has almost or no performance improvement. [3] 64-bit systems can run 32-bit programs, but this is not the case.
References
[1] win7 vs2012 compiled boost 1.55
Http://blog.csdn.net/alex_my/article/details/17630685
[2] bash script toinstall GCC 4.8.2 and boost 1.55.0 on centos 6.4, centos 5.5 and Mac OS X 10.9
Http://joelinoff.com/blog? P = 1003
Cmake-Boost-executable program-static library