最后,测试程序的编译命令:
along@along2x:~/bill2d/src$ g++ -std=c++14 -o bill2dmain1 bill2d_main.cpp -I/home/along/bill2d/src ---I/home/along/bill2d/build -I/usr/include/hdf5/serial -I/home/along/bill2d/build/googletest/src/gtest/googletest/include -L/usr/lib/x86_64-linux-gnu/hdf5/serial -L/home/along/bill2d/build/lib -L/usr/lib -lbill2d -lboost_system -lboost_filesystem -lboost_program_options -lhdf5 -lhdf5_cpp -mavx
along@along2x:~/bill2d/src$ g++ -o testc testc.c -I/home/along/bill2d/build -I/usr/include/hdf5/serial -I/home/along/bill2d/build/googletest/src/gtest/googletest/include -lbill2d -lboost_system -L/home/along/bill2d/build/lib -mavx
g++ test01p.cpp -I/usr/include/hdf5/serial -I/home/along/bill2d/build -I/home/along/bill2d/build/googletest/src/gtest/googletest/include -L/home/along/bill2d/build/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -L/path/to/bill2d/library -L/path/to/boost/library -L/home/along/bill2d/build/lib -L/path/to/hdf5/lib -L/usr/lib/x86_64-linux-gnu -lbill2d -lboost_system -lboost_program_options -lboost_filesystem -lgsl -lhdf5 -lhdf5_cpp -lblas -mavx -o test01p
g++ bill2d_main.cpp -I/usr/include/hdf5/serial -I/home/along/bill2d/build -I/home/along/bill2d/build/googletest/src/gtest/googletest/include -L/home/along/bill2d/build/lib -L/usr/lib/x86_64-linux-gnu/hdf5/serial -L/path/to/bill2d/library -L/path/to/boost/library -L/home/along/bill2d/build/lib -L/path/to/hdf5/lib -L/usr/lib/x86_64-linux-gnu -lbill2d -lboost_system -lboost_program_options -lboost_filesystem -lgsl -lhdf5 -lhdf5_cpp -lblas -mavx -o bill2d_main
/cmake1test/math01F/math02f.h
#define MATHFUNCTIONS_H
class MathFunc{
public:
static double square(double x);
};
#include "math02f.h"
double MathFunc::square(double x) {
return(x*x);
}
/cmake1test/math01F/CMakeLists.txt
add_library( math01F STATIC math02f.cpp)
/cmake1test/main.cpp
#include <iostream>
#include "math01F/math02f.h"
int main() {
double value=4.0;
std::cout<<"The square:" <<value<<"is" << MathFunc::square(value)<< std::endl;
return 0;
}//main()
/cmake1test/CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(MyProject VERSION 1.0)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_subdirectory(math01F)
add_executable(MyProject main.cpp)
target_link_libraries(MyProject PUBLIC math01F)
mkdir build
cd build
cmake ..
make
运行:
./MyProject