linking and compiling multiple c++ files into one
Hi!
I have 3 c++ files, classdef.h (header file with class definition), methods.cpp (class methods) and program.cpp - the program itself. Both .cpp files have Code:
#include "classdef.h" How I can link the files together and compile them in one executable program? I am using Geany IDE for coding. Thanks in advance, -skazhy |
I don't know about Geany, but with gcc:
Code:
g++ -o program program.cpp methods.cpp g++ will automatically include the necessary .h files. Don't know if this will help. |
The g++ program is a supervisor that invokes the compiler and linker for you.
The operation Code:
g++ -o program program.cpp methods.cpp compile program.cpp compile methods.cpp link the two results together plus startup code and default libraries. With compilers on many other platforms, including two cpp files in one compile command would tell the compiler to compile the concatenated source code, rather than compile separately. That is rarely what you want, so on such systems, you would issue the two separate compile commands followed by the link command. Even with GCC, you may prefer to give compile and link commands separately: Code:
g++ -c program.cpp If you want Geany to generate the g++ commands for you, read its documentation and/or put "Geany" in the topic of your thread so someone who knows it is more likely to respond. |
Quote:
|
thank you very much guys, this info was very helpful :)
|
All times are GMT -5. The time now is 03:27 AM. |