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 prints "Static linking is broken!" #841
Comments
That message was introduced in commit 8ed66f9 by @Lekensteyn . You remember the reason? Is it still valid? |
This likely refers to the generated curl-config file that is unusable in a certain configuration involving static libs, the actual library could still be functional. What if you There is also this TODO within that commit:
|
|
It seems that the problem is related to the inclusion of other shared libraries:
The problem is that Here is a WIP patch to prefer linking to static libs, but that still results in invalid linker commands (the TODO on the end is not resolved yet): diff --git a/CMakeLists.txt b/CMakeLists.txt
index 06f18cf..6eff378 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -94,6 +94,15 @@ if (ENABLE_CURLDEBUG)
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CURLDEBUG)
endif()
+# Prefer linking to static libraries when building a static library.
+if(CURL_STATICLIB)
+ if(WIN32)
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ else()
+ set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
+ endif()
+endif()
+
# initialize CURL_LIBS
set(CURL_LIBS "")
@@ -310,6 +319,9 @@ if(CMAKE_USE_OPENSSL)
find_package(OpenSSL)
if(OPENSSL_FOUND)
list(APPEND CURL_LIBS ${OPENSSL_LIBRARIES})
+ if(CURL_STATICLIB)
+ list(APPEND CURL_LIBS ${CMAKE_DL_LIBS})
+ endif()
set(USE_OPENSSL ON)
set(HAVE_LIBCRYPTO ON)
set(HAVE_LIBSSL ON)
@@ -1133,9 +1145,7 @@ set(CURL_CA_BUNDLE "")
set(CURLVERSION "${CURL_VERSION}")
set(ENABLE_SHARED "yes")
if(CURL_STATICLIB)
- # Broken: LIBCURL_LIBS below; .a lib is not built
- message(WARNING "Static linking is broken!")
- set(ENABLE_STATIC "no")
+ set(ENABLE_STATIC "yes")
else()
set(ENABLE_STATIC "no")
endif()
@@ -1144,7 +1154,6 @@ set(includedir "\${prefix}/include")
set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
set(LIBCURL_LIBS "")
set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
-# TODO CURL_LIBS also contains absolute paths which don't work with static -l...
foreach(_lib ${CMAKE_C_IMPLICIT_LINK_LIBRARIES} ${CURL_LIBS})
set(LIBCURL_LIBS "${LIBCURL_LIBS} -l${_lib}")
endforeach() |
Static linking of libcurl is however the ability to build a static libcurl. Using a static libcurl is harder and we actually can't presume that we can figure out and provide the dependency chain of possible libs. |
Libraries for `curl-config --static-libs` are required to have the form -ldl. Assume library paths like /usr/lib/libssl.so and map it to "ssl" for curl-config. This removes the confusing messag "Static linking is broken" which was printed because curl-config --static-libs was disfunctional while the static libcurl.a is fine. Fixes curl#841
Sorry to be using this as a message board for trouble-shooting but you guys seem responsive! :) I've tried building a simple C++ app with the static library and I am getting several ldap linking errors:
The thing that is confusing me is that I have disabled LDAP support: So, I'm not sure why libcurl.a still references LDAP or how to fix this (without having to needlessly link to the LDAP's libs). Suggestions? Thanks! |
I've made a little more progress. I was able get past the Linker errors (I think I may have just needed to clear my CMake cache and start from scratch) but now I don't seem to have any HTTP support (I'm on OSX 10.11.3). A simple call to an https site returns I'm certainly linking to the OpenSSL (and ZLib) libraries when I build libcurl, as well as in my app. However it doesn't look like it:
Thoughts? |
For general questions, help and support, please use curl-library mailing list. For specific bugs/issues you find, file them here. |
The `curl-config --static-libs` command should not output paths like -l/usr/lib/libssl.so, instead print the absolute path without `-l`. This also removes the confusing message "Static linking is broken" which was printed because curl-config --static-libs was disfunctional even though the static libcurl.a library works properly. Fixes curl#841
Fixed |
The `curl-config --static-libs` command should not output paths like -l/usr/lib/libssl.so, instead print the absolute path without `-l`. This also removes the confusing message "Static linking is broken" which was printed because curl-config --static-libs was disfunctional even though the static libcurl.a library works properly. Fixes #841
I want to statically link libcurl into an app I'm writing. I'm using the CMake build system since I'm trying to build with clang. However, the CMake build system is very clear:
However, when I generate and then build I see it's built a file ./lib/libcurl.a
Can this file be trusted?
The text was updated successfully, but these errors were encountered: