这个标题怎么看?

Posted

技术标签:

【中文标题】这个标题怎么看?【英文标题】:How can this header be seen? 【发布时间】:2016-07-11 22:50:45 【问题描述】:

我一直在尝试理解 CMake,最近我偶然发现了 CLion ide。到目前为止,它有所帮助。 在尝试将谷歌测试与 CLion 集成时,我克隆了 this github repo.

但是,我不明白保存测试方法的 .cpp 文件如何在它们位于错误的相对路径时“看到”库的头文件!

Calendar_check.cpp:

//
// Created by AK on 13/10/15.
//

#include "gtest/gtest.h"

#include "GregorianCalendar.h"
#include "JulianCalendar.h"
///Code that runs tests, not important for this question

但是,目录结构是这样设置的:

看看项目是如何设置的,不应该把calendar_check.cpp文件的#include语句读完

改为#include "../../calendars/GregorianCalendar.h" #include "../../calendars/JulianCalendar.h"

我知道静态库没有头文件,所以我不明白calendar_test.cpp 文件如何知道这些头在哪里使用它们使用的路径。

这里是 CMakeLists.txt 文件:

根:

cmake_minimum_required(VERSION 3.1)
project(Calendar)

#add_definitions(-std=c++11 --target=x86_64-linux-gnu)
#set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(calendar_run $SOURCE_FILES)

include_directories(calendars)

add_subdirectory(calendars)
add_subdirectory(calendars_tests)


target_link_libraries(calendar_run calendars)

根/日历:

project(calendars)

set(HEADER_FILES
        calendar_defs.h
        General.h
        GregorianCalendar.h
        JulianCalendar.h
        IslamicCalendar.h
        HebrewCalendar.h
    )

set(SOURCE_FILES
        calendar_defs.cpp
        Calendar.cpp
        General.cpp
        GregorianCalendar.cpp
        JulianCalendar.cpp
        IslamicCalendar.cpp
        HebrewCalendar.cpp
    )

add_library(calendars STATIC $SOURCE_FILES $HEADER_FILES)

root/calendar_tests:

project(calendars_tests)

add_subdirectory(lib/gtest-1.7.0)
add_subdirectory(basic_tests)

root/calendar_tests/basic_tests:

include_directories($gtest_SOURCE_DIR/include $gtest_SOURCE_DIR)

add_executable(runBasicCalendarTests
        basic_check.cpp
        calendar_check.cpp)

target_link_libraries(runBasicCalendarTests gtest gtest_main)
target_link_libraries(runBasicCalendarTests calendars)

【问题讨论】:

IDE 将头文件放在程序中的特定位置。对于大多数 IDE,您不需要输入整个文件路径,除非您已将文件移出默认位置,因为 IDE 已经知道它在哪里。 【参考方案1】:

你必须从这个问题阅读这个answer:What is the difference between #include < filename> and #include “filename”?

特别是,当piCookie 说:

表单的预处理指令

#include "q-char-sequence" new-line

导致将该指令替换为由 " 分隔符之间的指定序列标识的源文件的全部内容。以实现定义的方式搜索命名的源文件。如果不支持此搜索,或者如果搜索失败,指令被重新处理,就像它读取一样

#include <h-char-sequence> new-line

具有与原始指令相同的包含序列(包括 > 字符,如果有的话)。

在你读完 CMakeLists.txt 中这一行的注释后:

include_directories(calendars)

您要求cmake 包含calendars 目录以包含搜索路径。

【讨论】:

以上是关于这个标题怎么看?的主要内容,如果未能解决你的问题,请参考以下文章

java:从外面导入一个jdom包,使用这个包里面的类,还想看这个类都有哪些方法,怎么看?

索尼微单 怎么看快门次数

索尼微单怎么看快门次数?

CAJ怎么转换成PDF,这个方法看一次就会

怎么看8000端口?

牛哥对于测试岗怎么看 ?