c++ - 在 Clion : "Target not found" 中构建 C++ 程序

标签 c++ ide clion

我在网上和 Stackoverflow 上搜索了一些解决方案,但找不到适合我的解决方案。下面的代码是vector文件的CMakeList.txtvector文件是父文件DSA的子文件,其中还有main.cppCMakeList.txt,但我认为它们不相关。

cmake_minimum_required(VERSION 3.5)
project(vector)

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

set(SOURCE_FILES
    copy_assignment.h
    copy_constructor.h
    main.cpp
    traverse_funcs.h
    vector.h
    vector_bin_search_a.h
    vector_bin_search_b.h
    vector_bin_search_c.h
    vector_bracket.h
    vector_bubble.h
    vector_bubblesort.h
    vector_deduplicate.h
    vector_disordered.h
    vector_expand.h
    vector_fib_search_a.h
    vector_find.h
    vector_insert.h
    vector_merge.h
    vector_mergesort.h
    vector_permute.h
    vector_remove.h
    vector_removeinternal.h
    vector_shrink.h
    vector_traverse.h
    vector_uniquify.h
    vector_unsort.h)

add_executable(vector ${SOURCE_FILES})

主要.cpp:

#pragma once

#include <iostream>

#include "vector.h"
#include "vector_permute.h"

using namespace std;

int main()
{
    Vector<int> foo = {1, 2, 3, 4};
    cout << foo.size() << endl;
    return 0;
}

这是配置窗口。我已将 add_executable(vector ${SOURCE_FILES}) 添加到 C makelist 中,但它仍然不起作用,我该怎么办?

最佳答案

查看 add_subdirectory 命令。

https://cmake.org/cmake/help/v3.0/command/add_subdirectory.html

Add a subdirectory to the build.

add_subdirectory(source_dir [binary_dir] [EXCLUDE_FROM_ALL])

Add a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.txt and code files are located. If it is a relative path it will be evaluated with respect to the current directory (the typical usage), but it may also be an absolute path. The binary_dir specifies the directory in which to place the output files. If it is a relative path it will be evaluated with respect to the current output directory, but it may also be an absolute path. If binary_dir is not specified, the value of source_dir, before expanding any relative path, will be used (the typical usage). The CMakeLists.txt file in the specified source directory will be processed immediately by CMake before processing in the current input file continues beyond this command.

如果没有将此文件添加到定义 DSA 项目的顶层 CMakeLists.txt 文件,CLion 就不知道要查找您的其他 CMakeLists.txt 文件。

关于c++ - 在 Clion : "Target not found" 中构建 C++ 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38118729/

相关文章:

c++ - 在运行时用一个小部件替换另一个小部件并显示新的小部件

java - 具有最佳 Maven 集成的免费 Java IDE

python - _ZSt28__throw_bad_array_new_lengthv 尝试在编译共享对象后在 Python 中导入 C++ 代码

c++ - 如何在C++中与同一行不同地接受用户输入?

java - 是否有一个 Eclipse 插件可以让您在多个 Subversion 修订版中区分单个 Java 方法?

javascript - mac os x python/JavaScript IDE,我可以在其中使用断点

intellij-idea - 如何从 Ubuntu 16.04 LTS 中完全删除 CLion-2016.2.3?

CLion 中的 CMake 版本未更新

c++ - clion 在每个构建上运行 cmake

C++使用atof将字符串转换为double