Is is possible to create an object file (.o) from a header file? (.h / .hpp). All the code is inlined in the header ...
2 Answers
Yes, just tell the compiler to compile it as a C++ file and write the result to a .o
or .obj
file. But if all the functions are inline, there's nothing for the code to do, so the resulting object file won't have any code in it. So there's usually no point in doing this.

- 74,985
- 8
- 76
- 165
No, but recent GCC (e.g. GCC 4.7 on Linux) has the ability to compile one single header file, using the precompiled-header facility. Warning, this works well only when you have a single header file (often including system or third parties libraries headers) which is included by every source file of your application.
See also this reply which explains more why is it so.
And you might be interested by the link time optimizations, e.g. by passing -flto both at compile and at link time to g++

- 1
- 1

- 223,805
- 18
- 296
- 547