Since learning C + + has come into contact with a lot of very powerful libraries, such as opencv,boost and so on, but the relevant examples and tutorials have advocated the installation of these libraries on the computer, to a certain extent I hate to do so, but rather advocate the use of command-line compilation to build the executable file, Note the location of the header file and the location of the library file on the command line.
This is done on the one hand transparency high, oneself at compile time know what library to use, what header file, very convenient debug.
Secondly, it can improve the mobility, if the OPENCV library is compiled into a linked library file, installed in the/usr/libs/folder, the Linux system compiles our source program, it is natural to find these header files and library files, because this is the Linux default search library file location, However, if the project folder is copied to a Windows or Mac system, an error occurs. Because the file system is not the same, and if we use the command line to compile, we can avoid such a problem.
To compile a program that calls the Boost library file Test.cpp, for example:
#include "boost/lambda/lambda.hpp"
#include <iostream>
#include <iterator>
#include <algorithm>
int main (int argc, char* argv[])
{
using namespace Boost::lambda;
typedef std::istream_iterator<int> in;
Std::for_each (In (Std::cin), in (), std::cout<< (_1*3) << "");
}
If the header and source files are placed in a file,
Command line: $g + I (path to boost file) Test.cpp-o test
-I for include, path to boost file is the Boost folder that the user downloads and extracts from, the location of the Windows system, for example: I'm storing the location is C:\Users\s145019\Downloads\boost_1_60_ 0
Then command behavior: $g +/-C:\Users\s145019\Downloads\boost_1_60_0 test.cpp-o test
Generates the executable file test.
If the header file and the corresponding source file are not placed in a file, but are divided into two different folders,
The command behavior: $g + I (path to head file)-L (Path to library file)-L * * * test.cpp-o Test
-L represents the location where the Library,path to library file represents the library files. -L * * represents a dynamic or static link library that needs to be used
PS: If necessary, OPENCV or boost can be used to install the library into the system
Command-line compilation of a little bit of broken read