I tried looking this up and got mixed results using header files and such.
Basically I have multiple cpp files with all my functions I made for use with binary trees, B
You seems to be missing some pretty basic concepts in how to build a program. I'm going to give you a very basic primer, but you will have to go and find more complete answers elsewhere to really understand what's going on and to get the specifics for your setup.
You generally tell the compiler to compile each of your cpp files. When a cpp file has an #include
statement, that basically copies and pastes the include
d file into your cpp file before compiling (this is done by the preprocessor). Each of these complete units (cpp file, with includes) processed by the compiler is called a translation unit. Each translation unit produces one object file.
Object files contain compiled code, but they are often not complete. That is, they contain references to code that are not contained in them. Basically, they can say "now call this function, I don't know where it is or what it does, but you should call it".
The linker is then used to link object files, perhaps together with libraries, into an executable (or a library). The linker's job is to "resolve" all of the references to external code in each object file by finding the relevant code in other object files and libraries.
Libraries come in two flavours: shared libraries (.dll
s in Windows) and static libraries. A static library is linked into the executable (or other library) by the linker, meaning you can then use the executable without the library (relevant library code becomes part of the executable). You can also link an executable/library against a shared library, in which case you'll need a copy of that shared library every time you run your executable -- the operating system will need to dynamically link your compiled code to the shared library before running it.
So, back to your question.
You have, broadly, three choices: compile then link all of your cpp
files directly each time in a single project; compile useful reusable code into a static library, then link your project against it; or compile useful reusable code into a shared library, link your project against it, and make sure to ship the shared library with the result so it can be run.
Most projects of any reasonable size will combine at least two of these. Multiple cpp
files will be part of the project code, which will be compiled as separate translation units and given to the linker. Most projects will also use some libraries (either that you write yourself, or that others have written) that are linked statically or dynamically as appropriate.
Unfortunately (imho) C++ as a language doesn't come with a single build system to organise all of this for your (more recent languages often do). There are several different compilers/linkers and many different build systems that can all do all of this. The specific steps you need to take, unfortunately, depend an awful lot on your choice of compiler and build system.