HOW am I supposed to link three header files in C++? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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?

5th Mar 2022, 9:39 AM
Je Foip Cent
Je Foip Cent - avatar
6 ответов
5th Mar 2022, 11:13 AM
Mustafa A
Mustafa A - avatar
+ 1
Write a make file
5th Mar 2022, 1:03 PM
Raul Ramirez
Raul Ramirez - avatar
0
Mustafa A Well that doesn't answer my question as to how those 3 files can be compiled.
5th Mar 2022, 1:49 PM
Je Foip Cent
Je Foip Cent - avatar
0
Raul Ramirez I made a cmd file and it didn't work: g++ test.cpp orange.cpp apple.cpp -o end_file
5th Mar 2022, 1:50 PM
Je Foip Cent
Je Foip Cent - avatar
0
make sure orange.cpp has #include “orange.hpp” And apple.cpp has apple.hpp
5th Mar 2022, 2:17 PM
Raul Ramirez
Raul Ramirez - avatar
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.
5th Mar 2022, 4:03 PM
Mustafa A
Mustafa A - avatar