zengxiaobai edited a comment on issue #305: [Master] go build fail using static library. URL: https://github.com/apache/rocketmq-client-go/issues/305#issuecomment-559316107 > Hello, @hanzhonghua0927 @zengxiaobai > The Cgo SDK will link the dynamic CPP library as default, and the dependencies such as the zlib are linked dynamically. > if you want to use the CPP static library, the Zlib and libstdc++ libraries need to be linked manually, please follow 3 steps: > > 1. remove the dynamic library in your LDPATH(default: /usr/local/lib) > 2. change the LDFLAGs in the go SDK from "cgo LDFLAGS: -L/usr/local/lib -lrocketmq" to "cgo LDFLAGS: -L/usr/local/lib -lz -l stdc++ -lrocketmq" > 3. build your project directly without any building flags. > > please have a try. I try like this: step1: remove librocketmq.so from /usr/local/lib, mv librocketmq.a to /usr/local/lib/ step2: install zlib-static libstdc++-static step3: copy libz.a libstdc++.a to /usr/local/lib step4: change core/producer.go core/message.go core/cfuns.go core/pull_consumer.go core/push_consumer.go FROM #cgo LDFLAGS: -L /usr/local/lib/ -lrocketmq TO -L/usr/local/lib/ -lrocketmq -lz -lstdc++ (-lrocketmq) step5: go build ERRORS: ``` global_logger_storage.cpp:(.text+0x224): undefined reference to `std::string::_Rep::_M_dispose(std::allocator<char> const&)' /usr/local/lib/librocketmq.a(global_logger_storage.o):global_logger_storage.cpp:(.text+0x238): more undefined references to `std::string::_Rep::_M_dispose(std::allocator<char> const&)' follow /usr/local/lib/librocketmq.a(global_logger_storage.o): In function `boost::log::v2s_mt_posix::sources::aux::global_storage::get_or_init(std::type_info const&, boost::shared_ptr<boost::log::v2s_mt_posix::sources::aux::logger_holder_base> (*)())': global_logger_storage.cpp:(.text+0x678): undefined reference to `__cxa_guard_acquire' ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
