Ghazale
Ghazale

Reputation: 5

R package containing C++ library cannot build for window

I am trying to write a R package using Rcpp. I was successful in making it work for Linux but not for Windows.

It contains my C++ codes as well as another library. The code is available here: https://github.com/Healthcast/TransEnt/tree/devel-win

In the Makevars.win you can see I run the MakefileWin for the library:

PKG_CPPFLAGS = -Iann_1.1.2/include -I$(BOOSTLIB)
PKG_LIBS = -Lann_1.1.2/lib -lANN -lstdc++ 
OBJECTS= RcppExports.o compute_TE.o
all: before $(SHLIB)
before: annLib
annLib:
    (cd ann_1.1.2/src; make -f MakefileWin; make clean)

And for making the DLL in MakefileWin, I'm using:

ANNLIB = libANN.dll
LIBNAME = ANN
DLLFLAGS = -shared 
(other stuff)
$(LIBDIR)/$(ANNLIB): $(OBJECTS)
$(C++) $(DLLFLAGS) -o cyg${LIBNAME}.dll \
    -Wl,--out-implib=lib${LIBNAME}.dll.a \
    -Wl,--export-all-symbols \
    -Wl,--enable-auto-import \
    -Wl,--whole-archive $(OBJECTS) \
    -Wl,--no-whole-archive

The problem is I cannot make the DLL. I am getting warnings and errors. (But not in Linux) such as:

ANN.cpp:46:9: warning: 'ANNdist annDist(int, ANNpoint, ANNpoint)' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]

perf.cpp:71:14: error: function 'void annResetStats(int)' definition is marked dllimport

I tried different things, but I have a problem understanding what exactly should I do here.

I also tried just copying all the source files into the src folder and have a simple makewars file, and then I got different errors such as:

compute_TE.o:compute_TE.cpp:(.text+0x8ad): undefined reference to `_imp___Z11annAllocPtsii'

Upvotes: 0

Views: 258

Answers (1)

Qiang Kou
Qiang Kou

Reputation: 522

The error message is clear enough. In your code

DLL_API void annResetStats(int data_size);

And in the code

#ifdef DLL_EXPORTS
    #define DLL_API __declspec(dllexport)
#else
    #define DLL_API __declspec(dllimport)
#endif

You define DLL_API to make visual studio compiler happy, but R doesn't use it.

Please try to remove such lines and compile it again.

Upvotes: 1

Related Questions