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

Error building curl with openssl via pkgconfig #2848

Closed
pszemus opened this issue Aug 8, 2018 · 4 comments
Closed

Error building curl with openssl via pkgconfig #2848

pszemus opened this issue Aug 8, 2018 · 4 comments
Assignees

Comments

@pszemus
Copy link

pszemus commented Aug 8, 2018

I did this

PKG_CONFIG_PATH=/opt/WP/common.libs/lib/pkgconfig ./configure --with-ssl

I expected the following

Curl will be configured to build with SSL support.
OpenSSL is installed in custom path.

what happened

configure script does not report SSL (HTTPS, FTPS, ...) support:

configure: Configured to build curl/libcurl:

  curl version:     7.61.0
  SSL support:      no
  Protocols:        DICT FILE FTP GOPHER HTTP IMAP POP3 RTSP SMTP TELNET TFTP

OpenSSL static libraries are installed in custom path via ./config --prefix=/opt/WP/common.libs --openssldir=/opt/WP/common.libs no-shared -fPIC
pkgconfig files are also installed in /opt/WP/common.libs/lib/pkgconfig/libssl.pc:

prefix=/opt/WP/common.libs
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: OpenSSL-libssl
Description: Secure Sockets Layer and cryptography libraries
Version: 1.1.0h
Requires.private: libcrypto
Libs: -L${libdir} -lssl
Cflags: -I${includedir}

curl's config.log shows missing 'pthread':

configure:22454: checking for openssl options with pkg-config
configure:22468: result: found
configure:22497: pkg-config: SSL_LIBS: "-lssl -lcrypto  "
configure:22499: pkg-config: SSL_LDFLAGS: "-L/opt/WP/common.libs/lib  "
configure:22501: pkg-config: SSL_CPPFLAGS: "-I/opt/WP/common.libs/include  "
configure:22513: checking for HMAC_Update in -lcrypto
configure:22535: gcc -o conftest -Werror-implicit-function-declaration -O2 -Wno-system-headers    -I/opt/WP/common.libs/include      -L/opt/WP/common.libs/lib   conftest.c -lcrypto  -lssl -lcrypto   -lz  >&5
/opt/WP/common.libs/lib/libcrypto.a(threads_pthread.o): In function `CRYPTO_THREAD_lock_new':
threads_pthread.c:(.text+0x25): undefined reference to `pthread_rwlock_init'

curl/libcurl version

curl-7.61.0

operating system

openssl-1.1.0h
CentOS Linux release 7.5.1804 (Core)

@bagder
Copy link
Member

bagder commented Aug 8, 2018

If you look in your config.log below that snippet you showed here, you'll see that configure goes on and then tries again with -ldl and then with -ldl -lpthread added...

In the latter case, the error message it gets back says:

conftest.c:36:21: fatal error: openssl/err.h: No such file or directory
            #include <openssl/err.h>
                     ^~~~~~~~~~~~~~~

It looks like you have a bad openssl install? That's a standard openssl header that's been around since basically forever.

This seems to happen because the AC_TRY_LINK that is tested uses #include and yet the command line that builds the test program didn't get your -I/opt/WP/common.libs/include from the pkg-config...

@bagder
Copy link
Member

bagder commented Aug 8, 2018

Maybe a patch like this?

diff --git a/configure.ac b/configure.ac
index 22280a5e9..b20ce13de 100755
--- a/configure.ac
+++ b/configure.ac
@@ -1648,11 +1648,14 @@ if test -z "$ssl_backends" -o "x$OPT_SSL" != xno &&
   AC_CHECK_LIB(crypto, HMAC_Update,[
      HAVECRYPTO="yes"
      LIBS="-lcrypto $LIBS"
      ],[
      LDFLAGS="$CLEANLDFLAGS -L$LIB_OPENSSL"
-     CPPFLAGS="$CLEANCPPFLAGS -I$PREFIX_OPENSSL/include/openssl -I$PREFIX_OPENSSL/include"
+     if test "$PKGCONFIG" != "yes" ; then
+       # only set this if pkg-config wasn't used
+       CPPFLAGS="$CLEANCPPFLAGS -I$PREFIX_OPENSSL/include/openssl -I$PREFIX_OPENSSL/include"
+     fi
      AC_CHECK_LIB(crypto, HMAC_Init_ex,[
        HAVECRYPTO="yes"
        LIBS="-lcrypto $LIBS"], [
 
        dnl still no, but what about with -ldl?

@bagder bagder self-assigned this Aug 8, 2018
@pszemus
Copy link
Author

pszemus commented Aug 8, 2018

I'd change it to:

diff --git a/configure.ac b/configure.ac
index 22280a5e9..b20ce13de 100755
--- a/configure.ac
+++ b/configure.ac
@@ -1648,11 +1648,14 @@ if test -z "$ssl_backends" -o "x$OPT_SSL" != xno &&
   AC_CHECK_LIB(crypto, HMAC_Update,[
      HAVECRYPTO="yes"
      LIBS="-lcrypto $LIBS"
      ],[
      LDFLAGS="$CLEANLDFLAGS -L$LIB_OPENSSL"
-     CPPFLAGS="$CLEANCPPFLAGS -I$PREFIX_OPENSSL/include/openssl -I$PREFIX_OPENSSL/include"
+     if test "$PKGCONFIG" = "no" ; then
+       # only set this if pkg-config wasn't used
+       CPPFLAGS="$CLEANCPPFLAGS -I$PREFIX_OPENSSL/include/openssl -I$PREFIX_OPENSSL/include"
+     fi
      AC_CHECK_LIB(crypto, HMAC_Init_ex,[
        HAVECRYPTO="yes"
        LIBS="-lcrypto $LIBS"], [
 
        dnl still no, but what about with -ldl?

because PKGCONFIG variable can be "no" or "/usr/bin/pkg-config", to the best of my knowledge.

The aforementioned patch works.

@bagder
Copy link
Member

bagder commented Aug 8, 2018

Excellent!

bagder added a commit that referenced this issue Aug 8, 2018
... by making sure it uses the -I provided by pkg-config!

Reported-by: pszemus on github
Fixes #2848
@bagder bagder closed this as completed in 3668d9d Aug 9, 2018
falconindy pushed a commit to falconindy/curl that referenced this issue Sep 10, 2018
... by making sure it uses the -I provided by pkg-config!

Reported-by: pszemus on github
Fixes curl#2848
Closes curl#2850
@lock lock bot locked as resolved and limited conversation to collaborators Nov 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants