1

I'm working with a project that goes by one of two package names, depending on the distribution. On Debian and derivatives, the package name is libcrypto++. On Fedora and derivates, its called libcryptopp. (The official project name is Crypto++).

Users write code, and do things like:

#include <crypto++/aes.h>

And later, they link to the library with -lcrypto++.

Obviously, using "Debian conventions" breaks things on Fedora (and vice versa). See, for example, How to change the include file path with autotools?

I'm trying to determine what can be used to abstract the differences away so the user's code "just works".

Can pkg-config files be used to handle the differences? If so, then how does it handle the #include <crypto++/...> versus #include <cryptopp/...> found in user code? (I'm especially concerned about header clashes, like OpenSSL and Crypto++ both providing aes.h).

If not, what can we do to help with the issues caused by different names on different platforms?

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885

2 Answers2

2

There's nothing built-in to the auto-tools that would do this automatically. It's a fairly unusual need.

There are ways you could get this to work. Here are a couple:

  • Make a symlink in your build tree, with the name you like, pointing to the include tree. That is, symlink from libcrypto++ to /usr/include/libcrytpopp; then use #include <libcrypto++/mumble> in your source. You can make this symlink from configure.

  • Generate a new C macro definition at configure time (see AC_DEFINE) that expands to a string holding the prefix, e.g., "libcryptopp". Then use pasting in the #include line to include the proper header. See this answer.

Community
  • 1
  • 1
Tom Tromey
  • 21,507
  • 2
  • 45
  • 63
0

As Tom Tromey said there is nothing to help you much with this by itself. But with the help of the Crypto++ developers you could come up with a more standardized approach to discover this.

The trick is using pkg-config defined variables, and then use Tom's suggested approach of a macro and pasting. Essentially you just need to define the prefix variable in your .pc file:

includepathprefix = libcryptopp

And then use PKG_CHECK_VAR to read it through.

PKG_CHECK_VAR([CRYPTOPP_PREFIX], [libcrypto++], [includepathprefix])
AC_DEFINE([CRYPTOPP_PREFIX], [$CRYPTOPP_PREFIX],
    [Prefix for crypto++ header files.])

then you should use string pasting to include the files. It's definitely clunky, but it is slightly less of a shot in the dark.

I wrote more information about PKG_CHECK_VAR on my Autotools Mythbuster if you want to see the full syntax.

Diego Elio Pettenò
  • 3,152
  • 12
  • 15