gpt4 book ai didi

c++ - cmake 找到库但未包含在生成的 makefile 中

转载 作者:行者123 更新时间:2023-11-28 07:07:44 25 4
gpt4 key购买 nike

我正在尝试使用 CMake 编译一个使用 boost 的多文件 C++ 项目。我的 CMakeLists.txt 文件如下所示:

cmake_minimum_required(VERSION 2.8)
set(Boost_USE_STATIC_LIBS ON) # only find static libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.53.0 COMPONENTS serialization)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(RandomFor RandomFor.cpp)
target_link_libraries(RandomFor ${Boost_LIBRARIES})
endif()

当我运行 cmake .. 我得到以下输出

CMake ..

-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:492 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:494 ] Boost_USE_MULTITHREADED = ON
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:496 ] Boost_USE_STATIC_LIBS = ON
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:498 ] Boost_USE_STATIC_RUNTIME = OFF
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:500 ] Boost_ADDITIONAL_VERSIONS =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:502 ] Boost_NO_SYSTEM_PATHS =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:554 ] Declared as CMake or Environmental Variables:
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:556 ] BOOST_ROOT =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:558 ] BOOST_INCLUDEDIR =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:560 ] BOOST_LIBRARYDIR =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:562 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:655 ] location of version.hpp: /usr/include/boost/version.hpp
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:679 ] version.hpp reveals boost 1.53.0
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:755 ] guessed _boost_COMPILER = -gcc48
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:765 ] _boost_MULTITHREADED = -mt
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:808 ] _boost_RELEASE_ABI_TAG = -
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:810 ] _boost_DEBUG_ABI_TAG = -d
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:859 ] _boost_LIBRARY_SEARCH_DIRS = /usr/lib/x86_64-linux-gnu;NO_DEFAULT_PATH
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:947 ] Searching for SERIALIZATION_LIBRARY_RELEASE: boost_serialization-gcc48-mt-1_53;boost_serialization-gcc48-mt;boost_serialization-mt-1_53;boost_serialization-mt;boost_serialization
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:983 ] Searching for SERIALIZATION_LIBRARY_DEBUG: boost_serialization-gcc48-mt-d-1_53;boost_serialization-gcc48-mt-d;boost_serialization-mt-d-1_53;boost_serialization-mt-d;boost_serialization-mt;boost_serialization
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:1034 ] Boost_FOUND = 1
-- Boost version: 1.53.0
-- Found the following Boost libraries:
-- serialization
-- Configuring done
-- Generating done
-- Build files have been written to: /home/tladd/SeniorDesign/RandomForest/RandomForest/build

好像是找到序列化库了。当我运行 make 时,我在尝试构建时遇到错误,表明它找不到 serialization.hpp:

[100%] Building CXX object CMakeFiles/RandomFor.dir/RandomFor.cpp.o
In file included from /home/tladd/SeniorDesign/RandomForest/RandomForest/SerializeHelper.h:1:0,
from /home/tladd/SeniorDesign/RandomForest/RandomForest/RandomFor.cpp:14:
/home/tladd/SeniorDesign/RandomForest/RandomForest/ITreeNode.h:5:49: fatal error: boost\serialization\serialization.hpp: No such file or directory
#include "boost\serialization\serialization.hpp"
^
compilation terminated.
make[2]: *** [CMakeFiles/RandomFor.dir/RandomFor.cpp.o] Error 1
make[1]: *** [CMakeFiles/RandomFor.dir/all] Error 2
make: *** [all] Error 2

这是 cmake 生成的 Makefile:

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target

#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:

# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list

# Suppress display of executed commands.
$(VERBOSE).SILENT:

# A target that is always out of date.
cmake_force:
.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/tladd/SeniorDesign/RandomForest/RandomForest

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/tladd/SeniorDesign/RandomForest/RandomForest/build

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..."
/usr/bin/cmake -i .
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast

# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast

# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /home/tladd/SeniorDesign/RandomForest/RandomForest/build/CMakeFiles /home/tladd/SeniorDesign/RandomForest/RandomForest/build/CMakeFiles/progress.marks
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start /home/tladd/SeniorDesign/RandomForest/RandomForest/build/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean
.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named RandomFor

# Build rule for target.
RandomFor: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 RandomFor
.PHONY : RandomFor

# fast build rule for target.
RandomFor/fast:
$(MAKE) -f CMakeFiles/RandomFor.dir/build.make CMakeFiles/RandomFor.dir/build
.PHONY : RandomFor/fast

RandomFor.o: RandomFor.cpp.o
.PHONY : RandomFor.o

# target to build an object file
RandomFor.cpp.o:
$(MAKE) -f CMakeFiles/RandomFor.dir/build.make CMakeFiles/RandomFor.dir/RandomFor.cpp.o
.PHONY : RandomFor.cpp.o

RandomFor.i: RandomFor.cpp.i
.PHONY : RandomFor.i

# target to preprocess a source file
RandomFor.cpp.i:
$(MAKE) -f CMakeFiles/RandomFor.dir/build.make CMakeFiles/RandomFor.dir/RandomFor.cpp.i
.PHONY : RandomFor.cpp.i

RandomFor.s: RandomFor.cpp.s
.PHONY : RandomFor.s

# target to generate assembly for a file
RandomFor.cpp.s:
$(MAKE) -f CMakeFiles/RandomFor.dir/build.make CMakeFiles/RandomFor.dir/RandomFor.cpp.s
.PHONY : RandomFor.cpp.s

# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... RandomFor"
@echo "... edit_cache"
@echo "... rebuild_cache"
@echo "... RandomFor.o"
@echo "... RandomFor.i"
@echo "... RandomFor.s"
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

其中似乎没有提及 Boost。关于为什么生成的 Makefile 不起作用的任何帮助?

最佳答案

根据您尝试编译的编译器(可能还有操作系统),您不得在包含指令中使用反斜杠。

尝试像这样包含:

#include <boost/serialization/serialization.hpp>

关于c++ - cmake 找到库但未包含在生成的 makefile 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21514444/

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