CLION problems

Answered

I just purchased and installed and am getting problems out the box. When I open the program I can run the main.cpp file no problem. But the moment I add any other c++ source and try to run it here is what i get (macos)

 

FAILED: Debug/untitled 
: && /Library/Developer/CommandLineTools/usr/bin/c++ -g -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/untitled.dir/Debug/main.cpp.o CMakeFiles/untitled.dir/Debug/asdfasdfasdfasdfasdf.cpp.o -o Debug/untitled   && :
duplicate symbol '_main' in:
    CMakeFiles/untitled.dir/Debug/main.cpp.o
    CMakeFiles/untitled.dir/Debug/asdfasdfasdfasdfasdf.cpp.o
ld: 1 duplicate symbol for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

0
1 comment

Hello!

Each `main()` function should belong to a separate executable (in other words, each executable should have only one `main()` function). 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 for each file in the CMakeLists.txt.

For example, if you have two files `main.cpp` and `main2.cpp` and you have a `main()` function in each of these files, the simplest CMakeLists.txt for such project should look similar to the following:

cmake_minimum_required(VERSION 3.15)
project(my_project)

set(CMAKE_CXX_STANDARD 14)

add_executable(my_project main.cpp)

add_executable(my_project_2 main2.cpp)

After that, you can choose which target to run (`my_project` or `my_project_2`) 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

Please sign in to leave a comment.