Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ CMake在include\u目录中找不到正确的头文件/包含文件_C++_Compilation_Cmake - Fatal编程技术网

C++ CMake在include\u目录中找不到正确的头文件/包含文件

C++ CMake在include\u目录中找不到正确的头文件/包含文件,c++,compilation,cmake,C++,Compilation,Cmake,当我尝试编译时,再次出现“架构x86_64的未定义符号”错误。我已经尝试了超过我在这篇文章中实际记录的内容(因为我已经忘记了我所尝试的一切)。这是一个非常简单的设置,应该很容易用CMake编译 当我在这上面运行make时,它工作得很好。但我想将其转换为CMake以实现互操作性。正如您所看到的,我在一些地方抛出了我的“${HEADERS}”变量,我已经尝试了很多地方,但是我一直得到我的错误。根据我将${HEADER}放在何处,从技术上讲,它还可以生成一个错误“error:cannotspecify

当我尝试编译时,再次出现“架构x86_64的未定义符号”错误。我已经尝试了超过我在这篇文章中实际记录的内容(因为我已经忘记了我所尝试的一切)。这是一个非常简单的设置,应该很容易用CMake编译

当我在这上面运行make时,它工作得很好。但我想将其转换为CMake以实现互操作性。正如您所看到的,我在一些地方抛出了我的“${HEADERS}”变量,我已经尝试了很多地方,但是我一直得到我的错误。根据我将${HEADER}放在何处,从技术上讲,它还可以生成一个错误“error:cannotspecify-o when generating multiple output file”(如果它仅位于target\u link\u library声明中,则适用)

我有两个文件夹:

Root
    Headers (contains all .h files)
    Source (contains all .cc/.cpp/.c files) (and also a CMakeLists.txt)
CMakeLists.txt
我的根CMakeLists.txt包含以下内容:

cmake_minimum_required(VERSION 2.8.4)
project(Framework)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_compile_options("-v")

add_subdirectory(Source)

#Variables for making my life easier and adding the headers
set(H Headers)
include_directories(${H})
set(S Source)
file(GLOB HEADERS
#Add any file in the headers dir
"${H}/*"
)

# Create a variable to use for main.cc
set(MAIN ${S}/main.cc ${HEADERS})

# Add the main.cc file and headers
add_executable(Framework ${MAIN} ${HEADERS})

# Add the .cc/.cpp files
target_link_libraries(Framework ${SOURCE_FILES})
file(GLOB SOURCES
"*.cc"
"*.cpp"
)

add_library(SOURCE_FILES ${SOURCES})
我的源目录中的My CMakeLists.txt包含以下内容:

cmake_minimum_required(VERSION 2.8.4)
project(Framework)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_compile_options("-v")

add_subdirectory(Source)

#Variables for making my life easier and adding the headers
set(H Headers)
include_directories(${H})
set(S Source)
file(GLOB HEADERS
#Add any file in the headers dir
"${H}/*"
)

# Create a variable to use for main.cc
set(MAIN ${S}/main.cc ${HEADERS})

# Add the main.cc file and headers
add_executable(Framework ${MAIN} ${HEADERS})

# Add the .cc/.cpp files
target_link_libraries(Framework ${SOURCE_FILES})
file(GLOB SOURCES
"*.cc"
"*.cpp"
)

add_library(SOURCE_FILES ${SOURCES})
我没有一个在标题,因为,我相信,文件说明,我们不需要

谢谢你的帮助。我看过:

  • (适用于2.x版和3.x版)
  • --有可能找到解决方案,但最后说“我不知道”:(
  • 以及许多其他各种邮件列表和其他网站

这里的主要问题是,您引用的是
源文件
目标文件,就好像它是一个变量一样。请删除美元符号和大括号

target_link_libraries(Framework SOURCE_FILES)
调用
add_subdirectory
后设置
include_目录
似乎也有点奇怪,如果这样做有效,我会感到惊讶

总的来说,我认为你让事情变得比需要的更复杂了。以下是所有必要的

顶级CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(Framework CXX)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic")

include_directories(
  ${PROJECT_SOURCE_DIR}/Headers
)

add_subdirectory(Source)
# Do not use file globing because then CMake is not able to tell whether a file
# has been deleted or added when rebuilding the project.
set(HELLO_LIB_SRC
  hello.cc
)
add_library(hello ${HELLO_LIB_SRC})

set(MAIN_SRC
  main.cc
)
add_executable(hello_bin ${MAIN_SRC})
target_link_libraries(hello_bin hello)
Source/CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(Framework CXX)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic")

include_directories(
  ${PROJECT_SOURCE_DIR}/Headers
)

add_subdirectory(Source)
# Do not use file globing because then CMake is not able to tell whether a file
# has been deleted or added when rebuilding the project.
set(HELLO_LIB_SRC
  hello.cc
)
add_library(hello ${HELLO_LIB_SRC})

set(MAIN_SRC
  main.cc
)
add_executable(hello_bin ${MAIN_SRC})
target_link_libraries(hello_bin hello)
标题/hello.h

#pragma once

#include <string>

namespace nope
{
  std::string hello_there();
}

你,先生,一个救命恩人。我操纵了另一个项目中的一个旧CMake,它的设置完全不同;它显然不起作用。因此,链接库或添加可执行文件的位置无关紧要,只要它存在?我不确定你的意思。当你使用像add_executable/add_library/这样的函数时,你就创建了一个目标。你可以在特定目标之后或之前创建的其他目标中依赖此目标。CMake将确保在结束时满足所有依赖项,否则会发出尖叫。