Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

"Unresolved symbols remain" when using in a C++ project #19

Open
natevw opened this issue Apr 23, 2021 · 0 comments
Open

"Unresolved symbols remain" when using in a C++ project #19

natevw opened this issue Apr 23, 2021 · 0 comments

Comments

@natevw
Copy link

natevw commented Apr 23, 2021

As I started using this library in a C++ project I got some surprising error messages at first about unresolved symbols. Turns out that the compiler assumed the Cifra functions were C++ and would be name-mangled accordingly, but of course the implementation files are all C instead and so it wasn't finding the functions under the right names.

It would be convenient if this project added the usual #ifdef __cplusplus boilerplate to each header meant to be part of the public API. See https://isocpp.org/wiki/faq/mixing-c-and-cpp#include-c-hdrs-personal for some discussion.

Meanwhile the workaround isn't so bad but may not be obvious at first. Instead of e.g.

#include <lib/cifra/src/sha2.h>

wrap the #include itself in the block when including anything from cifra, which in the end does the same thing as if they were in the headers:

extern "C" {
    #include <lib/cifra/src/sha2.h>
}

Note this simple wrapping assumes a header file used only from C++. For a header file that itself saw mixed usage it would need the full boilerplate:

#ifdef __cplusplus
  extern "C" {
#endif
    #include <lib/cifra/src/sha2.h>
#ifdef __cplusplus
  }
#endif
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant