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

duplicate symbols for architecture x86_64 #28

Closed
isezen opened this issue May 12, 2019 · 2 comments · Fixed by #29
Closed

duplicate symbols for architecture x86_64 #28

isezen opened this issue May 12, 2019 · 2 comments · Fixed by #29

Comments

@isezen
Copy link

isezen commented May 12, 2019

Hello,
I created a simple minimal R package to reproduce the following compile error. If I include the dqrng_distribution.h or similar files into more than one .cpp file, I'm getting the following error. I believe those functions are not inline in header files but I might be wrong. Is there a workaround to overcome this issue or did I stuck to a single .cpp file?

duplicate symbol __ZN5dqrng20random_64bit_wrapperIN10pcg_detail6engineIyoNS1_12xsl_rr_mixinIyoEELb0ENS1_15specific_streamIoEENS1_18default_multiplierIoEEEEE4seedEyy in:
    rcpp1.o
    stat.o
duplicate symbol __ZN5dqrng20random_64bit_wrapperINS_7xoshiroILm2ELa24ELa16ELa37EEEE4seedEyy in:
    rcpp1.o
    stat.o
duplicate symbol __ZN5dqrng20random_64bit_wrapperINS_7xoshiroILm4ELa17ELa45ELa0EEEE4seedEyy in:
    rcpp1.o
    stat.o
duplicate symbol __ZN5dqrng20random_64bit_wrapperIN5sitmo15threefry_engineIyLm64ELm20EEEE4seedEyy in:
    rcpp1.o
    stat.o
ld: 4 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
LTLA added a commit to LTLA/dqrng that referenced this issue May 13, 2019
Inline template specializations for correct linking, fixes daqana#28.
@LTLA
Copy link
Contributor

LTLA commented May 13, 2019

I can't even get it to compile, let alone link. It seems xoshiro.h could do with:

#include <functional>
#include <algorithm>
#include <type_traits> // just in case.

... while your stat.hpp needs:

#include <functional>
#include <vector>

Presumably your compiler drags in those headers with something else that got #included, so you don't see a problem, but other implementations may not do so. In this case, I'm failing with GCC 7.4.0.

Anyway, onto the actual problem. The template specialized functions in dqrng_generator.h need to be inlined to bypass the one-definition rule. See #29; I didn't do them all, but we probably should.

@rstub rstub closed this as completed in #29 May 13, 2019
rstub pushed a commit that referenced this issue May 13, 2019
Inline template specializations for correct linking, fixes #28.
@isezen
Copy link
Author

isezen commented May 13, 2019

similar problem exist here, too.

template<>
uint16_t right_shift<32, uint16_t>(uint16_t val) { return 0; } // # nocov
template<>
uint32_t right_shift<32, uint32_t>(uint32_t val) { return 0; } // # nocov
template<int SHIFT, typename UIN>
UIN left_shift(UIN val) {
return val << SHIFT;
}
template<>
uint16_t left_shift<32, uint16_t>(uint16_t val) { return 0; } // # nocov
template<>
uint32_t left_shift<32, uint32_t>(uint32_t val) { return 0; } // # nocov

rstub added a commit that referenced this issue May 13, 2019
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

Successfully merging a pull request may close this issue.

2 participants