Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

arm - undefined reference error when building program using shared library that link static library

I built AWS WebRTC library as static library and made some shared library using it. As I understand, the static library should be included to the shared library if I make the shared library with the static library. But "undefined reference to ''" error(about the WebRTC library) happens if I build a program using the shared library.

Undefined reference error when building a program using the shared library

arm-linux-gnueabihf-g++ .obj/main.o -Wl,-rpath=/lib -Llibs -lpthread -lmysharedlib -o KeyWeDoorbell
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `getStateMachineCurrentState'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `mbedtls_x509write_crt_der'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `compareJsonString'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `initializeEndianness'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `mbedtls_x509_crt_parse_file'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `hashTableCreateWithParams'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `usrsctp_conninput'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `stackQueueRemoveItem'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `putInt32'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `lws_service'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `globalUnlockMutex'
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `onDataChannel'
....
/home/jacob/Workspace/toolchain/arm-linux-gnueabihf/bin/ld: libs/libkeywe.so: undefined reference to `globalGetTime'
collect2: error: ld returned 1 exit status

Build the shared library

arm-linux-gnueabihf-g++ -shared .obj/aws_webrtc_test.o -lpthread -Llibs -Bstatic -lkvsWebrtcClient -lkvsWebrtcSignalingClient -o mysharedlib.so

-------------------------- Edit ----------------------------

I tried to build a program that use the static library directly but it works well. So I thought it is because of Scope(PUBLIC/INTERFACE/PRIVATE) of target_link_libraries in the library CMakefile.

So I changed it like this

add_library(kvsWebrtcClient ${LINKAGE} ${WEBRTC_CLIENT_SOURCE_FILES})

target_link_libraries(
  kvsWebrtcClient
  PUBLIC kvspicUtils
         kvspicState
         ${CMAKE_THREAD_LIBS_INIT}
         ${OPENSSL_SSL_LIBRARY}
         ${OPENSSL_CRYPTO_LIBRARY}
         ${SRTP_LIBRARIES}
         ${Usrsctp}
         ${MBEDTLS_LIBRARIES}
         ${GPERFTOOLS_MALLOC_LIBRARIES}
         ${GPERFTOOLS_PROFILER_LIBRARIES}
         ${EXTRA_DEPS})

add_library(kvsWebrtcSignalingClient ${LINKAGE} ${WEBRTC_SIGNALING_CLIENT_SOURCE_FILES})

target_link_libraries(
  kvsWebrtcSignalingClient
  PUBLIC kvsCommonLws
         ${LIBWEBSOCKETS_LIBRARIES} 
         kvspicUtils
         kvspicState
         ${CMAKE_THREAD_LIBS_INIT}
         ${EXTRA_DEPS}
         ${OPENSSL_SSL_LIBRARY}
         ${OPENSSL_CRYPTO_LIBRARY}
         ${GPERFTOOLS_MALLOC_LIBRARIES}
         ${GPERFTOOLS_PROFILER_LIBRARIES}
         ${MBEDTLS_LIBRARIES})

But it is the same. Is there anyone who know how to fix it?

question from:https://stackoverflow.com/questions/65897491/undefined-reference-error-when-building-program-using-shared-library-that-link-s

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...