在 Clion 中构建 C++ 程序:"Target not found"
Build a C++ program in Clion: "Target not found"
我在网上和 Whosebug 上搜索了一些解决方案,但找不到适合我的解决方案。下面的代码是 vector
文件的 CMakeList.txt
。 vector
文件是父文件DSA
的子文件,其中还有main.cpp
和CMakeList.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})
main.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;
}
这是配置window。我已将 add_executable(vector ${SOURCE_FILES})
添加到 C makelist 中,但它仍然不起作用,我该怎么办?
CMakeLists.txt(带 s)可能吗?
查看 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 文件,CMakeLists.txt CLion 将无法查找您的其他 CMakeLists.txt 文件。
我在网上和 Whosebug 上搜索了一些解决方案,但找不到适合我的解决方案。下面的代码是 vector
文件的 CMakeList.txt
。 vector
文件是父文件DSA
的子文件,其中还有main.cpp
和CMakeList.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})
main.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;
}
这是配置window。我已将 add_executable(vector ${SOURCE_FILES})
添加到 C makelist 中,但它仍然不起作用,我该怎么办?
CMakeLists.txt(带 s)可能吗?
查看 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 文件,CMakeLists.txt CLion 将无法查找您的其他 CMakeLists.txt 文件。