-
Notifications
You must be signed in to change notification settings - Fork 360
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
Conversation
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}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
I found this merge is outdated, re-open one #172 |
Actually we should keep current behavior not link shared libcurl to curlpp, the owner project will handle it.
build broken scenario: