question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pulsar-client-cpp not able to build with static link

See original GitHub issue

Expected behavior

Build pulsar-client-cpp lib with static linking all libs.

Set LINK_STATIC to ON in CMakeList.txt and run ./docker-build.sh, expect to build the cpp client lib with static linking.

Actual behavior

Build failed.

Steps to reproduce

In pulsar/pulsar-client-cpp/

$ git diff CMakeLists.txt diff --git a/pulsar-client-cpp/CMakeLists.txt b/pulsar-client-cpp/CMakeLists.txt index 38a47742…7fb08401 100644 — a/pulsar-client-cpp/CMakeLists.txt +++ b/pulsar-client-cpp/CMakeLists.txt @@ -24,7 +24,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} “${CMAKE_SOURCE_DIR}/cmake_modules”) option(BUILD_TESTS “Build tests” ON) MESSAGE(STATUS "BUILD_TESTS: " ${BUILD_TESTS})

-option(LINK_STATIC “Link against static libraries” OFF) +option(LINK_STATIC “Link against static libraries” ON) MESSAGE(STATUS "LINK_STATIC: " ${LINK_STATIC})

option(USE_LOG4CXX “Build with Log4cxx support” OFF) $ ./docker-build.sh … [ 38%] Linking CXX shared library libpulsar.so … /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/5/…/…/…/x86_64-linux-gnu/libboost_filesystem.a(operations.o): relocation R_X86_64_32 against `.rodata.str1.1’ can not be used when making a shared object; recompile with -fPIC /usr/lib/gcc/x86_64-linux-gnu/5/…/…/…/x86_64-linux-gnu/libboost_filesystem.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status lib/CMakeFiles/pulsarShared.dir/build.make:2097: recipe for target ‘lib/libpulsar.so.2.1.0-incubating-SNAPSHOT’ failed make[2]: *** [lib/libpulsar.so.2.1.0-incubating-SNAPSHOT] Error 1 make[2]: Leaving directory ‘/pulsar/pulsar-client-cpp’ CMakeFiles/Makefile2:158: recipe for target ‘lib/CMakeFiles/pulsarShared.dir/all’ failed make[1]: *** [lib/CMakeFiles/pulsarShared.dir/all] Error 2 make[1]: Leaving directory ‘/pulsar/pulsar-client-cpp’ Makefile:86: recipe for target ‘all’ failed make: *** [all] Error 2

System configuration

Pulsar version: 2.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

6reactions
wolfstudycommented, Jun 12, 2019

@f7753 You can update clang-format version, because in CMakeLists.txt:

# `make format` option
if (NOT APPLE AND NOT WIN32)
    set(CLANG_FORMAT_VERSION "5.0")
endif()

Or, we can ignore make check-format. In centos7 OS, the default version of clang is 3.4.2


Then in apachepulsar/pulsar-build:centos-7 image, when i exec make -j12, error as follows:

[root@1fc7007643de pulsar-client-cpp]# make -j12
[ 86%] Built target pulsarShared
[ 86%] Built target pulsarStatic
[ 87%] Built target SampleConsumerListenerCApi
[ 91%] Built target SampleConsumerCApi
[ 91%] Built target SampleProducer
[ 89%] Built target SampleProducerCApi
[ 91%] Built target SampleConsumerListener
[ 93%] Built target SampleConsumer
[ 89%] Built target SampleAsyncProducer
[ 94%] Built target perfProducer
[ 93%] Built target SampleReaderCApi
[ 95%] Built target perfConsumer
[ 95%] Linking CXX shared library _pulsar.so
/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status
make[2]: *** [python/_pulsar.so] Error 1
make[1]: *** [python/CMakeFiles/_pulsar.dir/all] Error 2
make: *** [all] Error 2

I tried to exec yum install -y libstdc++-static.x86_64, this problem was fixed.

2reactions
f7753commented, Jun 13, 2019

BTW, when I compile these code in docker environment, I use the default CPU resource settings, and then I compile with the param -j12, it would throw the error below:

c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make[2]: *** [lib/CMakeFiles/pulsarShared.dir/BatchMessageContainer.cc.o] Error 4
make[2]: *** Waiting for unfinished jobs....

So, if you see the log above, please make sure that your compile params match the docker resource settings.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pulsar C++ client
libpulsar.so is the Shared library, it contains statically linked boost and openssl ... To build the C++ library packages, build the Java packages...
Read more >
C / C++ IDE (CDT) » How to link a static library in C++? - Eclipse
For CDT, go to Project ==> Properties ==> C/C++ Build ==> Settings and add -static to the linker command. There may be a...
Read more >
Walkthrough: Create and use a static library (C++)
To create a static library project in Visual Studio. On the menu bar, choose File > New > Project to open the Create...
Read more >
Protobuf version conflict when linking with libpulsar.so
I am trying to build c++ code that will use protobuf to serialize the ... failed in "/pulsar/pulsar-client-cpp/pkg/rpm/BUILD/apache-pulsar- ...
Read more >
Link Options (Using the GNU Compiler Collection (GCC))
A file name that does not end in a special recognized suffix is considered to name an object file or library. (Object files...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found