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:
   CMakeFiles/tution.dir/input.c.o
   CMakeFiles/tution.dir/test.c.o
ld: 1 duplicate symbol for architecture x86_64

0

Hello!

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)
set(CMAKE_C_STANDARD 11)
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: https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html.

0

请先登录再写评论。