Skip to content

snappy v1.2.2: undefined reference to `typeinfo for snappy::Source`

Description:

As of the current version of snappy in Archlinux, it is impossible to use the snappy::Source class (in snappy-sinksource.h) due to a linker error.

This makes it impossible to build Ceph on Arch and presumably, anything else that uses this class with fail the same way.

Additional info:

Steps to reproduce:

# CMakeLists.txt

cmake_minimum_required(VERSION 3.13)
project(app VERSION 1.0.0 LANGUAGES C CXX)

if(NOT CMAKE_CXX_STANDARD)
  # This project requires C++11.
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_CXX_STANDARD_REQUIRED ON)
  set(CMAKE_CXX_EXTENSIONS OFF)
endif(NOT CMAKE_CXX_STANDARD)

find_package(PkgConfig REQUIRED)
pkg_check_modules(Snappy REQUIRED snappy)

set(srcs main.cpp)

add_executable(
  app
  ${srcs}
)
target_link_libraries(
  app
  PRIVATE ${Snappy_LIBRARIES}
)
target_include_directories(
  app
  PUBLIC ${Snappy_INCLUDE_DIRS}
)
// main.cpp

#include <iostream>

#include <snappy.h>
#include <snappy-sinksource.h>

class Repo : public snappy::Source
{
public:
    size_t Available() const override
    {
        return 0;
    }
    const char *Peek(size_t *len) override
    {
        const char *data = NULL;
        return data;
    }
    void Skip(size_t n) override
    {}
};

int main()
{
    Repo *r = new Repo();

    std::cout << r->Available() << std::endl;
    return 0;
}
pacman -S cmake ninja snappy
cmake -Bbuild -GNinja -S. && cmake --build build

and you'll see something like:

[1/1] Linking CXX executable app
FAILED: app
: && /bin/c++  -Wl,--dependency-file=CMakeFiles/app.dir/link.d CMakeFiles/app.dir/main.cpp.o -o app  -lsnappy && :
/bin/ld: CMakeFiles/app.dir/main.cpp.o:(.data.rel.ro._ZTI4Repo[_ZTI4Repo]+0x10): undefined reference to `typeinfo for snappy::Source'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Edited by Paul Stemmet
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information