CMake代码优化编译选项

Mac有一次系统升级后,发现clang不支持了openmp了,最后brew安装了clang-omp。但是好不容易配置起来后发现程序运行速度巨慢,今天发现没有打开编译优化,在CMakeLists.txt文件中加入以下编译选项即可(o2优化,甚至o3):

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
程序速度提升4~5倍

Leave a Reply

Your email address will not be published. Required fields are marked *