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

C++ ODR violated when using testthat #350

Closed
jgaeb opened this issue Jan 20, 2024 · 2 comments
Closed

C++ ODR violated when using testthat #350

jgaeb opened this issue Jan 20, 2024 · 2 comments

Comments

@jgaeb
Copy link

jgaeb commented Jan 20, 2024

The autogenerated cpp11.cpp file is leading to run_testthat_tests() being defined twice. In particular, in my rar package it's defined here in cpp11.cpp:

extern SEXP run_testthat_tests(void *);

and in the testthat.h header:

extern "C" SEXP run_testthat_tests(SEXP use_xml_sxp) {
  bool use_xml = LOGICAL(use_xml_sxp)[0];
  bool success = testthat::run_tests(use_xml);
  return ScalarLogical(success);
}

This is leading to a violation of the C++ One Definition Rule when I compile this code on Fedora. (And presumably other platforms as well.) I've received the advice to simply include the testthat.h header in the cpp11.cpp file, but since it's autogenerated, I think this is a bug. (I'm pretty new to R package development, so my apologies in advance if this is actually user error.)

@jgaeb
Copy link
Author

jgaeb commented Jan 21, 2024

Nevermind—this seems to be the same as this issue on the testthat repo: r-lib/testthat#1230.

@jgaeb jgaeb closed this as completed Jan 21, 2024
@jgaeb
Copy link
Author

jgaeb commented Jan 21, 2024

In case anyone finds this in the future because they're dealing with the same problem, the issue actually seems to be with tools::package_native_routine_registration_skeleton(), which generates the wrong signature for some reason in R 4.3.2. See this bug report, as well as this patch in Rcpp. This thread on the r-package-devel list which includes some workarounds.

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

1 participant