0

I recently downloaded Clion and ran into some problem. First I wrote one simple code (it works), then I created another C++ file and wrote another simple code. But now, when running either of these two codes, an error is thrown:

clang: error: linker command failed with exit code 1 (use -v to see invocation)

when I remove one of the codes, the other one starts working. I seem to have found a solution on stackoverflow and it says just do Clean and then Build, though I can't figure out how to do it. Will you help?

  • Why do you see only the last output line? – 273K Mar 06 '22 at 06:25
  • My crystal ball says you have two files in your project with a `main` function and the error is due to multiple definitions. Hard to tell without the complete error and the code in question. – Retired Ninja Mar 06 '22 at 06:28
  • Okay, here it is duplicate symbol '_main' in: CMakeFiles/CodeForces.dir/4A.cpp.o CMakeFiles/CodeForces.dir/71A.cpp.o ld: 1 duplicate symbol for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[3]: *** [CodeForces] Error 1 make[2]: *** [CMakeFiles/CodeForces.dir/all] Error 2 make[1]: *** [CMakeFiles/CodeForces.dir/rule] Error 2 make: *** [CodeForces] Error 2 – user18279824 Mar 06 '22 at 06:36
  • Retired ninja's crystal ball works again, you have two `main` functions in a suitable program, there can be only one – Alan Birtles Mar 06 '22 at 08:02
  • how to fix it?? – user18279824 Mar 06 '22 at 08:57
  • Remove one of the main functions? – Alan Birtles Mar 06 '22 at 09:32
  • every time when I create a new C++ file I must do something like [[maybe_unused]] int main1{. . .} ? – user18279824 Mar 06 '22 at 11:19

0 Answers0