+ 1
HOW am I supposed to link three header files in C++?
Here are my three files in chronological order: 1. apple.hpp (Header file only, source file not shown): class Apple { }; 2. orange.hpp #include "apple.hpp" class Orange { Apple foo; }; 3. test.cpp (Main file) #include "orange.hpp" int main() { Orange bar; } How do I link and compile main? I tried this but it didn't work: g++ test.cpp orange.cpp apple.cpp -o end_file How do I make this work?
6 Respostas
+ 1
Write a make file
0
Mustafa A Well that doesn't answer my question as to how those 3 files can be compiled.
0
Raul Ramirez I made a cmd file and it didn't work:
g++ test.cpp orange.cpp apple.cpp -o end_file
0
make sure orange.cpp has #include “orange.hpp”
And apple.cpp has apple.hpp
0
Liam B. Harrison You need to first create object files with the compiler and then you can link the object files with the linker. As described by the forum discussion. The rest is Googling.