For this question, i have basically 4 main files, let's call it:
Constant.cc (where a define the function)
Field.cc (where i call the function)
So basically, i have defined a function at the file "Constant.cc" and i am calling it to be used at Field.cc. But when i try to run it on terminal (using make), it returns this:
1 2 3
/usr/bin/ld: CMakeFiles/eRosita.dir/application/src/Field.cc.o: in function "FF::GetFieldValue(double const*, double*) const":
Field.cc:(.text+0xcc): undefined reference for"Constant(int, double)"
collect2: error: ld returned 1 exit status
I'm actually not too well versed in make (have only written basic things to get me by), but I don't see where that actually links together the object files into some end result. Maybe somebody else can look at your build script more closely.
But as a sanity check, let's forget about the verbosity of those makefiles and just do some simple command-line call.s
I am assuming you have some file that has your main function. g++ -Wall Constant.cc Field.cc main.cc -o prog
(Replace paths as appropriate, and add -I include paths if needed).
I have not worked with Cmake, specifically. But I do have some experience with Makefiles (gnu make, I believe). Maybe Cmake is responsible for some of the problems I see, so I apologize if speak out of ignorance.
1: You appear to be somewhat of a beginner, at least in the use of make. So, why are you concerning yourself with .i and .s files? Unless you have a specific reason to study the preprocessed or assembly code, you only need to worry about compiling object (.o) files and linking them into executables.
2: Why are you calling the generated files .PHONY? These appear to be actual files that are the output of actual compilation steps. Wait ... now I see that these are being built in other directories, so maybe this is an attempt to make sure that those files are built. I think it would be cleaner to create another target (not the name of the actual file), and label it .PHONY. (OK, maybe this one's not critical.) Generally, the compiler generates .o files (not .cc.o files) directly from .cc files. There is no directly obvious reason (at least to me) to specify .cc.o files.
3: The Makefile that you provide only mentions Constant. The error you posted talks about errors linking Field.cc.o. Where is the Makefile that does that link?
4: The target Constant.o depends on Constant.cc.o, but there is no rule on how to make one .o file from another. (Oh wait ... that's probably where the .PHONY comes in. Ugh. Maybe this is a Cmake thing, but I am not a fan.)
5: The Makefile never says which .o files should be linked together to create an executable. That seems to be done somewhere else.