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

Make libscrypt-kdf available to C++ applications #363

Closed
Emill opened this issue Feb 23, 2023 · 6 comments
Closed

Make libscrypt-kdf available to C++ applications #363

Emill opened this issue Feb 23, 2023 · 6 comments

Comments

@Emill
Copy link

Emill commented Feb 23, 2023

The scrypt-kdf.h header does not wrap the function using extern "C", which leads to linking issues "undefined reference" in C++ applications. A workaround is to wrap the #include <scrypt-kdf.h> line inside extern "C" as explained by #224, which is a bit annoying.

It would be better to do this directly inside the scrypt-kdf.h file instead.

@gperciva
Copy link
Member

I'm not a C++ expert, but I believe that the

extern "C" {
  #include "..."
}

syntax is the canonical way to include a C header in a C++ project. I think it's an entirely normal part of writing code in C++.

@Emill
Copy link
Author

Emill commented Feb 23, 2023

Usually system libraries have these extern statements for compatibility with C++. From what I have seen, it seems more common to add these externs directly in the header file rather than requiring the application developer to add externs around the include statement. Since there are no particular downsides of having them directly in the include file but it enhances the experience for C++ developers, I guess that's why this is usually done.

As one of many examples, you have GLib, which is a C library but can be used from C++ as well. See https://stackoverflow.com/questions/58665349/what-are-g-begin-decls-and-g-end-decls-for.

The libscrypt project did exactly this: technion/libscrypt@7c0ecda.

@cperciva
Copy link
Member

I agree that this isn't really necessary; on the other hand, since the point of scrypt-kdf.h is to make it easier for people to use this code, we might as well make it easier for people to use this code.

@Emill Can you open a PR with a patch to add this?

@gperciva
Copy link
Member

I included this fix in #364.

@Emill
Copy link
Author

Emill commented Mar 16, 2023

Nice! Sorry, I didn't have time myself to file a PR.

@gperciva
Copy link
Member

Added in #364; will be part of the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants