g++ -o helloworld helloworld.cpp
但如果调用库的话,用g++编译非常不方便,我们可以写一个cmakelist,每次写新程序复制就可以了。
创建源文件 emacs -nw main.cpp
创建cmake命令 emacs -nw CMakeLists.txt
进行链接 cmake CMakeLists.txt
编译 make
运行 ./test test是生成的可执行文件
CMakeLists.txt的内容如下:
project(test)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_C_FLAGS "-frounding-math")
set(CMAKE_CXX_FLAGS "-frounding-math")
aux_source_directory(. SRCS)
add_executable(test ${SRCS})
target_link_libraries(test, CGAL, CGAL_core ) // link the external library, 把CGAL和CGAL_ core替换成你需要用的库
本文介绍了一种使用CMake结合g++进行程序开发的方法。通过创建CMakeLists.txt文件来简化编译流程,并实现外部库的链接。具体步骤包括创建源文件、编写CMake配置文件、编译及运行程序。
1491

被折叠的 条评论
为什么被折叠?



