I would lik to create a program in C/C++ running in Linux with multiple files, with 1 main file calling all my subroutines. There will also be a header file containing all my global variables that will be shared to used in each of the individual subroutines(So that i can access the same data anywhere).
Each of the subroutines will be in contained in an individual file.
eg. main.cpp, funct1.cpp, funct2.cpp, calculate.cpp, variables.h
main.cpp will call funct1.cpp & funct2.cpp. In funct1.cpp & funct2.cpp, both will call on funct3.cpp.
Prob:
funct3 contains multiple small functions within. In which file should i declare these sub functions? should this funct3 be saved as a .cpp or a .h?
Since all the cpp files require e shared use of the same variables, do i have to #include "variables.h" in every of the files? If not, in which file should i having this statement? I am facing the problem of redeclaration of variables when linking the files together with my makefile. However, if i did not include this in each of the files, i am unable to create my object files.
I am unable to link the files together. How should i go about creating the makefile as well as rest of the files?
My makefile goes like this:
Code:
test: main.o funct1.o funct2.o funct3.o variables.h
cc -o test main.o funct1.o funct2.o funct3.o variables.h
main.o: main.cpp variables.h
cc -o main.cpp
funct1.o: funct1.cpp funct3.cpp variables.h
cc -o funct1.cpp
funct2.o: funct2.cpp funct3.cpp variables.h
cc -o funct1.cpp
funct3.o: funct3.cpp variables.h
cc -o funct1.cpp