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

Fix build broken when there have no shared libcurl (only static libcurl) #168

Closed
wants to merge 0 commits into from

Conversation

laoshanxi
Copy link

@laoshanxi laoshanxi commented May 31, 2024

Actually we should keep current behavior not link shared libcurl to curlpp, the owner project will handle it.

build broken scenario:

# cmake ..
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- curlpp version=[0.8.1]
-- curlpp version num=[000801]
-- Looking for CURL
CMake Warning (dev) at /usr/local/lib64/cmake/CURL/CURLConfig.cmake:51 (if):
  if given arguments:

    "ON"

  An argument named "ON" appears in a conditional statement.  Policy CMP0012
  is not set: if() recognizes numbers and boolean constants.  Run "cmake
  --help-policy CMP0012" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/FindCURL.cmake:68 (find_package)
  CMakeLists.txt:72 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /usr/local/lib64/cmake/CURL/CURLConfig.cmake:54 (if):
  if given arguments:

    "ON"

  An argument named "ON" appears in a conditional statement.  Policy CMP0012
  is not set: if() recognizes numbers and boolean constants.  Run "cmake
  --help-policy CMP0012" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.
Call Stack (most recent call first):
  /usr/local/share/cmake-3.22/Modules/FindCURL.cmake:68 (find_package)
  CMakeLists.txt:72 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found CURL: /usr/local/lib64/cmake/CURL/CURLConfig.cmake (found version "8.5.0")  
-- Found CURL version: 
-- Using CURL include dir(s): 
-- Using CURL lib(s): 
-- Configuring done
CMake Warning (dev) at CMakeLists.txt:106 (add_library):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "curlpp" links to target "OpenSSL::SSL" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:106 (add_library):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "curlpp" links to target "OpenSSL::Crypto" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:106 (add_library):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "curlpp" links to target "ZLIB::ZLIB" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:106 (add_library):
  Policy CMP0003 should be set before this line.  Add code such as

    if(COMMAND cmake_policy)
      cmake_policy(SET CMP0003 NEW)
    endif(COMMAND cmake_policy)

  as early as possible but after the most recent call to
  cmake_minimum_required or cmake_policy(VERSION).  This warning appears
  because target "curlpp" links to some libraries for which the linker must
  search:

    -lpthread, OpenSSL::SSL, OpenSSL::Crypto, ZLIB::ZLIB

  and other libraries with known full path:

    /usr/local/lib64/libcurl.a

  CMake is adding directories in the second list to the linker search path in
  case they are needed to find libraries from the first list (for backwards
  compatibility with CMake 2.4).  Set policy CMP0003 to OLD or NEW to enable
  or disable this behavior explicitly.  Run "cmake --help-policy CMP0003" for
  more information.
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /workspace/curlpp/build

CMakeLists.txt Outdated
@@ -106,7 +106,6 @@ if(CURLPP_BUILD_SHARED_LIBS)
add_library(${PROJECT_NAME} SHARED ${HeaderFileList} ${SourceFileList})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
target_link_libraries(${PROJECT_NAME} PUBLIC CURL::libcurl ${CONAN_LIBS})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CURL::libcurl must be there.

Copy link
Author

@laoshanxi laoshanxi Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CURL::libcurl must be there.

Why we add this in the last commit? this actually broken the build when static link libcurl.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually broken the build when static link libcurl.

I might give more explanation how CMake works at this point. But it is unclear which error you refer to.

It is clear from your log that your CMakeLists.txt either lacks proper use of cmake_minimum_required (i.e. before project), or it doesn't at least ask for 3.5.

Copy link
Author

@laoshanxi laoshanxi Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dg0yt for your reply, in my case app-mesh, I built openssl & curl like this:

# build openssl
wget --quiet --no-check-certificate https://www.openssl.org/source/openssl-3.0.13.tar.gz
tar zxvf openssl-3.0.13.tar.gz >/dev/null
cd openssl-3.0.13
./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl --libdir=lib shared
make -j 3 >/dev/null
make install_sw
echo "/usr/local/ssl/lib" >/etc/ld.so.conf.d/openssl.conf
ldconfig
# build static libcurl
wget https://curl.se/download/curl-8.5.0.tar.gz
tar zxvf curl-8.5.0.tar.gz >/dev/null; cd curl-8.5.0
mkdir build; cd build; 
cmake .. -DHTTP_ONLY=ON -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DOPENSSL_ROOT_DIR=/usr/local/ssl || cmake .. -DHTTP_ONLY=ON -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DCURL_USE_OPENSSL=ON
make -j 3 >/dev/null
make install

so the openssl </usr/local/ssl> and curl </usr/local/lib64/libcurl.a> were all built manually in order to not conflict with system default one.

with this solution, if we link libcurl while building curlpp, it will try to find ssl as well and failed, without link libcurl, everything works well.

[root@51dba5857ef0 build]# make
Consolidate compiler generated dependencies of target curlpp
[  4%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/Easy.cpp.o
[  8%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/Exception.cpp.o
[ 12%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/Form.cpp.o
[ 16%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/Multi.cpp.o
[ 20%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/OptionBase.cpp.o
[ 25%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/Options.cpp.o
[ 29%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/cURLpp.cpp.o
[ 33%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/internal/CurlHandle.cpp.o
[ 37%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/internal/OptionList.cpp.o
[ 41%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/internal/OptionSetter.cpp.o
[ 45%] Building CXX object CMakeFiles/curlpp.dir/src/curlpp/internal/SList.cpp.o
[ 50%] Linking CXX shared library libcurlpp.so
/usr/bin/ld: cannot find -lOpenSSL::SSL
/usr/bin/ld: cannot find -lOpenSSL::Crypto
/usr/bin/ld: cannot find -lZLIB::ZLIB
collect2: error: ld returned 1 exit status
make[2]: *** [libcurlpp.so.1.0.0] Error 1
make[1]: *** [CMakeFiles/curlpp.dir/all] Error 2
make: *** [all] Error 2

I think if you link libcurl, you need consider openssl as well, otherwise, there will have some problems in different compile environment.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the policy-related CMake warnings go away with cmake_minimum_required?
Did you try a clean build?

CURLConfig.cmake has these lines which triggered the warnings in your build and which would resolve OpenSSL::SSL, OpenSSL::Crypto and ZLIB::ZLIB if executed properly:
https://github.com/curl/curl/blob/7161cb17c01dcff1dc5bf89a18437d9d729f1ecd/CMake/curl-config.cmake.in#L26-L32

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This build failure happen not from my code, but in building curlpp.

  • I am using curl 8.5.0 which looks the same as the link you shared: https://github.com/curl/curl/blob/curl-8_5_0/CMake/curl-config.cmake.in#L26

  • I always use clean build, I am using Github action, so every time, it's clean.

  • When I added cmake_minimum_required(VERSION 3.5), no warning, but also no makefile generated, so not work.

[root@51dba5857ef0 b]# git diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4f550b5..84bf7ba 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,4 @@
+cmake_minimum_required(VERSION 3.5)
 project(curlpp)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you link libcurl, you need consider openssl as well, otherwise, there will have some problems in different compile environment.

The reason is why you need link libcurl here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't build a single executable without linking curl and all link libs it needs.

curlpp is just a wrapper, so curl is a transitive usage requirement.
In Modern CMake, transitive usage requirements are implemented via imported targets and target_link_libraries.
Note that this doesn't necessarily mean immediate linking of the artifact. When building static libs, CMake will take care of forwarding the transitive usage requirements.

  • This build failure happen not from my code, but in building curlpp.

Indeed, wrong use of cmake_minimum_required is a bug in curlpp.

  • When I added cmake_minimum_required(VERSION 3.5), no warning, but also no makefile generated, so not work.

Well, what is the error then? There is no alternative to fixing the real problems.

Copy link
Author

@laoshanxi laoshanxi Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I need build libcurl with -DCMAKE_POSITION_INDEPENDENT_CODE=ON for static libcurl.a
  • with cmake_minimum_required, the makefile write to source dir instread of build dir.

Copy link
Author

@laoshanxi laoshanxi Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a clean test, it works with with cmake_minimum_required(VERSION 3.5) and -DCMAKE_POSITION_INDEPENDENT_CODE=ON for libcurl
[root@51dba5857ef0 b]# cmake -DOPENSSL_ROOT_DIR=/usr/local/ssl .. -- curlpp version=[0.8.1] -- curlpp version num=[000801] -- Looking for CURL -- Found CURL version: -- Using CURL include dir(s): -- Using CURL lib(s): -- Configuring done -- Generating done -- Build files have been written to: /tmp/curlpp/b [root@51dba5857ef0 b]# make Consolidate compiler generated dependencies of target curlpp [ 4%] Linking CXX shared library libcurlpp.so [ 50%] Built target curlpp [ 54%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/Easy.cpp.o [ 58%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/Exception.cpp.o [ 62%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/Form.cpp.o [ 66%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/Multi.cpp.o [ 70%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/OptionBase.cpp.o [ 75%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/Options.cpp.o [ 79%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/cURLpp.cpp.o [ 83%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/internal/CurlHandle.cpp.o [ 87%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/internal/OptionList.cpp.o [ 91%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/internal/OptionSetter.cpp.o [ 95%] Building CXX object CMakeFiles/curlpp_static.dir/src/curlpp/internal/SList.cpp.o [100%] Linking CXX static library libcurlpp.a [100%] Built target curlpp_static [root@51dba5857ef0 b]# git diff diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f550b5..f30ea0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,4 @@ +cmake_minimum_required(VERSION 3.5) project(curlpp)

@laoshanxi
Copy link
Author

I found this merge is outdated, re-open one #172

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

Successfully merging this pull request may close these issues.

2 participants