16
votes

I've created a library using C++, I want to create a Python Wrapper for this library and I am using boost.python - The problem is that I have created .h and .cpp files separately and for some reason, the .so file cannot link these .cpp files.

I have therefore decided to just use the .hpp extension and include the implementation as a header file. Is this good or bad practice in terms of C++? I'm hoping to upload my project to Github so want to maximize the most optimal solution.

P.S. I think this question would more belong on programmers.stackexchange.com so if it is, could someone please migrate it.

1
.hpp and .h are the same thing.chris
@chris Hey, I thought the .hpp invoked that the implementation of the class would be in there? The general question is: Is this acceptable? I've always been taught to have a .h and .cpp filePhorce
If you are going to put implementation in the header file, make sure to use inline where appropriate to avoid link errors (and be aware of which types of functions are automatically inline in a header file)JBentley

1 Answers

17
votes

This is a good idea if you have mixed c++ and c in your project. As mentioned in the comments .hpp and .h are essentially the same (for compiling c++, not c). If you are having problems linking your project it's not because of your file extensions.

In the header files you typically 'prototype' the class definition so that all of your class members can be used, not just ones defined before the current code.

Please review: *.h or *.hpp for your class definitions