I want to include an object file(solution.o) in a manager.h file. But I don't have solution.h file. I know I have to include #include solution.h in my manager.h, but the problem is that during the compile time, it shows an error "no solution.h such file exists". Please help. Thank you.
Asked
Active
Viewed 566 times
-8
-
4A `.o` file is compiled output. You can't "include" it in anything except when linking a final executable. Where did `solution.o` come from? You can't `#include` something that doesn't exist, you must create that first. – tadman Nov 02 '18 at 17:52
-
@tadman My professor only want to give us the solution.o file, this file might compile by professor and then give the object file to us. – ccc Nov 02 '18 at 17:54
-
2The `.o` is worthless without its `.h` – n.caillou Nov 02 '18 at 17:54
-
1Sounds like the correct thing to do is make a solution.h that exposes the functionality you want exposed. Handy reading: [How does the compilation/linking process work?](https://stackoverflow.com/questions/6264249/how-does-the-compilation-linking-process-work) – user4581301 Nov 02 '18 at 17:54
-
The solution is not to include a object file in a header file. It is to declare functions that are defined within the object file in a header, use that header in source files, and then list the object file as a parameter when linking the program. – Peter Nov 02 '18 at 22:02
1 Answers
4
You cannot include an object file. The preprocessor can only include some file containing some C code. Read documentation of cpp
.
You need to find the solution.h
header file (or to code it). Probably your duty is to write such a header file. I guess that it part of your homework (and your professor might have given some explanations for that)

Basile Starynkevitch
- 223,805
- 18
- 296
- 547
-
My professor only want to give us the solution.o file, this file might compile by professor and then give the object file to us. Is there a way I can use solution.o without .h file? Thanks – ccc Nov 02 '18 at 17:56
-
1@ccc Technically yes, but practically no. You can write the declarations for the contents of solution.o you need directly into the source files that need the declarations, but this is effectively repeating what would be in solution.h. Do you know what pieces of solution.o you need and have any documentation on those pieces or examples of their use? If so, you can write declarations into your own solution.h. If you have problems doing this, ask a new question and provide the documentation/examples and Stack Overflow can help you fill in the blanks. – user4581301 Nov 02 '18 at 18:03
-
1Your professor could have given you some documentation about that `solution.o`. Then you can write your `solution.h` from the explanations given by your professor. Or else, ask him – Basile Starynkevitch Nov 02 '18 at 18:44