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
请先登录再写评论。
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 aadd_executable(<target name> <file name>)
line in the CMakeLists.txt for each executable.In your case, you have two files
input.c
andtest.c
, and you have amain()
function in each of them. The simplest CMakeLists.txt for such a project should look similar to the following:After that, you can choose which target to run (
tution_input
ortution_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.