Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrectly specified init.c routine registration? #274

Closed
DavisVaughan opened this issue Jul 25, 2018 · 9 comments
Closed

Incorrectly specified init.c routine registration? #274

DavisVaughan opened this issue Jul 25, 2018 · 9 comments

Comments

@DavisVaughan
Copy link
Contributor

I've been trying to build on Windows 7 with R 3.4.1 and keep running into:

> devtools::build(binary = TRUE)
"C:/PROGRA~1/R/R-34~1.1/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  "C:\r-packages\Rblpapi" --build 

* installing to library 'C:/Users/D24929/AppData/Local/Temp/RtmpKMmECn/temp_libpath5a387ea45ddf'
* installing *source* package 'Rblpapi' ...

   **********************************************
   WARNING: this package has a configure script
         It probably needs manual configuration
   **********************************************


** libs

*** arch - i386
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c RcppExports.cpp -o RcppExports.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c authenticate.cpp -o authenticate.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c bdh.cpp -o bdh.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c bdp.cpp -o bdp.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c bds.cpp -o bds.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c beqs.cpp -o beqs.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c blpConnect.cpp -o blpConnect.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c blpVersion.cpp -o blpVersion.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c blpapi_utils.cpp -o blpapi_utils.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c bsrch.cpp -o bsrch.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c fieldsearch.cpp -o fieldsearch.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c getBars.cpp -o getBars.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c getFieldInfo.cpp -o getFieldInfo.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c getTicks.cpp -o getTicks.o
C:/RTOOLS/mingw_32/bin/gcc  -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O3 -Wall  -std=gnu99 -mtune=core2 -c init.c -o init.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c lookup.cpp -o lookup.o
C:/RTOOLS/mingw_32/bin/g++  -std=gnu++11 -I"C:/PROGRA~1/R/R-34~1.1/include" -DNDEBUG -I../inst/include -I. -I"R:/Vaughan/R/r-libs/Rcpp/include" -I"R:/Vaughan/R/r-libs/BH/include"   -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c subscribe.cpp -o subscribe.o
C:/RTOOLS/mingw_32/bin/g++ -shared -s -static-libgcc -o Rblpapi.dll tmp.def RcppExports.o authenticate.o bdh.o bdp.o bds.o beqs.o blpConnect.o blpVersion.o blpapi_utils.o bsrch.o fieldsearch.o getBars.o getFieldInfo.o getTicks.o init.o lookup.o subscribe.o -lblpapi3_32 -Li386 -Ld:/Compiler/gcc-4.9.3/local330/lib/i386 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-34~1.1/bin/i386 -lR
init.o:init.c:(.rdata+0x184): undefined reference to `Rblpapi_authenticate_Impl'
init.o:init.c:(.rdata+0x190): undefined reference to `Rblpapi_bdh_Impl'
init.o:init.c:(.rdata+0x19c): undefined reference to `Rblpapi_bdp_Impl'
init.o:init.c:(.rdata+0x1a8): undefined reference to `Rblpapi_bds_Impl'
init.o:init.c:(.rdata+0x1b4): undefined reference to `Rblpapi_beqs_Impl'
init.o:init.c:(.rdata+0x1c0): undefined reference to `Rblpapi_blpConnect_Impl'
init.o:init.c:(.rdata+0x1cc): undefined reference to `Rblpapi_bsrch_Impl'
init.o:init.c:(.rdata+0x1d8): undefined reference to `Rblpapi_fieldInfo_Impl'
init.o:init.c:(.rdata+0x1e4): undefined reference to `Rblpapi_fieldSearch_Impl'
init.o:init.c:(.rdata+0x1f0): undefined reference to `Rblpapi_getBars_Impl'
init.o:init.c:(.rdata+0x1fc): undefined reference to `Rblpapi_getHeaderVersion'
init.o:init.c:(.rdata+0x208): undefined reference to `Rblpapi_getPortfolio_Impl'
init.o:init.c:(.rdata+0x214): undefined reference to `Rblpapi_getRuntimeVersion'
init.o:init.c:(.rdata+0x220): undefined reference to `Rblpapi_getTicks_Impl'
init.o:init.c:(.rdata+0x22c): undefined reference to `Rblpapi_lookup_Impl'
init.o:init.c:(.rdata+0x238): undefined reference to `Rblpapi_subscribe_Impl'
collect2.exe: error: ld returned 1 exit status
installing to C:/Users/D24929/AppData/Local/Temp/RtmpKMmECn/temp_libpath5a387ea45ddf/Rblpapi/libs/i386

After much suffering, I found that in your init.c file you are registering routines using: Rblpapi_authenticate_Impl but Rcpp exports these as _Rblpapi_authenticate_Impl. Don't you need to be consistent for this to work correctly?

I went ahead and cloned and prefixed everything with underscores and it seems to build correctly now.

(Keep in mind I know a decent amount about R, but essentially nothing about C/C++ so this is the result of speculation + reading the R Extensions section on this)

Extra side note) I looked at how dplyr does this and they define their call entries and register the routines in their RcppExports.cpp file. They also don't have that extern SEXP ... piece. Not sure if that part is necessary or not, as again I essentially know nothing in this space.
https://github.com/tidyverse/dplyr/blob/master/src/RcppExports.cpp

@DavisVaughan
Copy link
Contributor Author

Didn't mean to close. Here is the corrected version. I'd PR but I don't think I can push to github from work.

#include <R.h>
#include <Rinternals.h>
#include <stdlib.h> // for NULL
#include <R_ext/Rdynload.h>

/* FIXME:
   Check these declarations against the C/Fortran source code.
*/

/* .Call calls */
extern SEXP _Rblpapi_authenticate_Impl(SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_bdh_Impl(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_bdp_Impl(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_bds_Impl(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_beqs_Impl(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_blpConnect_Impl(SEXP, SEXP);
extern SEXP _Rblpapi_bsrch_Impl(SEXP, SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_fieldInfo_Impl(SEXP, SEXP);
extern SEXP _Rblpapi_fieldSearch_Impl(SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_getBars_Impl(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_getHeaderVersion();
extern SEXP _Rblpapi_getPortfolio_Impl(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_getRuntimeVersion();
extern SEXP _Rblpapi_getTicks_Impl(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_lookup_Impl(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
extern SEXP _Rblpapi_subscribe_Impl(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);

static const R_CallMethodDef CallEntries[] = {
    {"_Rblpapi_authenticate_Impl", (DL_FUNC) &_Rblpapi_authenticate_Impl,  3},
    {"_Rblpapi_bdh_Impl",          (DL_FUNC) &_Rblpapi_bdh_Impl,          10},
    {"_Rblpapi_bdp_Impl",          (DL_FUNC) &_Rblpapi_bdp_Impl,           7},
    {"_Rblpapi_bds_Impl",          (DL_FUNC) &_Rblpapi_bds_Impl,           7},
    {"_Rblpapi_beqs_Impl",         (DL_FUNC) &_Rblpapi_beqs_Impl,          7},
    {"_Rblpapi_blpConnect_Impl",   (DL_FUNC) &_Rblpapi_blpConnect_Impl,    2},
    {"_Rblpapi_bsrch_Impl",        (DL_FUNC) &_Rblpapi_bsrch_Impl,         4},
    {"_Rblpapi_fieldInfo_Impl",    (DL_FUNC) &_Rblpapi_fieldInfo_Impl,     2},
    {"_Rblpapi_fieldSearch_Impl",  (DL_FUNC) &_Rblpapi_fieldSearch_Impl,   3},
    {"_Rblpapi_getBars_Impl",      (DL_FUNC) &_Rblpapi_getBars_Impl,       8},
    {"_Rblpapi_getHeaderVersion",  (DL_FUNC) &_Rblpapi_getHeaderVersion,   0},
    {"_Rblpapi_getPortfolio_Impl", (DL_FUNC) &_Rblpapi_getPortfolio_Impl,  7},
    {"_Rblpapi_getRuntimeVersion", (DL_FUNC) &_Rblpapi_getRuntimeVersion,  0},
    {"_Rblpapi_getTicks_Impl",     (DL_FUNC) &_Rblpapi_getTicks_Impl,      7},
    {"_Rblpapi_lookup_Impl",       (DL_FUNC) &_Rblpapi_lookup_Impl,        6},
    {"_Rblpapi_subscribe_Impl",    (DL_FUNC) &_Rblpapi_subscribe_Impl,     6},
    {NULL, NULL, 0}
};

void R_init_Rblpapi(DllInfo *dll) {
    R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
    R_useDynamicSymbols(dll, FALSE);
}

@eddelbuettel
Copy link
Member

Well it builds at CRAN and on win-builder so my first reaction would be to blame local problems...

@eddelbuettel
Copy link
Member

If you changed init.c try running compileAttributes() again. Sometimes one has to run it twice -- known side effect of changes in R requiring changes in Rcpp.

@DavisVaughan
Copy link
Contributor Author

DavisVaughan commented Jul 25, 2018

Ooh good point. I'm just seeing that your RcppExports.cpp file actually uses the non-underscored version so things line up for you.

I deleted the RcppExports.cpp file and reran Rcpp::compileAttributes() and it generates it with the _Rblpapi... underscored version.

Did Rcpp::compileAttributes() change over the past year to now add an underscore?

@eddelbuettel
Copy link
Member

And src/init.c is old. As this now ends up in RcppExports.cpp maybe src/init.c can be deleted. Try that locally.

@DavisVaughan
Copy link
Contributor Author

Ah, now things are making sense. Yes, removing src/init.c and then running compileAttributes() generates everything in the RcppExports.cpp file with prefixed underscores. It now mimics the dplyr file I linked above.

Running it now locally to ensure it builds, but I think this might be a worthwhile change as the next time someone runs compileAttributes() on your side you might run into this.

@DavisVaughan
Copy link
Contributor Author

Things look good after removing src/init.c, running compileAttributes() so that it generates the RcppExports.cpp file with underscores and with the routine registration information, and then building.

And I believe here is that Rcpp commit that adds the leading underscore as an FYI.
RcppCore/Rcpp@e0f95a5#diff-d80665655fb9b9ad6197ceb8e9f5cad6

@eddelbuettel
Copy link
Member

A few other repos had similar changes of removing src/init.c. As I recall the code aims to be careful and not redefine the registration block if one is found but that may not be failsafe. Sorry for your troubles there.

@DavisVaughan
Copy link
Contributor Author

It's okay. Thanks for being responsive. If you give me a few minutes I think I can actually submit a PR.

eddelbuettel added a commit that referenced this issue Jul 26, 2018
Closes #274. Remove src/init.c and use the newer version of compileAt…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants