【问题标题】:cmake acting differently when compiling in different directoriescmake 在不同目录中编译时的行为不同
【发布时间】:2021-02-12 18:40:41
【问题描述】:

我的文件结构如下:

gameFolder 
|-cmake-build-debug
|-CMakeLists.txt **for clion build**
|-src
  |-example.cpp
  |-example.h
|-emscripten **web build**
  |-build
  |-CMakeLists.txt

这里的问题是当我在 emscripten 下的 build 文件夹中运行 cmake .. 时,cmake 无法找到 boost 库,但是当我在emscripten 文件夹直接构建我的项目。

我只想知道这里发生了什么?是否有一些秘密的奇怪编译器正在发生?为什么我必须在与文本文件相同的文件夹中运行 cmake?

编辑: 这是我的 enscripten/CMakeLists.txt

cmake_minimum_required(VERSION 3.17)
project(FernQuest)

message(STATUS "running cmake...")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out)

include_directories(.)


message(STATUS "finding boost!")
find_package(Boost 1.74.0 REQUIRED serialization system filesystem COMPONENTS serialization system filesystem)

if(Boost_FOUND)
    message(STATUS "found boost!")
endif()

include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

if(NOT Boost_FOUND)
    message(FATAL_ERROR "Could not find boost!")
endif()

message(STATUS "setting sources")
SET(FQ_SRCS
    ../src/FernQuest.cpp
    ../src/Item.cpp
    ../src/Item.h
    ../src/Player.cpp
    ../src/Player.h
    ../src/Game.cpp
    ../src/Game.h
    ../src/QuestLog.cpp
    ../src/QuestLog.h)


SET(CMAKE_C_COMPILER emcc)
SET(CMAKE_CPP_COMPILER em++)


add_executable(FernQuest.html ${FQ_SRCS})


if(Boost_FOUND)
    message(STATUS "found boost!")
    target_link_libraries(FernQuest.html)
    target_link_libraries(FernQuest.html ${Boost_LIBRARIES})
endif()

以及我按照描述运行它时遇到的错误

build % cmake ..
-- running cmake...
-- finding boost!
CMake Error at /usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:218 (message):
  Could NOT find Boost (missing: Boost_INCLUDE_DIR serialization system
  filesystem serialization system filesystem) (Required is at least version
  "1.74.0")
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:582 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/3.19.4/share/cmake/Modules/FindBoost.cmake:2193 (find_package_handle_standard_args)
  CMakeLists.txt:13 (find_package)


-- Configuring incomplete, errors occurred!

【问题讨论】:

  • 从哪个目录运行cmake 无关紧要,除非您的CMakeLists.txt 中存在错误。请编辑您的帖子以包含 emscripten/CMakeLists.txt 的内容以及完整的错误文本。
  • 由于某种原因,cmake 似乎寻找提升的地方似乎取决于构建目录!?不知道为什么。可用信息太少。
  • 我更新了帖子,这不是什么大问题,因为我可以运行 cmake 。 它只会打乱我的整个构建流程
  • boost 安装在哪里,cmake 是如何定位的?

标签: c++ boost cmake c++14 emscripten


【解决方案1】:

所以我偶然发现了一个解决方案:

include_directories("path-to-emscripten")

对我来说,它是使用 brew 安装的,所以我只是在顶部输入它,它就成功了

include_directory("/usr/local/Cellar")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-21
    • 2011-03-09
    • 2019-11-07
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多