简体   繁体   English

Clion 使用 -O3 编译

[英]Clion compile with -O3

I'm writing a c++ program using CLion and I need to specify -O3 flag on the compiler, using set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" -O3) on the CMakeList file does not work.我正在使用 CLion 编写一个 c++ 程序,我需要在编译器上指定 -O3 标志,在 CMakeList 文件上使用set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" -O3)不起作用。 Is there a way to do it?有办法吗?

Use either add_compile_options(-O3) to add it globally or target_compile_options(YourTarget -O3) to add it locally to a specific target.使用add_compile_options(-O3)将其全局添加或使用target_compile_options(YourTarget -O3)将其本地添加到特定目标。


You could also do it by using CMAKE_CXX_FLAGS but that is a pretty old way of doing things in CMakeLists files, that's how it would look like: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") or set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -O3) .您也可以通过使用CMAKE_CXX_FLAGS来完成,但这是在 CMakeLists 文件中做事的一种非常古老的方式,这就是它的样子: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -O3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM