Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was writing a calculator project containing multiple source and header files. I had uploaded those files on Github, but left out the cmakefile. Due to some reasons I lost access to my older account and had to reinstall the system. Now when I am trying to build my project(on a new system, through the IDE) I am getting this error.
main.c:(.text+0x19): undefined reference to...
I have realized that the cause of this error is the lack of linking of multiple source files. I can compile and generate executable just fine by using command line and writing all the source files separately in GCC argument, but I want to automate it, so that the executable is generated directly through the IDE(I am working on CLion).

I can't find a way to generate cmakelist automatically, I am trying to write one manually but
1) It feels difficult
2) I am worried that will my IDE keep updating it automatically if I add new files in future?

What should I do? Is there a tool to automate my task, or do I need to just write one manually?

What I have tried:

cmake_minimum_required(VERSION 3.13)  # CMake version check
project(ScientificCalc)               # Create project "simple_example"
set(CMAKE_CXX_STANDARD 14)            # Enable c++14 standard

# Add main.cpp file of project root directory as source file
set(SOURCE_FILES main.c)

# Add executable target with source files listed in SOURCE_FILES variable
add_executable(calc main.c)

I have copy pasted a cmake example from the internet, and slightly modified it, but I am not sure if I had done it right either(It is still not building correctly). For example in the last line
add_executable(calc main.c)
I have only added main.c. For the context I have several .c and .h files.
Updated 28-Feb-23 22:08pm

1 solution

Take a look at cmake(1) — CMake 3.26.0-rc4 Documentation[^] for guidance on creating your make file.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900