CMake项目Boost库错误:boost/config/compiler/gcc.hpp:165:10:致命错误:cstddef:没有这样的文件或目录
Posted
技术标签:
【中文标题】CMake项目Boost库错误:boost/config/compiler/gcc.hpp:165:10:致命错误:cstddef:没有这样的文件或目录【英文标题】:CMake project Boost library error : boost/config/compiler/gcc.hpp:165:10: fatal error: cstddef: No such file or directory 【发布时间】:2020-02-25 11:34:36 【问题描述】:我正在开发 C++ 代码。 我正在使用 VisualStudio CMake 项目。
我成功地将我的 Boost 1.66 版本库添加到了我的 CMake 项目中。
这是我的 CMakeLists.txt 文件:
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
SET(CMAKE_C_COMPILER_WORKS TRUE CACHE INTERNAL "")
SET(CMAKE_CXX_COMPILER_WORKS TRUE CACHE INTERNAL "")
SET(CMAKE_C_COMPILER_FORCED TRUE CACHE INTERNAL "")
SET(CMAKE_CXX_COMPILER_FORCED TRUE CACHE INTERNAL "")
SET(CMAKE_C_COMPILER_ID_RUN TRUE CACHE INTERNAL "")
SET(CMAKE_CXX_COMPILER_ID_RUN TRUE CACHE INTERNAL "")
project(CMakeProject4 CXX)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
list(APPEND CMAKE_PREFIX_PATH /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr)
set(Boost_NO_BOOST_CMAKE ON)
message(STATUS "CMAKE_TOOLCHAIN_FILE='$CMAKE_TOOLCHAIN_FILE'")
set(CROSS_COMPILER_DIR /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr)
set(CMAKE_C_COMPILER $CROSS_COMPILER_DIR/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER $CROSS_COMPILER_DIR/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++)
message(STATUS "CMAKE_C_COMPILER='$CMAKE_C_COMPILER'")
message(STATUS "CMAKE_CXX_COMPILER='$CMAKE_CXX_COMPILER'")
find_package(Boost 1.66.0 REQUIRED)
add_executable (CMakeProject4 CMakeProject4.cpp CMakeProject4.h)
target_link_libraries(CMakeProject4 PRIVATE Boost::headers)
当我保存这个文件时,我可以看到:
1> /home/ubuntu/.vs/cmake/bin/cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DBoost_INCLUDE_DIRS:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_LIBRARIES:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/lib" -DBoost_INCLUDE_DIR:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_DEBUG=ON -DCMAKE_TOOLCHAIN_FILE=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake -DCMAKE_INSTALL_PREFIX=/home/ubuntu/CMake/RemoteIL "/home/ubuntu/CMake/RemoteCML/CMakeLists.txt";
1> [CMake] -- CMAKE_TOOLCHAIN_FILE='/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake'
1> [CMake] -- CMAKE_C_COMPILER='/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc'
1> [CMake] -- CMAKE_CXX_COMPILER='/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-g++'
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1427 ] _boost_TEST_VERSIONS = "1.70.0;1.70;1.69.0;1.69;1.68.0;1.68;1.67.0;1.67;1.66.0;1.66"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1428 ] Boost_USE_MULTITHREADED = "OFF"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1429 ] Boost_USE_STATIC_LIBS = "ON"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1430 ] Boost_USE_STATIC_RUNTIME = "OFF"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1431 ] Boost_ADDITIONAL_VERSIONS = <unset>
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1432 ] Boost_NO_SYSTEM_PATHS = <unset>
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1501 ] BOOST_ROOT = <unset>
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1502 ] ENVBOOST_ROOT = <unset>
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1503 ] BOOST_INCLUDEDIR = <unset>
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1504 ] ENVBOOST_INCLUDEDIR = <unset>
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1505 ] BOOST_LIBRARYDIR = <unset>
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1506 ] ENVBOOST_LIBRARYDIR = <unset>
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1594 ] location of version.hpp: /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/boost/version.hpp
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1634 ] Boost_VERSION = "106600"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1635 ] Boost_VERSION_STRING = "1.66.0"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1636 ] Boost_VERSION_MACRO = "106600"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1637 ] Boost_VERSION_MAJOR = "1"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1638 ] Boost_VERSION_MINOR = "66"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1639 ] Boost_VERSION_PATCH = "0"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1640 ] Boost_VERSION_COUNT = "3"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1657 ] Boost_LIB_PREFIX = ""
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1658 ] Boost_NAMESPACE = "boost"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:766 ] _boost_COMPILER = "-gcc74" (guessed)
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1694 ] _boost_MULTITHREADED = ""
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1771 ] _boost_ARCHITECTURE_TAG = "" (detected)
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1775 ] _boost_RELEASE_ABI_TAG = "-"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1776 ] _boost_DEBUG_ABI_TAG = "-d"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1836 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/lib;/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/../lib;/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
1> [CMake] -- [ /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/FindBoost.cmake:1837 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/lib;/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/../lib;/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: /home/ubuntu/CMake/RemoteBR
1> Extracted includes paths.
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> CMake generation finished.
我将使用arm-poky-linux-gnueabi-g++
编译器来编译我的 C++ 程序:
#include "CMakeProject4.h"
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
typedef std::istream_iterator<int> in;
std::cout << "Type in any number: ";
std::for_each(
in(std::cin), in(), std::cout
<< (boost::lambda::_1 * 10)
<< "\nType in another number: ");
但是当我运行程序时,会出现这个错误:
[ 50%] Building CXX object CMakeProject4/CMakeFiles/CMakeProject4.dir/CMakeProject4.cpp.o
In file included from /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/boost/config.hpp:39:0,
from /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/boost/type_traits/remove_reference.hpp:12,
from /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/boost/type_traits/add_pointer.hpp:12,
from /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/boost/type_traits/transform_traits.hpp:15,
from /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/boost/lambda/core.hpp:25,
from /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/boost/lambda/lambda.hpp:14,
from /home/ubuntu/CMake/RemoteCML/CMakeProject4/CMakeProject4.cpp:5:
/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include/boost/config/compiler/gcc.hpp:165:10: fatal error: cstddef: No such file or directory
#include <cstddef>
^~~~~~~~~
compilation terminated.
CMakeProject4/CMakeFiles/CMakeProject4.dir/build.make:62: recipe for target 'CMakeProject4/CMakeFiles/CMakeProject4.dir/CMakeProject4.cpp.o' failed
CMakeFiles/Makefile2:93: recipe for target 'CMakeProject4/CMakeFiles/CMakeProject4.dir/all' failed
CMakeFiles/Makefile2:100: recipe for target 'CMakeProject4/CMakeFiles/CMakeProject4.dir/rule' failed
Makefile:118: recipe for target 'CMakeProject4' failed
make[3]: *** [CMakeProject4/CMakeFiles/CMakeProject4.dir/CMakeProject4.cpp.o] Error 1
make[2]: *** [CMakeProject4/CMakeFiles/CMakeProject4.dir/all] Error 2
make[1]: *** [CMakeProject4/CMakeFiles/CMakeProject4.dir/rule] Error 2
make: *** [CMakeProject4] Error 2
Build failed.
有人可以帮我吗?
【问题讨论】:
【参考方案1】:这不是答案,但评论太长了,所以。
我记得在交叉编译(linux x86_64 到 linux armhf)时遇到了这个问题,但我不记得我到底做了什么。我知道我或多或少地遵循了这些步骤:
-
运行 cmake 而不构建任何东西,仅用于配置。
运行 make 时(我假设您手动运行),运行:
VERBOSE=1 make
-
复制失败的确切执行行,例如
g++ -I/.../ -pthread -o file.o -c file.cpp
进入构建目录并执行此行添加-v
选项,所以如果行如上,运行:
g++ -I/.../ -pthread -o file.o -c file.cpp -v
-
GCC 将打印有关包含目录的信息等。在我的情况下,这类似于:
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/opt/ZS/deps/lib/gcc/x86_64-linux-gnu/9.2.0/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/ZS/deps/include
/home/jd/code/config/.
/opt/ZS/deps/lib/gcc/x86_64-linux-gnu/9.2.0/../../../../include/c++/9.2.0
/opt/ZS/deps/lib/gcc/x86_64-linux-gnu/9.2.0/../../../../include/c++/9.2.0/x86_64-linux-gnu
/opt/ZS/deps/lib/gcc/x86_64-linux-gnu/9.2.0/../../../../include/c++/9.2.0/backward
/opt/ZS/deps/lib/gcc/x86_64-linux-gnu/9.2.0/include
/usr/local/include
/opt/ZS/deps/lib/gcc/x86_64-linux-gnu/9.2.0/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
请注意,在我上面的输出中(这是真正的输出)有两个以ignoring nonexistent directory
开头的条目。
检查这些不存在的目录,并仔细检查列出的任何现有目录中是否有文件 cstddef(可能在#include <...> search starts here:
之后)。
希望能有所帮助。
【讨论】:
好吧..也许我做了你提到的坏事或者我是对的..但这无济于事 所以我假设gcc显示的路径中有标题cstddef?我记得有这个错误的现场日,但似乎解决方案非常容易 - 尽管我真的不记得它是什么。对不起。以上是关于CMake项目Boost库错误:boost/config/compiler/gcc.hpp:165:10:致命错误:cstddef:没有这样的文件或目录的主要内容,如果未能解决你的问题,请参考以下文章
Cmake 无法在 Homebrew 中找到 boost_pyhton 库