Skip to content

[R-pkg-devel] compiling C sources on windows

3 messages · Kevin Ushey, Brad Eck

#
Dear List -

I'm working to get a package of mine that was archived last year back on to
CRAN.
The epanet2toolkit provides an R interface to the EPANET simulation engine
that is written in C.

The latest development version of the package builds and checks ok on mac
and linux but fails to
compile and install on windows with a bunch of errors like:

undefined reference to `_imp__*`

where * is some function defined in a header file and implemented in the
corresponding source file.

Am i missing a compiler flag or something?

Current output from winbuilder :
https://win-builder.r-project.org/9aIcl8Fxu7w1/00install.out
or https://pastebin.com/8JQNpNKp

source code: https://github.com/bradleyjeck/epanet2toolkit/tree/v22dev

Any insights appreciated.

Brad
#
I suspect the cause is this:

https://github.com/bradleyjeck/epanet2toolkit/blob/aa698568ab85db133f8634928e8cfe661b41ed57/src/epanet2.h#L42-L61

Usually, you only need to explicitly use __declspec if you're
compiling with MSVC -- it shouldn't be necessary when using a MinGW
toolchain (as R's toolchain is). You could try adding something like:

#ifdef __MINGW32__
#define DLLEXPORT
#endif

If you need to test locally on Windows, there are free virtual
machines available here:
https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/

Best,
Kevin
On Mon, Apr 19, 2021 at 2:14 AM Brad Eck <bradleyjeck at gmail.com> wrote:
#
Thanks Kevin, that fixed the compilation issue.  On to the next!

Brad
On Mon, Apr 19, 2021 at 5:06 PM Kevin Ushey <kevinushey at gmail.com> wrote: