Got the trivial situation: some c++ code has to be exported statically to other language project via compiling ‘.obj’ files.
At c++ side: the declaration and implementation are classically separated between ‘.h’ and ‘.cpp’ files.
Simple example:
dummy.h
#ifndef dummy_h
#define dummy_h
namespace D {
void doDummy(); // implementation in 'dummy.cpp'
void doDummyX()
{
// do smth
return;
};
}
#endif //dummy_h
dummy.cpp
#include "dummy.h"
void D::doDummy() // declared in 'dummy.h'
{
// do smth
return;
};
exporttest.cpp
#include "dummy.h"
extern "C" void __stdcall funcTest()
{
D::doDummy(); // declared in 'dummy.h', implementation in 'dummy.cpp'
D::doDummyX(); // declaration & implementation in 'dummy.h'
return;
};
Is there any fast tweak to make compiler include the implementation of function doDummy to corresponding ‘dummy.obj’ file?
Obviously, two ‘.obj’ files are compiled: ‘dummy.obj’ and ‘exporttest.obj’. The problem is none of them contains the implementation binary of doDummy
.
I understand that moving implementation of function doDummy
directly to “dummy.h” from “dummy.cpp” solves the problem. But this is not the way out in scope of project.
dummy.h
#ifndef dummy_h
#define dummy_h
namespace D {
void doDummy()
{
// do smth
return;
};
}
#endif //dummy_h
Also, want to avoid expansion of ‘.h’ with ‘.cpp’ like:
dummy.h
#ifndef dummy_h
#define dummy_h
namespace D {
void doDummy();
}
#include "dummy.cpp" // expand with implementation (.hpp)
#endif //dummy_h
PS: I know there is a lot info on this topic, BUT I appreciate a minimal workaround with least modifications.
iap is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.