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

Linking to multiple ffi crates fails #980

Closed
seftontycho opened this issue Jul 1, 2024 · 2 comments
Closed

Linking to multiple ffi crates fails #980

seftontycho opened this issue Jul 1, 2024 · 2 comments

Comments

@seftontycho
Copy link

seftontycho commented Jul 1, 2024

I have two crates that use cbindgen to generate bindings for c++.
When I try to build the C++ project with both crates on windows I get the following errors:

06:24:17   analogue_dropouts.lib(alloc-7bfd0a6d1a588dbd.alloc.a1e7c519547c97d-cgu.0.rcgu.o) : error LNK2005: __rdl_oom already defined in language_identification.lib(alloc-f7d2d3884e227169.alloc.e369825d162945b2-cgu.0.rcgu.o)
06:24:17   analogue_dropouts.lib(std-8ac42145e0282c2a.std.184ed18d6ec46d5f-cgu.0.rcgu.o) : error LNK2005: __rdl_alloc already defined in language_identification.lib(std-0953e6946d141dd5.std.1acf644841c643e8-cgu.0.rcgu.o)
06:24:17   analogue_dropouts.lib(std-8ac42145e0282c2a.std.184ed18d6ec46d5f-cgu.0.rcgu.o) : error LNK2005: __rdl_dealloc already defined in language_identification.lib(std-0953e6946d141dd5.std.1acf644841c643e8-cgu.0.rcgu.o)

It looks like some parts of alloc and std are present in both (which makes sense) causing a conflict.
How can I get around this?

My cbindgen.toml looks like the following:

include_guard = "ANALOGUE_DROPOUTS_HPP"

autogen_warning = "/* This file is autogenerated by cbindgen. Don't modify this file manually. */"

namespace = "ffi"

pragma_once = true

[parse]
expand = ["analogue_dropouts"]

[export]
prefix = "analogue_dropouts_"
@seftontycho
Copy link
Author

This is not an issue on linux but I assume that is because on windows to link to the dll you also need the .lib file whereas on linux that is not the case.

@emilio
Copy link
Collaborator

emilio commented Jul 1, 2024

This is not a cbindgen issue, cbindgen only generates the headers... However it seems like you're trying to statically link multiple crates which is not really something that works, see rust-lang/rust#33221 and so on.

A way to make it work could be something like this which compiles everything into a single staticlib.

@emilio emilio closed this as completed Jul 1, 2024
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