0

Is is possible to create an object file (.o) from a header file? (.h / .hpp). All the code is inlined in the header ...

Victor Parmar
  • 5,719
  • 6
  • 33
  • 36

2 Answers2

6

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.

Pete Becker
  • 74,985
  • 8
  • 76
  • 165
1

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++

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547