# Multiple definition of main

**URL:** <https://discourse.cmake.org/t/multiple-definition-of-main/1573>\
**Category:** Code\
**Created:** [July 16, 2020, 2:08pm UTC](https://discourse.cmake.org/t/multiple-definition-of-main/1573 "2020-07-16T14:08:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ELNS](https://discourse.cmake.org/user_avatar/discourse.cmake.org/elns/32/747_2.png) [@ELNS](https://discourse.cmake.org/u/ELNS)\
**Post date:** [July 16, 2020, 2:08pm UTC](https://discourse.cmake.org/t/multiple-definition-of-main/1573/1 "2020-07-16T14:08:55Z")

</div>

Hi all,  
I have created a [new cpp repository](https://github.com/EverLookNeverSee/CPPCS) a day ago to re-implement my fortran code snippets in c plus plus language and this is default generated cmake file by clion IDE:

```
cmake_minimum_required(VERSION 3.16)
project(CPPCS)

set(CMAKE_CXX_STANDARD 14)

include_directories(.)
include_directories(cmake-build-debug)
include_directories(src)

add_executable(CPPCS
    cmake-build-debug/cmake_install.cmake
    cmake-build-debug/CMakeCache.txt
    cmake-build-debug/Makefile
    cmake-build-debug/Project.cbp
    src/numerical_methods/Exercise_01.cpp
    CMakeLists.txt
    LICENSE
    README.md)

```

This worked very well before i decided to re-implement other exercise. Now when i run the second exercise.  
How can i fix this? I want to configure smake file so that every new cpp file can run without any conflict with other cpp file.

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [July 16, 2020, 2:16pm UTC](https://discourse.cmake.org/t/multiple-definition-of-main/1573/2 "2020-07-16T14:16:20Z")

</div>

It’s very obvious just from looking at this that it was auto-generated.

Please change the `add_executable()` call to:

```cmake
add_executable(CPPCS src/numerical_methods/Exercise_01.cpp)

```

removing everything except the `.cpp` file from `add_executable()`. In addition, you don’t need `include_directories(cmake-build-debug)`.

---

<div class="post-metadata">

**Author:** ![ELNS](https://discourse.cmake.org/user_avatar/discourse.cmake.org/elns/32/747_2.png) [@ELNS](https://discourse.cmake.org/u/ELNS)\
**Post date:** [July 16, 2020, 2:27pm UTC](https://discourse.cmake.org/t/multiple-definition-of-main/1573/3 "2020-07-16T14:27:32Z")

</div>

should only one cpp executable be in cmake file?

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [July 16, 2020, 2:30pm UTC](https://discourse.cmake.org/t/multiple-definition-of-main/1573/4 "2020-07-16T14:30:54Z")

</div>

No, you can have more than one executable, but those other files aren’t needed to build the executable.

---

<div class="post-metadata">

**Author:** ![ELNS](https://discourse.cmake.org/user_avatar/discourse.cmake.org/elns/32/747_2.png) [@ELNS](https://discourse.cmake.org/u/ELNS)\
**Post date:** [July 16, 2020, 2:33pm UTC](https://discourse.cmake.org/t/multiple-definition-of-main/1573/5 "2020-07-16T14:33:38Z")

</div>

could you please provide me correct cmake configuration for my project?

---

<div class="post-metadata">

**Author:** ![kyle.edwards](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/k/65b543/32.png) [@kyle.edwards](https://discourse.cmake.org/u/kyle.edwards)\
**Post date:** [July 16, 2020, 2:36pm UTC](https://discourse.cmake.org/t/multiple-definition-of-main/1573/6 "2020-07-16T14:36:58Z")

</div>

I don’t know exactly what your project requires, but based on what you have so far I think it looks approximately like this:

```cmake
cmake_minimum_required(VERSION 3.16)
project(CPPCS)

set(CMAKE_CXX_STANDARD 14)

include_directories(.)
include_directories(src)

add_executable(CPPCS
    src/numerical_methods/Exercise_01.cpp)

```

---

<div class="post-metadata">

**Author:** ![ELNS](https://discourse.cmake.org/user_avatar/discourse.cmake.org/elns/32/747_2.png) [@ELNS](https://discourse.cmake.org/u/ELNS)\
**Post date:** [July 16, 2020, 2:39pm UTC](https://discourse.cmake.org/t/multiple-definition-of-main/1573/7 "2020-07-16T14:39:21Z")

</div>

Thank you very much
