On 2/24/2021 5:24 PM, Nir Azkiel via curl-library wrote:
This is the cmake file for the libcurl:

    include(ExternalProject)
    message(STATUS "Building libcurl enabled")

    set(CURL_FLAGS -DBUILD_CURL_EXE=OFF -DBUILD_SHARED_LIBS=OFF -DUSE_WIN32_LDAP=OFF -DHTTP_ONLY=ON -DCURL_ZLIB=OFF -DCURL_DISABLE_CRYPTO_AUTH=ON -DCMAKE_USE_LIBSSH2=OFF -DBUILD_TESTING=OFF )
    if (WIN32)
        set(CURL_FLAGS ${CURL_FLAGS} -DCURL_STATIC_CRT=ON )
    endif()

    if (APPLE)
        set(CURL_FLAGS ${CURL_FLAGS} -DCMAKE_USE_SECTRANSP=ON )
    elseif(WIN32)
        set(CURL_FLAGS ${CURL_FLAGS} -DCMAKE_USE_SCHANNEL=ON )
    else()
        set(CURL_FLAGS ${CURL_FLAGS} -DCMAKE_USE_OPENSSL=ON )
    endif()

    ExternalProject_Add(
        libcurl
        PREFIX libcurl
        GIT_REPOSITORY "https://github.com/curl/curl.git <https://github.com/curl/curl.git>"
        GIT_TAG "2f33be817cbce6ad7a36f27dd7ada9219f13584c" # curl-7_75_0
        SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/libcurl
        CMAKE_ARGS  -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
                    -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
                    -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}
-DCMAKE_C_FLAGS_MINSIZEREL=${CMAKE_C_FLAGS_MINSIZEREL}
-DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}
-DCMAKE_C_FLAGS_RELWITHDEBINFO=${CMAKE_C_FLAGS_RELWITHDEBINFO}
-DCMAKE_CXX_STANDARD_LIBRARIES=${CMAKE_CXX_STANDARD_LIBRARIES}
-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/libcurl/libcurl_install
                    -DCMAKE_INSTALL_LIBDIR=lib
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
                    -DANDROID_ABI=${ANDROID_ABI}
                    -DANDROID_STL=${ANDROID_STL} ${CURL_FLAGS}
        UPDATE_COMMAND ""
        PATCH_COMMAND ""
        TEST_COMMAND ""
    )

    set(CURL_DEBUG_TARGET_NAME "libcurl-d")
    set(CURL_RELEASE_TARGET_NAME "libcurl")
    add_library(curl INTERFACE)
    add_definitions(-DCURL_STATICLIB) # Mandatory for building libcurl as static lib

    target_include_directories(curl INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/libcurl/libcurl_install/include>)

    # libcurl require ws2_32.lib for windows only
    if (WIN32)
        target_link_libraries(curl INTERFACE ws2_32.lib crypt32.lib)
    else(NOT APPLE)
        set(OPENSSL_USE_STATIC_LIBS TRUE)
        find_package(OpenSSL REQUIRED)
      target_link_libraries(curl INTERFACE OpenSSL::SSL OpenSSL::Crypto)
    endif()

    target_link_libraries(curl INTERFACE debug ${CMAKE_CURRENT_BINARY_DIR}/libcurl/libcurl_install/lib/${CURL_DEBUG_TARGET_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})     target_link_libraries(curl INTERFACE optimized ${CMAKE_CURRENT_BINARY_DIR}/libcurl/libcurl_install/lib/${CURL_RELEASE_TARGET_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})



on my application cmake I have this :

        add_dependencies(rs-depth-quality libcurl)
        target_link_libraries(rs-depth-quality curl)



The yellow line is in charge of adding the linkage to the curl dependency

The green line add the curl project with it's depedency to my application.

It works on Win /Linux /OSX without SSL, with the SSL addition it works on Win but Linux and OSX complains about linkage errors .

Thanks

On Wed, Feb 24, 2021 at 11:13 PM Ray Satiro via curl-library <curl-library@cool.haxx.se <mailto:curl-library@cool.haxx.se>> wrote:

    On 2/24/2021 9:40 AM, Nir Azkiel via curl-library wrote:
    I got libcurl downloaded and build, I would like to add HTTPS
    support but I keep getting linkage errors.

    I added this flag to libcurl Externalproject_Add
    -DCMAKE_USE_OPENSSL=ON

    also I added link to ssl like this

    set(OPENSSL_USE_STATIC_LIBS TRUE)
    find_package(OpenSSL REQUIRED)
    target_link_libraries(curl INTERFACE OpenSSL::SSL OpenSSL::Crypto).

    I am using libcurl latest release : 7.75

    My configure step find the ssl package:
    Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.a (found
    version "1.0.2g")
    I keep getting linkage errors like this:
    ../../libcurl/libcurl_install/lib/libcurl.a(openssl.c.o): In
    function `ossl_log_tls12_secret':
    
3703/home/travis/build/Nir-Az/librealsense/build/third-party/libcurl/lib/vtls/openssl.c:270:
    undefined reference to `SSL_get_session'
    3704../../libcurl/libcurl_install/lib/libcurl.a(openssl.c.o): In
    function `ossl_strerror':
    
3705/home/travis/build/Nir-Az/librealsense/build/third-party/libcurl/lib/vtls/openssl.c:354:
    undefined reference to `ERR_error_string_n'


    ERR_error_string_n is in libcrypto so I think your project is not
    including it. Maybe it is the INTERFACE dependency specification?
    OTOH we are a bit unfamiliar with cmake. Can you give us a minimal
    sample cmake project that can be used to reproduce?



Please don't top-post, it makes the conversation hard to follow [1]. I was able to reproduce using cmake's demo project [2]. It looks like the problem is library order. To reproduce I added appended to Hello/CMakeLists.txt this

add_dependencies(Hello libcurl)
target_link_libraries(Hello curl)

.. then I appended the content from your cmake file for libcurl. I had the same errors in Ubuntu 16. I ran make VERBOSE=1 and saw that the OpenSSL libraries were included before the libcurl library:

/usr/bin/c++      CMakeFiles/helloDemo.dir/demo.cxx.o CMakeFiles/helloDemo.dir/demo_b.cxx.o  -o helloDemo -rdynamic ../Hello/libHello.a /usr/lib/x86_64-linux-gnu/libssl.a /usr/lib/x86_64-linux-gnu/libcrypto.a ../Hello/libcurl/libcurl_install/lib/libcurl.a

I changed that around and added dl and pthread (since this is a static link of OpenSSL that is necessary) I was able to get it to build.

/usr/bin/c++      CMakeFiles/helloDemo.dir/demo.cxx.o CMakeFiles/helloDemo.dir/demo_b.cxx.o  -o helloDemo -rdynamic ../Hello/libHello.a ../Hello/libcurl/libcurl_install/lib/libcurl.a /usr/lib/x86_64-linux-gnu/libssl.a /usr/lib/x86_64-linux-gnu/libcrypto.a -ldl -lpthread

The cmake equivalent changes would mean OpenSSL libs are included after libcurl:

target_link_libraries(curl INTERFACE debug ${CMAKE_CURRENT_BINARY_DIR}/libcurl/libcurl_install/lib/${CURL_DEBUG_TARGET_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}) target_link_libraries(curl INTERFACE optimized ${CMAKE_CURRENT_BINARY_DIR}/libcurl/libcurl_install/lib/${CURL_RELEASE_TARGET_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
target_link_libraries(curl INTERFACE OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(curl INTERFACE dl pthread)

You'd have to adjust that for your project but basically that's the idea. I must reiterate I don't know much cmake. There are a few that do know and hopefully they can chime in here. AFAICT this isn't a libcurl problem. We can't be responsible for static linking dependencies.


[1]: https://curl.se/mail/etiquette.html#Do_Not_Top_Post
[2]: https://cmake.org/examples/

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.se/mail/etiquette.html

Reply via email to