Skip to contentSkip to conversation

libcpprestsdk: fix building as a static library

PATCH Superseded Adam Duskett 2 participants 2 messages Feb 6, 2018 – Feb 8, 2018

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libcpprestsdk: fix building as a static library

zlib must be put after OpenSSL when building as a static library or else OpenSSL will be unable to find zlib specific functions.

Put the search for zlib below the search for OpenSSL to ensure that zlib links after OpenSSL.

Fixes:
http://autobuild.buildroot.net/results/1df528254468a5ece2f6fe37b3401e68737beed1

---
 .../0004-fix-static-library-linking.patch          | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 package/libcpprestsdk/0004-fix-static-library-linking.patch
package/libcpprestsdk/0004-fix-static-library-linking.patch new file +56 -0
new file mode 100644
index 0000000000..e904bb96c1
@@ -0,0 +1,56 @@
+From cefe8da037e0c2bb97dc1cb4d7ff43e7123feabf Mon Sep 17 00:00:00 2001
+From: Adam Duskett <[email protected]>
+Date: Tue, 6 Feb 2018 11:34:49 -0500
+Subject: [PATCH] fix static library linking
+
+zlib must be put after OpenSSL when building as a static library or else
+OpenSSL will be unable to find zlib specific functions.
+
+Put the search for zlib below the search for OpenSSL to
+ensure that zlib links after OpenSSL.
+
+Upstream status: submitted
+https://github.com/Microsoft/cpprestsdk/pull/688
+
+Signed-off-by: Adam Duskett <[email protected]>
+---
+ Release/src/CMakeLists.txt | 16 ++++++++--------
+ 1 file changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/Release/src/CMakeLists.txt b/Release/src/CMakeLists.txt
+index 3f8a0f8..2a6d440 100644
+--- a/Release/src/CMakeLists.txt
++++ b/Release/src/CMakeLists.txt
+@@ -75,14 +75,6 @@ else()
+   message(FATAL_ERROR "Invalid implementation")
+ endif()
+ 
+-# Compression component
+-if(CPPREST_EXCLUDE_COMPRESSION)
+-  target_compile_definitions(cpprest PRIVATE -DCPPREST_EXCLUDE_COMPRESSION=1)
+-else()
+-  cpprest_find_zlib()
+-  target_link_libraries(cpprest PRIVATE cpprestsdk_zlib_internal)
+-endif()
+-
+ # PPLX component
+ if(CPPREST_PPLX_IMPL STREQUAL "apple")
+   find_library(COREFOUNDATION CoreFoundation "/")
+@@ -133,6 +125,14 @@ else()
+   message(FATAL_ERROR "Invalid implementation")
+ endif()
+ 
++# Compression component
++if(CPPREST_EXCLUDE_COMPRESSION)
++  target_compile_definitions(cpprest PRIVATE -DCPPREST_EXCLUDE_COMPRESSION=1)
++else()
++  cpprest_find_zlib()
++  target_link_libraries(cpprest PRIVATE cpprestsdk_zlib_internal)
++endif()
++
+ # fileio streams component
+ if(CPPREST_FILEIO_IMPL STREQUAL "win32")
+   target_sources(cpprest PRIVATE streams/fileio_win32.cpp)
+-- 
+2.14.3
+
Signature · 1 line
2.14.3
#1 lore raw

PATCH 1/1 libcpprestsdk: fix building as a static library

Hello,

Quoted 25 lines · Adam Duskett

zlib must be put after OpenSSL when building as a static library or else OpenSSL will be unable to find zlib specific functions.

Put the search for zlib below the search for OpenSSL to ensure that zlib links after OpenSSL.

Fixes:
http://autobuild.buildroot.net/results/1df528254468a5ece2f6fe37b3401e68737beed1

---
 .../0004-fix-static-library-linking.patch          | 56 ++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 package/libcpprestsdk/0004-fix-static-library-linking.patch
package/libcpprestsdk/0004-fix-static-library-linking.patch new file +5 -0
new file mode 100644
index 0000000000..e904bb96c1
@@ -0,0 +1,56 @@
+From cefe8da037e0c2bb97dc1cb4d7ff43e7123feabf Mon Sep 17 00:00:00 2001
+From: Adam Duskett <[email protected]>
+Date: Tue, 6 Feb 2018 11:34:49 -0500
+Subject: [PATCH] fix static library linking
+

package/libcpprestsdk/0004-fix-static-library-linking.patch line 15

Quoted 10 lines
package/libcpprestsdk/0004-fix-static-library-linking.patch new file +10 -0
+zlib must be put after OpenSSL when building as a static library or else
+OpenSSL will be unable to find zlib specific functions.
+
+Put the search for zlib below the search for OpenSSL to
+ensure that zlib links after OpenSSL.
+
+Upstream status: submitted
+https://github.com/Microsoft/cpprestsdk/pull/688
+
+Signed-off-by: Adam Duskett <[email protected]>

This is in fact not really the correct fix. The correct fix is to use pkg-config, which already takes care of recursive dependencies when linking statically.

cpprestsdk shouldn't have to know that openssl internally uses zlib. In fact, it is just an accident that cpprestsdk also needs zlib for other reasons. It could very well be that cpprestsdk only needed openssl, and had no reason to know about zlib.

Can we use pkg-config instead ? CMake has good support for pkg-config, so it is quite easy to use.

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
http://bootlin.com