It has been a while since I used C++ and I need some help compiling some source codes.
I have a program that contains about 21 files some of these files are header files and some are .cpp files.
When I try to compile the main.cpp file I get a bunch of error saying it cannot find some of the other files that is needed for the main program to run.
I'm using gcc -o main main.cpp to compile the main program (this is when I get the error).
I also tried to compile all the files together by using gcc -o main *.cpp but I still get some errors.
How can I compile the files in the correct order so I can get it to work? I tried to compile some of the other files that has no MAIN in the code, but I cannot get it to compile, I get an error saying undefined reference to main.
First, you need to learn to differentiate compiler and linker errors. Which ones are you getting?
To compile a cpp file, use g++ -c <filename>. So g++ -c *.cpp should give you a bunch of .o files. If an error occurs during running this command, it's a compiler error and you will have to check for missing include files and possibly include the -I flag in your command.
To link the files to form an executable use g++ -o <name_of_executable> *.o. If you get errors there, you might be missing some cpp files or you will have to link in a library (-l flag).
In any case, post the error message to get more help.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth