-
Notifications
You must be signed in to change notification settings - Fork 337
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
does it work in a Windows cdylib? #1115
Comments
I don't know anything about cdylib on Windows, but possibly it's related to #231. Is the error any different if you do this? class MyClass {
public:
__declspec(dllexport) MyClass();
__declspec(dllexport) uint32_t something(uint32_t input) const;
}; |
I did not see any difference in the message when __declspec(dllexport) was added. I will keep trying a few permutations. The *.lib file seems correct, but I'm no expert. Incidentally it also fails as a dylib, but not as an rlib. Also, as an observation, I tried to add a block like this in my cpp *.h file:
and then in the *.cpp file, I added the following before the header file is included
However it seems like somewhere in the process of building the DLL, the header file is being read directly, and it compiles it with __declspec(dllimport) instead of __declspec(dllexport) since CXX_DLL is not set. Will update if I learn anything new. |
Sounds good. One other knob that may be fruitful to mess with (if you are using cxx-build / build.rs / Cargo as your build system) is right here: Lines 399 to 403 in 8b7643b
You can try adding: cxx_impl_annotations: Some("__declspec(dllexport)".to_owned()), in that struct to make cxx-build stick a given attribute onto every signature in the generated binding. (Obviously we would expose this in a better way if it turns out to work.) |
I managed to get it to work. I don't think it has anything to do with linkage, there is probably something I don't understand in the sample. The root of the problem was probably a misunderstanding between my header file, and the code that was generated by the build crate from the cpp file. Once I managed to fix that, it works. I did not have to use the explicit export annotations. The part I don't understand is this (from sample):
In my case, I cannot include both "blobstore.h" (or my equivalent thereof) and "main.rs.h" because I end up with redefinition errors. I must be missing something very basic in the sample. I had to comment out main.rs.h (or in my case, lib.rs.h) to get it to compile. Anyway, sorry for the false alarm, you can close this as "user error" or something. ;) |
Missing a |
No, it's there, but I probably just don't understand the flow here, what causes the conflict below, why those two would conflict.
I have a declaration such as this in my defs.h:
|
It's unlikely there is any more guidance I would be able to provide on this, so I'll close the issue at this point. Good luck! |
Is using this in a cdylib (on windows) supported?
I am trying to follow the documentation, and although I can get it to work in an exe, when I try it in a cdylib I get linkage errors coming from the C++ compiler (the C++ functions cannot be found).
For example I have a class:
and on the rust side, I have:
When I compile this, I get a link failure (trimmed down a bit):
The text was updated successfully, but these errors were encountered: