Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CMAKE脚本中的编译器标志设置_Cmake - Fatal编程技术网

CMAKE脚本中的编译器标志设置

CMAKE脚本中的编译器标志设置,cmake,Cmake,运行生成时,我面临以下问题: C:/Test.cpp: In member function '........': C:/Test.cpp:291:50: error: 'round_one' may be used uninitialized in this function [-Werror=maybe-uninitialized] 我试图在我的整个源代码中grep字符串可能未初始化,但我找不到一个。我期待一些声明,如下所示: set_source_files_properties(RO

运行生成时,我面临以下问题:

C:/Test.cpp: In member function '........':
C:/Test.cpp:291:50: error: 'round_one' may be used uninitialized in this function [-Werror=maybe-uninitialized]
我试图在我的整个源代码中grep字符串可能未初始化,但我找不到一个。我期待一些声明,如下所示:

set_source_files_properties(ROOT_DIR/Test.cpp PROPERTIES COMPILE_FLAGS "-Wno-maybe-uninitialized -Wno-misleading-indentation" )


但是我找不到任何-请告诉我如何在CMAKE实用程序中设置编译器标志?

警告
-Wmaybe uninitialized
是已启用的警告之一 通过
-Wall
始终由熟练的程序员指定。警告将被转换 将错误设置为,因此标志
-Wall-Werror
将生成
-Werror=可能未初始化
,
根据您的诊断,如果检测到可能未初始化的变量


您很可能会发现
-Wall-在相关
CMakeLists.txt

中指定的编译器标志中,一种方法是为项目设置添加编译器标志:

cmake_minimum_required(VERSION 2.8)

# Project
project(008-compile-flags-01)

# Add compile flag
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHELLO_WORLD" CACHE STRING "Hello World Define." FORCE)

# Executable source files
set(executable_SOURCES src/main.cpp)

# Executable
add_executable(executable ${executable_SOURCES})
另一种方法是为目标设置编译器标志:

cmake_minimum_required(VERSION 3.2)

# Project
project(008-compile-flags-03)

# Executable source files
set(executable_SOURCES src/main.cpp)

# Executable
add_executable(executable ${executable_SOURCES})

# Add compile flag
target_compile_options(executable PRIVATE -DHELLO_WORLD)
另一种方法是使用目标编译功能。我以前没用过这个。请参阅:


最简单的方法是查看编译器的命令行(
make VERBOSE=1
),找到一个生成此错误的标志,并为该标志grep您的CMake脚本。CMake本身绝对不会通过
-Werror
。以及@Tsyvarev提到的
make VERSBOSE=1
,您可以使用
CMake
或CMake GUI,并显示高级视图来检查
CMake_CXX_flags
中定义的标志……我使用CMake构建我的系统2次-第一次我发出“CMake-G”忍者命令“../”,其中我的CMakeLists.txt存在于../…目录中,然后是同一目录中的“cmake--build.”-请让我知道在何处使用详细标志?在build命令中使用它不会启动生成过程
cmake_minimum_required(VERSION 3.2)

# Project
project(008-compile-flags-03)

# Executable source files
set(executable_SOURCES src/main.cpp)

# Executable
add_executable(executable ${executable_SOURCES})

# Add compile flag
target_compile_options(executable PRIVATE -DHELLO_WORLD)