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
# Add executable target with source files listed in SOURCE_FILES variable
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
I have only added main.c. For the context I have several .c and .h files.