shared object generation

This commit is contained in:
siddharth jain 2020-12-18 11:28:26 +05:30
parent b8c5ad2bbc
commit e9cc90e73a
2 changed files with 36 additions and 8 deletions

View File

@ -1,10 +1,32 @@
#include "Moses2Wrapper.h"
#include <iostream>
#include <windows.h>
#ifdef WIN32
#include <windows.h>
#endif // DEBUG
#if defined(_MSC_VER)
// Microsoft
#define EXPORT __declspec(dllexport)
#define IMPORT __declspec(dllimport)
#elif defined(__GNUC__)
// GCC
#define HRESULT int
#define EXPORT __attribute__((visibility("default")))
#define __stdcall
#define IMPORT
#define S_OK 0
#define E_FAIL 1
#else
// do nothing and hope for the best?
#define EXPORT
#define IMPORT
#pragma warning Unknown dynamic link import/export semantics.
#endif
using namespace std;
using namespace Moses2;
extern "C" __declspec(dllexport) HRESULT __stdcall GetMosesSystem(const char* filePath, Moses2::Moses2Wrapper ** pObject) {
extern "C" EXPORT HRESULT __stdcall GetMosesSystem(const char* filePath, Moses2::Moses2Wrapper ** pObject) {
if (*pObject == NULL) {
*pObject = new Moses2::Moses2Wrapper(filePath);
return S_OK;
@ -14,7 +36,7 @@ extern "C" __declspec(dllexport) HRESULT __stdcall GetMosesSystem(const char* fi
}
}
extern "C" __declspec(dllexport) HRESULT __stdcall MosesTranslate(Moses2::Moses2Wrapper * pObject, long id, const char* input, char* output, int strlen) {
extern "C" EXPORT HRESULT __stdcall MosesTranslate(Moses2::Moses2Wrapper * pObject, long id, const char* input, char* output, int strlen) {
if (pObject != NULL)
{
std::string tr = pObject->Translate(input, id);
@ -26,7 +48,7 @@ extern "C" __declspec(dllexport) HRESULT __stdcall MosesTranslate(Moses2::Moses2
return E_FAIL;
}
}
extern "C" __declspec(dllexport) int __stdcall ReleaseSystem(Moses2::Moses2Wrapper ** pObject) {
extern "C" EXPORT int __stdcall ReleaseSystem(Moses2::Moses2Wrapper ** pObject) {
if (*pObject != NULL)
{
delete *pObject;
@ -37,6 +59,6 @@ extern "C" __declspec(dllexport) int __stdcall ReleaseSystem(Moses2::Moses2Wrapp
return E_FAIL;
}
}
extern "C" __declspec(dllexport) string __stdcall GetEngineVersion() {
extern "C" EXPORT string __stdcall GetEngineVersion() {
return "1.0";
}

View File

@ -52,7 +52,7 @@ alias deps : ..//z ..//boost_iostreams ..//boost_filesystem : : : $(max-factors
TypeDef.cpp
Vector.cpp
Weights.cpp
Word.cpp
Word.cpp
FF/Distortion.cpp
FF/FeatureFunction.cpp
FF/FeatureFunctions.cpp
@ -188,9 +188,15 @@ alias deps : ..//z ..//boost_iostreams ..//boost_filesystem : : : $(max-factors
:
$(includes)
;
lib moses2so :
Moses2Wrapper.cpp
DLLEntryApi.cpp
moses2_lib
: <link>shared
$(includes)
;
exe moses2 : Main.cpp moses2_lib ../probingpt//probingpt ../util//kenutil ../lm//kenlm ;
echo "Building Moses2" ;
alias programs : moses2 ;
alias programs : moses2 moses2so ;