【问题标题】:CMake builds when in directory, but it won't when add_subdirectory is usedCMake 在目录中构建,但在使用 add_subdirectory 时不会
【发布时间】:2021-05-29 04:19:21
【问题描述】:

我不知道如何解释原因,但是当我在目录中运行 cmake 时,它​​可以正常工作。如果我上一层并在 CMakeLists.txt 中使用 Add_SubDirectory,那么它就坏了。

我会放下步骤。

  1. mkdir 我的文件夹
  2. git 克隆https://github.com/mariadb-corporation/mariadb-connector-c.git

这些步骤可以证明构建有效:

  1. cd mariadb-connector-c
  2. mkdir build && cd build
  3. cmake -G Ninja ..
  4. 忍者

好的,效果很好。所以接下来尝试上一层:

  1. cd ../..(现在位于“MyFolder”中)
  2. 使用此源添加 CMakeLists.txt。
cmake_minimum_required(VERSION 3.0.0)
project(mariadb VERSION 1.0.0)

add_subdirectory(mariadb-connector-c)
  1. mkdir build & cd build
  2. cmake -G Ninja ..

现在它爆炸了。有谁知道为什么会这样?

编辑

这里的要求是作为子项目构建时日志的第一个错误。

Determining if files select.h exist failed with the following output:
Change Dir: /home/questionable/Desktop/Programming/source-mariadb/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/ninja cmTC_c650d && [1/2] Building C object CMakeFiles/cmTC_c650d.dir/HAVE_SELECT_H.c.o
FAILED: CMakeFiles/cmTC_c650d.dir/HAVE_SELECT_H.c.o 
/usr/bin/cc   -Wunused -Wlogical-op -Wno-uninitialized -Wall -Wextra -Wformat-security -Wno-init-self -Wwrite-strings -Wshift-count-overflow -Wdeclaration-after-statement -Wno-undef -Wno-unknown-pragmas -o CMakeFiles/cmTC_c650d.dir/HAVE_SELECT_H.c.o   -c /home/questionable/Desktop/Programming/source-mariadb/build/CMakeFiles/CheckIncludeFiles/HAVE_SELECT_H.c
/home/questionable/Desktop/Programming/source-mariadb/build/CMakeFiles/CheckIncludeFiles/HAVE_SELECT_H.c:2:10: fatal error: select.h: No such file or directory
    2 | #include <select.h>
      |          ^~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.


Source:
/* */
#include <select.h>


int main(void){return 0;}

【问题讨论】:

  • 定义“爆炸”。你得到什么错误?
  • 这是错误、页面和页面的完整日志。第一个错误是找不到,最后一个错误是-lpthread不存在。
  • 除非 CMake 项目的文档/README 明确指定它可以构建为子项目,否则没有人保证它可以以这种方式建造的。嗯,通常一个很好的假设,可以将特定项目构建为子项目。但是,如果您希望我们调试该用法,则需要更详细地了解您的问题。例如。显示您收到的确切错误消息。像往常一样,如果您的错误日志太长,通常只显示第一条错误消息就足够了。
  • 不,不显示CMakeErrorLog.txt 文件的内容:这些错误消息大多不是“真实的”。在 CMake 输出中显示错误消息。
  • 请发布整个错误日志,所有页面和所有页面。也请详细编译(make VERBOSE=1cmake --verbose --build ..)以获得更多页面的错误日志,然后将其全部发布。您发布了用于检测select.h 的部分CMakeErrorLog - 我认为它甚至与问题无关,它只是检测select.h,并且确定它应该丢失,它是sys/select.h

标签: cmake


【解决方案1】:

我在 cmake configure 阶段从您的来源得到的错误是:

CMake Deprecation Warning at mariadb-connector-c/CMakeLists.txt:5 (CMAKE_MINIMUM_REQUIRED):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


CMake Warning (dev) at mariadb-connector-c/CMakeLists.txt:19 (PROJECT):
  Policy CMP0048 is not set: project() command manages VERSION variables.
  Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The following variable(s) would be set to empty:

    PROJECT_VERSION
    PROJECT_VERSION_MAJOR
    PROJECT_VERSION_MINOR
    PROJECT_VERSION_PATCH
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at mariadb-connector-c/cmake/install_plugins.cmake:11 (INSTALL):
  INSTALL TARGETS given no LIBRARY DESTINATION for module target "dialog".
Call Stack (most recent call first):
  mariadb-connector-c/cmake/plugins.cmake:82 (INSTALL_PLUGIN)
  mariadb-connector-c/plugins/auth/CMakeLists.txt:30 (REGISTER_PLUGIN)
  mariadb-connector-c/plugins/CMakeLists.txt:7 (INCLUDE)
  mariadb-connector-c/CMakeLists.txt:392 (INCLUDE)


CMake Error at mariadb-connector-c/cmake/install_plugins.cmake:11 (INSTALL):
  INSTALL TARGETS given no LIBRARY DESTINATION for module target
  "client_ed25519".
Call Stack (most recent call first):
  mariadb-connector-c/cmake/plugins.cmake:82 (INSTALL_PLUGIN)
  mariadb-connector-c/plugins/auth/CMakeLists.txt:54 (REGISTER_PLUGIN)
  mariadb-connector-c/plugins/CMakeLists.txt:7 (INCLUDE)
  mariadb-connector-c/CMakeLists.txt:392 (INCLUDE)


CMake Error at mariadb-connector-c/cmake/install_plugins.cmake:11 (INSTALL):
  INSTALL TARGETS given no LIBRARY DESTINATION for module target
  "caching_sha2_password".
Call Stack (most recent call first):
  mariadb-connector-c/cmake/plugins.cmake:82 (INSTALL_PLUGIN)
  mariadb-connector-c/plugins/auth/CMakeLists.txt:70 (REGISTER_PLUGIN)
  mariadb-connector-c/plugins/CMakeLists.txt:7 (INCLUDE)
  mariadb-connector-c/CMakeLists.txt:392 (INCLUDE)


CMake Error at mariadb-connector-c/cmake/install_plugins.cmake:11 (INSTALL):
  INSTALL TARGETS given no LIBRARY DESTINATION for module target
  "sha256_password".
Call Stack (most recent call first):
  mariadb-connector-c/cmake/plugins.cmake:82 (INSTALL_PLUGIN)
  mariadb-connector-c/plugins/auth/CMakeLists.txt:81 (REGISTER_PLUGIN)
  mariadb-connector-c/plugins/CMakeLists.txt:7 (INCLUDE)
  mariadb-connector-c/CMakeLists.txt:392 (INCLUDE)


CMake Error at mariadb-connector-c/cmake/install_plugins.cmake:11 (INSTALL):
  INSTALL TARGETS given no LIBRARY DESTINATION for module target
  "auth_gssapi_client".
Call Stack (most recent call first):
  mariadb-connector-c/cmake/plugins.cmake:82 (INSTALL_PLUGIN)
  mariadb-connector-c/plugins/auth/CMakeLists.txt:106 (REGISTER_PLUGIN)
  mariadb-connector-c/plugins/CMakeLists.txt:7 (INCLUDE)
  mariadb-connector-c/CMakeLists.txt:392 (INCLUDE)


CMake Error at mariadb-connector-c/cmake/install_plugins.cmake:11 (INSTALL):
  INSTALL TARGETS given no LIBRARY DESTINATION for module target
  "mysql_clear_password".
Call Stack (most recent call first):
  mariadb-connector-c/cmake/plugins.cmake:82 (INSTALL_PLUGIN)
  mariadb-connector-c/plugins/auth/CMakeLists.txt:126 (REGISTER_PLUGIN)
  mariadb-connector-c/plugins/CMakeLists.txt:7 (INCLUDE)
  mariadb-connector-c/CMakeLists.txt:392 (INCLUDE)


CMake Error at mariadb-connector-c/cmake/install_plugins.cmake:11 (INSTALL):
  INSTALL TARGETS given no LIBRARY DESTINATION for module target "remote_io".
Call Stack (most recent call first):
  mariadb-connector-c/cmake/plugins.cmake:82 (INSTALL_PLUGIN)
  mariadb-connector-c/plugins/io/CMakeLists.txt:7 (REGISTER_PLUGIN)
  mariadb-connector-c/plugins/CMakeLists.txt:7 (INCLUDE)
  mariadb-connector-c/CMakeLists.txt:392 (INCLUDE)


-- Configuring incomplete, errors occurred!
See also "/home/kamil/tmp/test/build/CMakeFiles/CMakeOutput.log".
See also "/home/kamil/tmp/test/build/CMakeFiles/CMakeError.log".

install.cmake 中似乎有问题。看起来很奇怪 INSTALL_PLUGINDIR 没有设置,所以 DESTINATION 的参数 install 没有参数... :/ 。以下:

cmake_minimum_required(VERSION 3.0.0)
project(mariadb VERSION 1.0.0)

set(INSTALL_PLUGINDIR /some/path)
add_subdirectory(mariadb-connector-c)

允许构建项目。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 2021-02-19
    • 1970-01-01
    相关资源
    最近更新 更多