gpt4 book ai didi

C++:在 CMake 中禁用旧式转换警告

转载 作者:行者123 更新时间:2023-12-05 07:19:06 27 4
gpt4 key购买 nike

我正在与广泛使用旧式转换(数千)的旧代码库交互。我试图在 Cmake 中禁用这些警告,但它不起作用(我不想看到 1000 条警告,也不想修复根本原因)。为此,我假设我应该设置 -Wno-old-style-cast。我尝试在 CMakeLists.txt 文件的 3 个不同位置执行此操作,但无济于事。这是完整的文件:

set(example "train")
project(${example} CXX)

# Python
message(STATUS "We are going to force it to use Python 3. If you change this, you will need to remove the build folder and reload the cmake project.")
find_package(PythonLibs 3 EXACT)
find_package(PythonInterp 3 EXACT)

# PCL library
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-old-style-cast")
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -Wno-old-style-cast")

add_executable(${example} src/${example}.cpp)
target_compile_options(${example} PUBLIC -Wno-old-style-cast)
target_link_libraries(${example} ${Boost_LIBRARIES} ${PCL_LIBRARIES} ${PYTHON_LIBRARIES})
target_include_directories(${example} PRIVATE include/ ${PYTHON_INCLUDE_DIRS})

我正在使用 GCC 7.4.0 在 Ubuntu 18.04 上编译。我看到了成千上万个这样的错误:

/usr/include/python3.7m/object.h:118:49: warning: use of old-style cast [-Wold-style-cast]
#define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)

编辑:

make VERBOSE=1 的输出产生:

/usr/bin/c++  -DDISABLE_LIBUSB_1_0 -DDISABLE_PCAP -DDISABLE_PNG -DPCL_NO_PRECOMPILE=0 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -Dqh_QHpointer -DvtkRenderingContext2D_AUTOINIT="1(vtkRenderingContextOpenGL2)" -DvtkRenderingCore_AUTOINIT="3(vtkInteractionStyle,vtkRenderingFreeType,vtkRenderingOpenGL2)" -isystem /usr/include/vtk-7.1 -isystem /usr/include/freetype2 -isystem /usr/include/x86_64-linux-gnu -isystem /usr/local/include/pcl-1.9 -isystem /usr/include/eigen3 -I/home/bob/Desktop/choc/include -I/usr/include/python3.7m -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++  -Wno-old-style-cast    -Wno-old-style-cast -march=native -msse4.2 -mfpmath=sse -fPIC -std=gnu++14 -o CMakeFiles/train.dir/src/train.cpp.o -c /home/bob/Desktop/choc/src/train.cpp

最佳答案

一些 pcl 库使用 Diagnostic Pragmas 设置 -Wold-style-cast 警告。出于这个原因,无论您在 cmake 配置中设置什么,都应该出现此警告。在包含 pcl header 之前使用 pragmas 禁用它解决了我的问题。

#include <pcl/surface/concave_hull.h>

#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif

关于C++:在 CMake 中禁用旧式转换警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58012550/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com