Error while running c program in Clion IDE


I just created a projec folder and write two prgrams , each are working fin when they seperatly as different project   but when i try to run those inside a same project its not working its shows this error :

duplicate symbol '_main' in:
ld: 1 duplicate symbol for architecture x86_64

1 comment


It seems that you have two main() functions in your project.

Each main() function should belong to a separate executable. In order to have several executables in your project, you need to create several CMake targets for them: there should be a add_executable(<target name> <file name>) line in the CMakeLists.txt for each executable.

In your case, you have two files input.c and test.c, and you have a main() function in each of them. The simplest CMakeLists.txt for such a project should look similar to the following:

cmake_minimum_required(VERSION 3.15)
project(tution C)
add_executable(tution_input input.c)
add_executable(tution_test test.c)

After that, you can choose which target to run (tution_input or tution_test) via "Run configuration" pop-up (left to the "Run" button).

Please read our quick CMake tutorial for more details:


Please sign in to leave a comment.