hedgehog0
hedgehog0

Reputation: 76

Build a C++ program in Clion: "Target not found"

I have searched some solutions online and on Stackoverflow but could not found one that suits mine. The code below is the CMakeList.txt of vector file. vector file is a sub-file of the parent file DSA, in which there are also main.cpp and CMakeList.txt, but I do not believe they are relevant.

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;
}

This is the configuration window. I have added add_executable(vector ${SOURCE_FILES}) into C makelist but it still does not work, what should I do?

Upvotes: 0

Views: 1802

Answers (2)

jshum
jshum

Reputation: 26

Check out the add_subdirectory command.

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.

CLion doesn't know to look for your other CMakeLists.txt file without this added to the top level CMakeLists.txt file that is defining your DSA project.

Upvotes: 1

crujose
crujose

Reputation: 1

CMakeLists.txt (with an s) maybe?

Upvotes: 0

Related Questions