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

Multiple definition compilation errors from mman.h on MinGW32 #312

Closed
LTLA opened this issue Oct 5, 2018 · 3 comments
Closed

Multiple definition compilation errors from mman.h on MinGW32 #312

LTLA opened this issue Oct 5, 2018 · 3 comments

Comments

@LTLA
Copy link
Contributor

LTLA commented Oct 5, 2018

Should the mmap, munmap, etc. functions in mman.h be inlined to avoid the ODR? I've been including the annoylib.h headers in several *.cpp files that are to be used to create a single shared library (in an R package via RcppAnnoy, see https://github.com/LTLA/BiocNeighbors) - this works fine, except on Windows where linking fails due to multiple definitions of the mm* functions. This seems like a standard case for requiring inlineing in a header-only library, though I don't have a Windows machine available to confirm it's a fix.

@erikbern
Copy link
Collaborator

erikbern commented Oct 5, 2018

what's ODR?

not sure what's going on since there's definitely an #ifndef guard at the top

@LTLA
Copy link
Contributor Author

LTLA commented Oct 5, 2018

Ah, sorry - One Definition Rule. The header guard only protects against multiple includes in a single translation unit (i.e., each *.o, in my case) but it doesn't protect against multiple definitions upon linking different units into a single library, which is the problem here. I'm no expert on this, but inlineing the relevant functions seems to help, presumably by forcing the functions to be be defined locally in each unit that includes the header file.

@erikbern
Copy link
Collaborator

erikbern commented Oct 6, 2018

sure if inlining resolves the issue, feel free to submit a pull request!

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