-
Notifications
You must be signed in to change notification settings - Fork 365
Add Missing C++ Annotations to Control Symbol Visibility #612
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
Comments
FYI @adetaylor — hopefully this matches your understanding of where cxx_impl_annotations should be going. |
It would be great to get a PR adding a CI job which builds our test suite in a way that is sensitive to these annotations. |
Annotations for symbol visibility (such as `__declspec(dllexport)` and `__attribute__((visibility("default")))`) is the primary use case. Such annotations are expected to be needed on declarations (headers) only, however forcing the annotations into the header file only is causes missing symbols. Therefore the fix is to force the annotations into both declaration (header files) and definition (source files). Original issue: dtolnay#612 PR with the fix for dtolnay#612: dtolnay#615
This fixes missing symbols that occur in v1.0.25.
Hello @dtolnay, I am still getting missing symbols using cxx v1.0.25 (which includes the changes from #615). I have fixed the problem for my cxx-demo-example repo using this patch in my fork of cxx: If you want to test it out, you can use this repo commit: I don't understand why you were only excluding the annotations from source files. Line 953 in b478fcb
As I understand it the annotations should only be included in the declarations (header file), but right now in my project if I change fn begin_function_definition(out: &mut OutFile) {
if out.header {
if let Some(annotation) = &out.opt.cxx_impl_annotations {
write!(out, "{} ", annotation);
}
}
} ... I will get missing symbols for I am continuing to debug the underlying problem but the patch (david-cattermole@d58c650) will fix things (for my projects at least) since the auto-generated files are never intended to be edited, so the problem on definition vs declaration doesn't matter - it's just a human readable problem I guess. Thank you, P.S. I'm still looking into the GitHub actions to trigger the problem via CI on Windows. |
I pulled that commit into 1.0.26. I don't have a good way to know where those annotations are supposed to go so I am happy to do whatever works for now. |
Thanks. I have updated to cxx 1.0.26 and the problem of annotations seem to be fixed. I am however having other symbol problems with the update to 1.0.26 (specifically
I am currently trying to reproduce the error in |
Scratch that, please ignore me. I have discovered the issue and it is unrelated to cxx (I had forgot to update my the cxx version, so I was using the header from 1.0.26 with the cxx.cc file from 1.0.25 - hence causing missing symbol errors.). |
Hello David,
I have noticed that the flag
--cxx-impl-annotations
used on the commandcxxbridge
(from cxxbridge-cmd) does not seem to add annotations to all function and method declarations.As a result of this problem I was only able to use cxx on Windows by compiling downstream libraries that linked to the Rust library by including the C++ source files. (You can see this in my (CMake based) https://github.com/david-cattermole/cxx-demo-example project. See the main branch with the hack included.)
Since GCC and Clang default to exporting all symbols, but MSVC does not, I suspect this was not caught by other users. Or perhaps it's because I'm using
cxxbridge-cmd
directly, or maybe it's caused by older Windows compilers (Visual Studio 2015 / MSVC 14).To fix the missing annotations I have made a commit to my cxx fork; david-cattermole@363c18b. The fix will add annotations to all the function (and method) declarations needed (in my libraries - I could be missing others).
You can see my cxx-demo-example project on the shared-object-symbol-visibility branch which uses my forked
cxx
repo. This has been tested on both Linux GCC and Windows MSVC and it appears to work (see output for Linux/GCC and Windows/MSVC).Would you like a PR? Or you can simply use my commit david-cattermole@363c18b to implement a better fix?
Thanks,
David Cattermole
The text was updated successfully, but these errors were encountered: