gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 05:36:44 25 4
gpt4 key购买 nike

我在网上和 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com