0

I am trying to get started with developing a DLL with C++ functions for use in R (Visual Studio 2015).

I am using this as a reference and to begin with some test code:

http://adv-r.had.co.nz/C-interface.html

stdafx.h:

#include <windows.h>
#include <R.h>
#include <Rinternals.h>

extern "C" SEXP add(SEXP a, SEXP b);

R_Code_Test.cpp:

#include "stdafx.h"

SEXP add(SEXP a, SEXP b) 
{
    SEXP result = PROTECT(allocVector(REALSXP, 1));
    REAL(result)[0] = asReal(a) + asReal(b);
    UNPROTECT(1);

    return result;
}

Compiling this results in linker errors:

LNK2019 unresolved external symbol REAL referenced in function add
LNK2019 unresolved external symbol Rf_asReal referenced in function add
LNK2019 unresolved external symbol Rf_allocVector referenced in function add
LNK2019 unresolved external symbol Rf_protect referenced in function add
LNK2019 unresolved external symbol Rf_unprotect referenced in function add

(I have the definition file as well but didn't copy/paste it here.)

I read elsewhere that R.dll needed to be linked, so I've included that directory from the R install, but I think I must still be missing something obvious.

Any help is much appreciated!

Cheers

0 Answers0