2

I'm getting undefined reference to 'typeinfo for apache::thrift::transport::TTransportException' (and other symbols) when trying to link my executable with my library which uses thrift. I'm using GCC 7.3.0 on Ubuntu 18.04, building with CMake in CLion I'm stuck after spending a day googling about this problem and after visiting this, that and this links.

The CMake command looks as following

For my shared object:

TARGET_LINK_LIBRARIES(server INTERFACE
                      etcdclient
                      TopologyProtocols
                      event
                      ${THRIFT_LIBRARIES}
                      ${Boost_LIBRARIES}
                      lzo2
                      sqlite3
                      zmq
                      ${SPDK_LIBS}
                      ${DPDK_LIBS}
                      grpc
                      grpc++
                      gtest
                      gmock
                      xml2
                      stdc++fs
                      bfd
                      -l:libisal.so.2
                      sgutils2
                      pthread
                      uuid
                      rt
                      )

The executable CMake command:

TARGET_LINK_LIBRARIES(kserver
                      server
                      ${THRIFT_LIBRARIES}
                      )

Linker command generated by CMake:

cmake_link_script CMakeFiles/kserver.dir/link.txt --verbose=1
/usr/bin/c++  -O3 -DNDEBUG   CMakeFiles/kserver.dir/main.cpp.o  -o kserver  -L/server/ext/spdk/build/lib  -L/server/ext/spdk/dpdk/build/lib  -L/server/ext/isal/lib -Wl,-rpath,/server/ext/spdk/build/lib:/server/ext/spdk/dpdk/build/lib:/server/ext/isal/lib:/server/cmake-build-release/lib/proj:/usr/local/lib:/server/cmake-build-release/ext/etcd:/server/cmake-build-release/protocols ../../lib/proj/libproj.so /usr/local/lib/libthrift.so /usr/local/lib/libthriftnb.so ../../ext/etcd/libetcdclient.so ../../protocols/libTopologyProtocols.so /home/user/vcpkg/installed/x64-linux/lib/libprotobuf.a -levent /usr/local/lib/libthrift.so /usr/local/lib/libthriftnb.so /home/user/vcpkg/installed/x64-linux/lib/libboost_system.a -llzo2 /home/user/vcpkg/installed/x64-linux/lib/libsqlite3.a -lpthread -ldl -lzmq -lspdk -ldpdk -lgrpc -lgrpc++ -lgtest -lgmock -lxml2 -lstdc++fs -lbfd -l:libisal.so.2 -lsgutils2 -lpthread -luuid -lrt

The command looks perfectly fine, it links with thrift, thriftnb and event As of compiler and general projects settings, here a content of root CMakeList.txt in the source root

LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
LIST(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/cmake")

SET(CMAKE_CXX_STANDARD 17)
#SET(ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/lib")
#SET(LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/lib")
#SET(RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/bin")

ADD_COMPILE_OPTIONS(
        -include server.h
        #        -Wall
        #        -pedantic
        -march=native
)
ADD_COMPILE_DEFINITIONS(
        BOOST_COROUTINES_NO_DEPRECATION_WARNING
        GTEST_LINKED_AS_SHARED_LIBRARY
)
INCLUDE_DIRECTORIES(
        ${CMAKE_SOURCE_DIR}/lib/include/server
        ${CMAKE_SOURCE_DIR}/lib/include
)

LINK_DIRECTORIES(
        ${CMAKE_SOURCE_DIR}/ext/spdk/build/lib
        ${CMAKE_SOURCE_DIR}/ext/spdk/dpdk/build/lib
        ${CMAKE_SOURCE_DIR}/ext/isal/lib
)

FIND_PACKAGE(Boost REQUIRED COMPONENTS
             system)
FIND_PACKAGE(Protobuf REQUIRED)
FIND_PACKAGE(GRPC REQUIRED)
INCLUDE(${CMAKE_CURRENT_LIST_DIR}/cmake/FindGRPC.cmake)

FIND_PACKAGE(LZO REQUIRED)
FIND_PACKAGE(sqlite3 REQUIRED)
FIND_PACKAGE(ZeroMQ CONFIG REQUIRED)
FIND_PACKAGE(GTest REQUIRED)
FIND_PACKAGE(Thrift REQUIRED)

ADD_SUBDIRECTORY(lib/server)
ADD_SUBDIRECTORY(ext/etcd)
ADD_SUBDIRECTORY(protocols)
ADD_SUBDIRECTORY(proc/kserver)


Sample compilation command

/usr/bin/c++  -DBOOST_COROUTINES_NO_DEPRECATION_WARNING -DGTEST_LINKED_AS_SHARED_LIBRARY -Dserver_EXPORTS -I/home/user/sourcelib/include/server -I/home/user/sourcelib/include -I/home/user/sourceext/spdk/include -I/home/user/sourcecmake-build-release/ext/etcd -I/home/user/sourcecmake-build-release/protocols -I/home/user/vcpkg/installed/x64-linux/include  -O3 -DNDEBUG -fPIC   -include server.h -march=native -std=gnu++1z -o CMakeFiles/server.dir/misc/ServerHost.cpp.o -c /home/user/sourcelib/server/misc/ServerHost.cpp

What I'm doing wrong?

kreuzerkrieg
  • 3,009
  • 3
  • 28
  • 59
  • It is hard to say at the moment. Did CMake build all C++ sources with a C++ compiler? You might give things a whirl with `CXXFLAGS` that includes `-fexceptions -frtti`. – jww Aug 25 '18 at 16:34
  • Added compilation command and parent CMake file content. -fexceptions enabled by default, as I understand, not sure about RTTI. How (and why) exceptions and RTTI would affect linkage? – kreuzerkrieg Aug 25 '18 at 17:27

1 Answers1

0

It took two days to figure out that there was some esoteric version installed on my machine and the package manager was not aware of it, after removing it manually and using version provided by vcpkg everything linked as expected.

kreuzerkrieg
  • 3,009
  • 3
  • 28
  • 59