-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Static compiling #23
Comments
Hmm, good question. I've never tried to build go-ceph statically, or any software that statically links against librados. As long as librados plays nicely as a statically linked library then I suspect it is possible. Do you have any links on how to build static Go binaries? I can play around with it a little bit. In the first error you posted |
I have found some refs, but little bit outdated I think: http://blog.hashbangbash.com/2014/04/linking-golang-statically/ |
Maybe this... |
Any news about this? |
@adrianlzt sorry no I haven't had time to look into this. thanks for those links. have you hacked on this? i'd be happy to review and merge changes, but my bandwidth is a bit limited right now. |
I'll try, but first I need to understant how all this stuff works (linking, cgo, etc). |
The error |
It is possible to build a static binary using go-ceph, but we have some obstacles to overcome. Firstly, the librados library only has shared library by default, we cannot build statically unless we have static librados library. Secondly, on centos, some libraries librados depends on only have shared library on system, we need to build them ourself. So the steps for building a static library as follows:
# git diff src/librados/CMakeLists.txt
diff --git a/src/librados/CMakeLists.txt b/src/librados/CMakeLists.txt
index f15aa7d..404fc5b 100644
--- a/src/librados/CMakeLists.txt
+++ b/src/librados/CMakeLists.txt
@@ -27,6 +27,9 @@ else(ENABLE_SHARED)
$<TARGET_OBJECTS:librados_api_obj>
$<TARGET_OBJECTS:librados_objs>)
endif(ENABLE_SHARED)
+add_library(rados-static STATIC
+ $<TARGET_OBJECTS:librados_api_obj>
+ $<TARGET_OBJECTS:librados_objs>)
target_link_libraries(librados PRIVATE
osdc ceph-common cls_lock_client
${BLKID_LIBRARIES} ${CRYPTO_LIBS} ${EXTRALIBS})
# git diff src/CMakeLists.txt
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3868956..6b809d2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -711,6 +711,7 @@ if(WITH_STATIC_LIBSTDCXX)
endif()
add_library(ceph-common SHARED ${ceph_common_objs})
+add_library(ceph-common-static STATIC ${ceph_common_objs})
target_link_libraries(ceph-common ${ceph_common_deps})
# appease dpkg-shlibdeps
set_target_properties(ceph-common PROPERTIES And then, we can build static librados library using the following command: make rados-static
make ceph-common-static
--- a/rados/conn.go
+++ b/rados/conn.go
@@ -1,6 +1,11 @@
package rados
-// #cgo LDFLAGS: -lrados
+// #cgo LDFLAGS: -lz -lnspr4 -lnss3 -lresolv -ldl -lm -lssl3 -lssl -lcrypto
+// #cgo LDFLAGS: -L. -lrados-static -lceph-common-static -ljson_spirit -lcls_lock_client
+// #cgo LDFLAGS: -L. -lboost_iostreams -lboost_system -lboost_thread -lboost_regex
+// #cgo LDFLAGS: -L. -libverbs -lnl-3 -lnl-route-3
+// #cgo LDFLAGS: -static-libstdc++ -static-libgcc
+// #cgo CPPFLAGS: -Iinclude/
// #include <stdlib.h>
// #include <rados/librados.h> As the diff shows, we need to copy the static libraries to go-ceph/rados directory for cgo to link. After these two steps, the binary we build does not depend on librados.so to run. |
@yaozongyou which version of ceph are you looking at? I just peaked at the latest master and there seems to be support for building static versions of librados. is this something that people are still interested in? @adrianlzt |
@noahdesu I have tested on the ceph current master branch. As far as i know, the default ceph rpm repo does not contain librados static development rpm. And i have tried to build ceph using the flag |
I have meet the same problem. I want to build the ceph rbd statically but failed, and then I use the go-ceph to work around, but it is also failed. Looks like the root case is the same: lack some static link libraries in ceph. |
Hello, I'm automatically closing all issues filed prior to 2018 that have not been commented on recently. If this issue is still relevant to you please reopen the issue and restart the discussion. Thank you for your understanding. |
I'm trying to make a static binary using go-ceph library.
I have tried passing the static flag to cgo:
Or without cgo:
Is this possible?
Thanks
The text was updated successfully, but these errors were encountered: