我正试图让包括-你用什么?第一次使用我的代码库。
我的CentOS6系统默认安装了g++ 4.4.7。我在我的g++项目中使用了C++11 4.9.3。这四种选择都是不灵活的。
我为我的项目有效地构建了cmake数据库,如下所示:
%> export CXX=/path/to/gcc-4.9.3/bin/g++
%> export CC=/path/to/gcc-4.9.3/bin/gcc
%> mkdir $HOME/dev/build
%> cd $HOME/dev/build
%> cmake .. -GNinja -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE=/path/to/iwyu-6/bin/include-what-you-use当我编译我的项目时,输出如下:
...
Warning: include-what-you-use reported diagnostics:
In file included from ../dev/src/whatever/foo.cc:13:
In file included from ../dev/src/whatever/foo.h:17:
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/string:42:
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/char_traits.h:41:
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_algobase.h:61:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/cstddef:44:10: fatal error: 'stddef.h' file not found
#include <stddef.h>
^~~~~~~~~~
../dev/src/whatever/foo.h should add these lines:
../dev/src/whatever/foo.h should remove these lines:
- #include <deque> // lines 18-18
The full include-list for ../dev/src/trekcc/pss_dsl/pssTypes.h:
#include <string> // for string
...太棒了!我不需要deque.h在那个文件,所以这个工具有点工作!
但警告令人沮丧..。当然,stddef.h是通过我的实际编译找到的,因为它实际上是在gcc-4.9.3下面定义的:
/path/to/gcc-4.9.3/lib/gcc/x86_64-unknown-linux-gnu/4.9.3/include/stddef.h问:如何更改我的${CMAKE_CXX_INCLUDE_WHAT_YOU_USE}变量,使工具看起来低于gcc-4.9.3,而不是默认的gcc-4.4.7
请注意,如果我要求cmake导出JSON编译命令,这个条目如下所示:
{
"directory": "/home/me/dev/build",
"command": "/tools/gnu/gcc-4.9.3/bin/g++ -I../dev/foo -I../dev/bar -I/path/to/boost_1_66_0/include -I/path/to/graphviz-2.38.0/include -I/path/to/graphviz-2.38.0/include/graphviz -I../include -Wall --std=c++11 -Wno-parentheses -fPIC -D_GLIBCXX_USE_CXX11_ABI=0 -g -o dev/whatever/foo.cc.o -c /home/me/dev/src/whatever/foo.cc",
"file": "/home/me/dev/src/whatever/foo.cc"
}谢谢!
编辑:
Per @KamilCuk在下面的建议中,在iwyu命令中添加一个sysroot似乎可以消除4.4.7警告。
%> cmake .. -GNinja -DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="/path/to/iwyu-6/bin/include-what-you-use;-Xiwyu;--mapping_file=../iwyu.imp;--sysroot;/path/to/gcc-4.9.3/lib/gcc/x86_64-unknown-linux-gnu/4.9.3"它现在找不到像<map>或<vector>这样的基础,但是4.4.7警告已经消失了,这告诉我我们在正确的轨道上!
使用--sysroot /path/to/gcc-4.9.3/include/c++/4.9.3并不能解决这个问题。对于许多常见的文件,我会收到许多这样的错误:
Warning: include-what-you-use reported diagnostics:
../dev/whatever/foo.cc:12:10: fatal error: 'sstream' file not found
#include <sstream>
^~~~~~~~~发布于 2021-07-16 08:26:19
也许你应该使用一个工具链文件。在我的项目中(特别是在交叉编译中),我将创建一个专用文件夹,将所有的工具链和其他cmake命令放在其中。
my_proj
cmake
other_gcc.cmake
CMakeLists.txt
...例如,下面是用于交叉编译的other_gcc.cmake的一个版本:
# Define our host system
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
# Define the cross compiler locations
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
# Define the sysroot path for the RaspberryPi distribution in our tools folder
#set(CMAKE_FIND_ROOT_PATH $ENV{AARCH64_LINUX_TOOLS_DIR}/aarch64-linux-gnu/sysroot)
# Use our definitions for compiler tools
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)这与您相关,因为您还需要更改编译器。也许您可以对用例中的前3条CMAKE_SYSTEM_命令进行注释。
然后,在配置步骤中,只需告诉Cmake您想使用这个工具链文件:
cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/other_gcc.cmake ..https://stackoverflow.com/questions/68275792
复制相似问题