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

cmake build failed #12316

Closed
wddsx opened this issue Nov 13, 2023 · 12 comments
Closed

cmake build failed #12316

wddsx opened this issue Nov 13, 2023 · 12 comments
Labels

Comments

@wddsx
Copy link

wddsx commented Nov 13, 2023

I did this

mkdir build
cd build
cmake .. -DOPENSSL_ROOT_DIR:PATH=/home/sunyuchang/ttt/openssl-openssl-3.0.12/output
make -j 64

The results are as follows :
[100%] Building C object src/CMakeFiles/curl.dir/__/lib/warnless.c.o
[100%] Linking C executable curl
../lib/libcurl.so.4.8.0: undefined reference to OPENSSL_sk_num' ../lib/libcurl.so.4.8.0: undefined reference to BIO_set_data'
../lib/libcurl.so.4.8.0: undefined reference to X509_get0_notAfter' ../lib/libcurl.so.4.8.0: undefined reference to BIO_set_init'
../lib/libcurl.so.4.8.0: undefined reference to OpenSSL_version' ../lib/libcurl.so.4.8.0: undefined reference to OPENSSL_init_ssl'
../lib/libcurl.so.4.8.0: undefined reference to X509_STORE_load_file' ../lib/libcurl.so.4.8.0: undefined reference to EVP_PKEY_get_id'
../lib/libcurl.so.4.8.0: undefined reference to BIO_meth_free' ../lib/libcurl.so.4.8.0: undefined reference to BIO_get_shutdown'
../lib/libcurl.so.4.8.0: undefined reference to SSL_CTX_set_keylog_callback' ../lib/libcurl.so.4.8.0: undefined reference to X509_STORE_up_ref'
../lib/libcurl.so.4.8.0: undefined reference to OPENSSL_sk_pop_free' ../lib/libcurl.so.4.8.0: undefined reference to SSL_get1_peer_certificate'
../lib/libcurl.so.4.8.0: undefined reference to OPENSSL_sk_pop' ../lib/libcurl.so.4.8.0: undefined reference to OPENSSL_sk_value'
../lib/libcurl.so.4.8.0: undefined reference to BIO_meth_set_destroy' ../lib/libcurl.so.4.8.0: undefined reference to BIO_meth_set_write'
../lib/libcurl.so.4.8.0: undefined reference to BIO_meth_set_read' ../lib/libcurl.so.4.8.0: undefined reference to SSL_CTX_set_post_handshake_auth'
../lib/libcurl.so.4.8.0: undefined reference to X509_get0_extensions' ../lib/libcurl.so.4.8.0: undefined reference to SSL_CTX_set_options'
../lib/libcurl.so.4.8.0: undefined reference to SSL_CTX_set_ciphersuites' ../lib/libcurl.so.4.8.0: undefined reference to EVP_MD_CTX_free'
../lib/libcurl.so.4.8.0: undefined reference to X509_get_X509_PUBKEY' ../lib/libcurl.so.4.8.0: undefined reference to X509_get_version'
../lib/libcurl.so.4.8.0: undefined reference to TLS_client_method' ../lib/libcurl.so.4.8.0: undefined reference to X509_get0_notBefore'
../lib/libcurl.so.4.8.0: undefined reference to BIO_get_data' ../lib/libcurl.so.4.8.0: undefined reference to X509_STORE_load_path'
../lib/libcurl.so.4.8.0: undefined reference to BIO_set_shutdown' ../lib/libcurl.so.4.8.0: undefined reference to BIO_meth_new'
../lib/libcurl.so.4.8.0: undefined reference to EVP_MD_CTX_new' ../lib/libcurl.so.4.8.0: undefined reference to BIO_meth_set_create'
../lib/libcurl.so.4.8.0: undefined reference to EVP_PKEY_get_bn_param' ../lib/libcurl.so.4.8.0: undefined reference to ASN1_STRING_get0_data'
../lib/libcurl.so.4.8.0: undefined reference to `BIO_meth_set_ctrl'
collect2: error: ld returned 1 exit status
src/CMakeFiles/curl.dir/build.make:811: recipe for target 'src/curl' failed
make[2]: *** [src/curl] Error 1
CMakeFiles/Makefile2:229: recipe for target 'src/CMakeFiles/curl.dir/all' failed
make[1]: *** [src/CMakeFiles/curl.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

I expected the following

build success

curl/libcurl version

openssl 3.0.12
curl 8.4.0

operating system

ubuntu16.04

@bagder bagder added the cmake label Nov 13, 2023
@bagder
Copy link
Member

bagder commented Nov 14, 2023

and you did make install openssl into /home/sunyuchang/ttt/openssl-openssl-3.0.12/output ? Ie it is a genuine install root?

If you do make VERBOSE=1 you'll get to see the full command lines. Does it seem to use the right OpenSSL lib?

@wddsx
Copy link
Author

wddsx commented Nov 14, 2023

and you did make install openssl into /home/sunyuchang/ttt/openssl-openssl-3.0.12/output ? Ie it is a genuine install root?

If you do make VERBOSE=1 you'll get to see the full command lines. Does it seem to use the right OpenSSL lib?

I'm sure there is the 3.0.12 version of openssl in '/home/sunyuchang/ttt/openssl-openssl-3.0.12/output', and then I run make VERBOSE=1, and it seems that other openssl is used. Is ‘-DOPENSSL_ROOT_DIR’ not working?

/usr/local/gcc-7.3/bin/gcc -W -Wall -pedantic -Wbad-function-cast -Wconversion -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-long-long -Wno-multichar -Wpointer-arith -Wshadow -Wsign-compare -Wundef -Wunused -Wwrite-strings -Wcast-align -Wdeclaration-after-statement -Wempty-body -Wendif-labels -Wfloat-equal -Wignored-qualifiers -Wno-format-nonliteral -Wno-sign-conversion -Wno-system-headers -Wstrict-prototypes -Wtype-limits -Wvla -Wmissing-parameter-type -Wold-style-declaration -Wstrict-aliasing=3 -Wformat=2 -Warray-bounds=2 -ftree-vrp -Wduplicated-cond -Wnull-dereference -fdelete-null-pointer-checks -Wshift-negative-value -Wshift-overflow=2 -Walloc-zero -Wduplicated-branches -Wformat-overflow=2 -Wformat-truncation=1 -Wrestrict -Wdouble-promotion -Wunused-const-variable CMakeFiles/curl.dir/slist_wc.c.o CMakeFiles/curl.dir/tool_binmode.c.o CMakeFiles/curl.dir/tool_bname.c.o CMakeFiles/curl.dir/tool_cb_dbg.c.o CMakeFiles/curl.dir/tool_cb_hdr.c.o CMakeFiles/curl.dir/tool_cb_prg.c.o CMakeFiles/curl.dir/tool_cb_rea.c.o CMakeFiles/curl.dir/tool_cb_see.c.o CMakeFiles/curl.dir/tool_cb_wrt.c.o CMakeFiles/curl.dir/tool_cfgable.c.o CMakeFiles/curl.dir/tool_dirhie.c.o CMakeFiles/curl.dir/tool_doswin.c.o CMakeFiles/curl.dir/tool_easysrc.c.o CMakeFiles/curl.dir/tool_filetime.c.o CMakeFiles/curl.dir/tool_findfile.c.o CMakeFiles/curl.dir/tool_formparse.c.o CMakeFiles/curl.dir/tool_getparam.c.o CMakeFiles/curl.dir/tool_getpass.c.o CMakeFiles/curl.dir/tool_help.c.o CMakeFiles/curl.dir/tool_helpers.c.o CMakeFiles/curl.dir/tool_hugehelp.c.o CMakeFiles/curl.dir/tool_libinfo.c.o CMakeFiles/curl.dir/tool_listhelp.c.o CMakeFiles/curl.dir/tool_main.c.o CMakeFiles/curl.dir/tool_msgs.c.o CMakeFiles/curl.dir/tool_operate.c.o CMakeFiles/curl.dir/tool_operhlp.c.o CMakeFiles/curl.dir/tool_paramhlp.c.o CMakeFiles/curl.dir/tool_parsecfg.c.o CMakeFiles/curl.dir/tool_progress.c.o CMakeFiles/curl.dir/tool_setopt.c.o CMakeFiles/curl.dir/tool_sleep.c.o CMakeFiles/curl.dir/tool_stderr.c.o CMakeFiles/curl.dir/tool_strdup.c.o CMakeFiles/curl.dir/tool_urlglob.c.o CMakeFiles/curl.dir/tool_util.c.o CMakeFiles/curl.dir/tool_vms.c.o CMakeFiles/curl.dir/tool_writeout.c.o CMakeFiles/curl.dir/tool_writeout_json.c.o CMakeFiles/curl.dir/tool_xattr.c.o CMakeFiles/curl.dir/var.c.o CMakeFiles/curl.dir/__/lib/base64.c.o CMakeFiles/curl.dir/__/lib/curl_multibyte.c.o CMakeFiles/curl.dir/__/lib/dynbuf.c.o CMakeFiles/curl.dir/__/lib/nonblock.c.o CMakeFiles/curl.dir/__/lib/strtoofft.c.o CMakeFiles/curl.dir/__/lib/timediff.c.o CMakeFiles/curl.dir/__/lib/version_win32.c.o CMakeFiles/curl.dir/__/lib/warnless.c.o -o curl -Wl,-rpath,/home/sunyuchang/ttt/curl-curl-8_4_0/build/lib: ../lib/libcurl.so.4.8.0 -lpthread /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/x86_64-linux-gnu/libcrypto.so /usr/lib/x86_64-linux-gnu/libz.so

@jzakrzewski
Copy link
Contributor

From /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/x86_64-linux-gnu/libcrypto.so it's pretty obvious the libraries where found in the system instead of your preferred location.
Do you have following files?:

  • /home/sunyuchang/ttt/openssl-openssl-3.0.12/output/lib(64)/libssl.so
  • /home/sunyuchang/ttt/openssl-openssl-3.0.12/output/lib(64)/libcrypto.so

@wddsx
Copy link
Author

wddsx commented Nov 14, 2023

From /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/x86_64-linux-gnu/libcrypto.so it's pretty obvious the libraries where found in the system instead of your preferred location. Do you have following files?:

  • /home/sunyuchang/ttt/openssl-openssl-3.0.12/output/lib(64)/libssl.so
  • /home/sunyuchang/ttt/openssl-openssl-3.0.12/output/lib(64)/libcrypto.so

yes,just as follows :

(sunyuchang) sunyuchang@ubuntu:~/ttt/openssl-openssl-3.0.12/output/lib64$ ls
engines-3  libcrypto.a  libcrypto.so  libcrypto.so.3  libssl.a  libssl.so  libssl.so.3  ossl-modules  pkgconfig

@jay
Copy link
Member

jay commented Nov 14, 2023

I was able to reproduce this in Ubuntu 16 LTS with a caveat. Since the default native packaged cmake 3.5.1 is too old to build curl I had to add Kitware's apt repository for xenial and then sudo apt install cmake which installed cmake 3.20.5. Note the latest cmake is 3.27.7 but Kitware is no longer updating their apt repo with cmake packages for Ubuntu 16.

AFAICT the FindOpenSSL module (/usr/share/cmake-3.20/Modules/FindOpenSSL.cmake) does not search the lib64 directory and that is the problem. I've also looked at the latest one and don't see a lib64 check there either. (edit: lib64 check was added in CMake 3.23.0, so the problem is the packaged cmake is older and missing the fix)

FindOpenSSL.cmake from 3.20.5
FindOpenSSL.cmake from 3.27.7

I'm not sure if failure to search lib64 is a cmake bug so I've asked about it in their forum.

I can think of two ways to work around this and build curl using cmake.

The first way is set the pkgconfig path of OpenSSL via PKG_CONFIG_PATH. For example:

PKG_CONFIG_PATH=/home/sunyuchang/ttt/openssl-openssl-3.0.12/output/lib64/pkgconfig VERBOSE=1 cmake ../curl-8.4.0 -DOPENSSL_ROOT_DIR:PATH=/home/sunyuchang/ttt/openssl-openssl-3.0.12/output

The second way is build and install OpenSSL libs into the lib subdirectory instead of lib64. That is what OpenSSL used to do by default when lib64 subdir does not exist. You can set the directory name by passing --libdir to OpenSSL's config script. For example:

./config shared no-zlib -Wl,--enable-new-dtags,-rpath,'$(LIBRPATH)' --libdir=lib --prefix=/home/sunyuchang/ttt/openssl-openssl-3.0.12/output --openssldir=/home/sunyuchang/ttt/openssl-openssl-3.0.12/output

@jzakrzewski
Copy link
Contributor

The lib64 should be searched. This is what the PATH_SUFFIXES lib lib64 do.

I'd maybe try to do:

set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package(OpenSSL REQUIRED)
set(CMAKE_FIND_DEBUG_MODE FALSE)

here: https://github.com/curl/curl/blob/444f64b3e93bbb0b6a65ffa10c5bb3d1becfc140/CMakeLists.txt#L483C3-L483C33
To try to debug the issue a bit.

@jay
Copy link
Member

jay commented Nov 15, 2023

This is what the PATH_SUFFIXES lib lib64 do.

FindOpenSSL.cmake doesn't add lib64 to PATH_SUFFIXES anywhere AFAICS

set(CMAKE_FIND_DEBUG_MODE TRUE)

With -DOPENSSL_ROOT_DIR:PATH=/home/owner/tmp/osslroot here is what I get:

  find_library considered the following locations:

    /home/owner/tmp/osslroot/lib/(lib)ssl(\.so|\.a)
    /home/owner/tmp/osslroot/lib/(lib)ssleay32(\.so|\.a)
    /home/owner/tmp/osslroot/lib/(lib)ssleay32MD(\.so|\.a)
    /home/owner/tmp/osslroot/(lib)ssl(\.so|\.a)
    /home/owner/tmp/osslroot/(lib)ssleay32(\.so|\.a)
    /home/owner/tmp/osslroot/(lib)ssleay32MD(\.so|\.a)
    /usr/lib/x86_64-linux-gnu/lib/(lib)ssl(\.so|\.a)
    /usr/lib/x86_64-linux-gnu/lib/(lib)ssleay32(\.so|\.a)
    /usr/lib/x86_64-linux-gnu/lib/(lib)ssleay32MD(\.so|\.a)

@jzakrzewski
Copy link
Contributor

FindOpenSSL.cmake doesn't add lib64 to PATH_SUFFIXES anywhere AFAICS

Right. I was looking at FindOpenSSL.cmake from 3.27.7.
It seems to be fixed in CMake 3.23 ( Kitware/CMake@ae48449 )

@bagder
Copy link
Member

bagder commented Nov 15, 2023

@wddsx an easy work-around for you that saves you from having to upgrade your cmake, is to make sure your OpenSSL install uses lib instead of lib64. You can specify that with OpenSSL's ./config script and its --libdir= option.

@vszakats
Copy link
Member

vszakats commented Nov 15, 2023

--libdir= also changes the paths hardcoded in the built binaries, meaning it also changes runtime behaviour. I use the hack of renaming lib64 to lib in the install destination to avoid this build issue (I'm sure this has other side-effects depending on situation).

@jay
Copy link
Member

jay commented Nov 16, 2023

It seems to be fixed in CMake 3.23 ( Kitware/CMake@ae48449 )

Thanks, I missed that. IMO the workarounds we've discussed should be sufficient and this can be closed.

@bagder
Copy link
Member

bagder commented Nov 16, 2023

Case closed.

@bagder bagder closed this as completed Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

5 participants