Ошибка при линковке shared библиотеки при использовании cmake
Форум — Development
Имею проект с такой структурой
* test_dpi
* dpi
* include
* typedefs.h
* streams.h
* src
* typedefs.cpp
* streams.cpp
* CMakeLists.txt
* main.cpp
* CMakeLists.txt
typedefs.h
#pragma once
#include <iostream>
#include <vector>
#define DECLARE_SERIALIZATION template<typename Ar> void serialize(Ar& ar, const unsigned version);
namespace DPI
{
enum class Direction : int {
Forward = 1,
Reverse
};
struct Flow {
uint64_t id{};
DECLARE_SERIALIZATION
};
struct Packet {
uint64_t flow_id{};
DECLARE_SERIALIZATION
};
struct Dump {
std::vector<Packet> packets;
std::vector<Flow> flows;
DECLARE_SERIALIZATION
};
}
streams.h
#pragma once
#include "typedefs.h"
#include <boost/filesystem.hpp>
#include <boost/archive/binary_wiarchive.hpp>
#include <boost/archive/binary_woarchive.hpp>
namespace DPI
{
bool load(const std::wstring& path, Dump& dump);
bool dump(const std::wstring& path, const Dump& dump);
}
main.cpp
#include "dpi/streams.h"
int main() {
std::cout << "Hello, World!" << std::endl;
DPI::Dump dump;
DPI::dump(L"this.bin", dump);
return 0;
}
dpi/CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(dpi)
add_library(dpi SHARED
include/dpi/typedefs.h include/dpi/streams.h
src/typedefs.cpp src/streams.cpp
)
target_include_directories(dpi PRIVATE ./include/dpi)
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
project(test_dpi)
set(CMAKE_CXX_STANDARD 17)
find_package(Boost REQUIRED)
add_subdirectory(dpi)
include_directories(${dpi_SOURCE_DIR}/include)
add_executable(test_dpi main.cpp)
link_libraries(test_dpi boost_system boost_serialization boost_wserialization dpi)
Сам подпроект компилируется нормально, но при попытке собрать test_dpi в терминале появляются такие ошибки
====================[ Build | test_dpi | Debug ]================================
/opt/clion-2018.3.1/bin/cmake/linux/bin/cmake --build /home/ramb/Projects/test_dpi/cmake-build-debug --target test_dpi -- -j 2
[ 50%] Linking CXX executable test_dpi
/usr/bin/ld: CMakeFiles/test_dpi.dir/main.cpp.o: in function `main':
/home/ramb/Projects/test_dpi/main.cpp:9: undefined reference to `DPI::dump(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, DPI::Dump const&)'
/usr/bin/ld: CMakeFiles/test_dpi.dir/main.cpp.o: in function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
/usr/include/boost/system/error_code.hpp:676: undefined reference to `boost::system::generic_category()'
/usr/bin/ld: /usr/include/boost/system/error_code.hpp:679: undefined reference to `boost::system::generic_category()'
/usr/bin/ld: CMakeFiles/test_dpi.dir/main.cpp.o: in function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
/usr/include/boost/system/error_code.hpp:706: undefined reference to `boost::system::generic_category()'
/usr/bin/ld: /usr/include/boost/system/error_code.hpp:709: undefined reference to `boost::system::generic_category()'
/usr/bin/ld: /usr/include/boost/system/error_code.hpp:721: undefined reference to `boost::system::generic_category()'
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/test_dpi.dir/build.make:84: test_dpi] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/test_dpi.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/test_dpi.dir/rule] Error 2
gmake: *** [Makefile:118: test_dpi] Error 2
Что я делаю не так?