Linking error for client of rabbitmq-c - c++

I want to implement a small c++ client, that connects to my local RabbitMQ-server.
The app is configured with CMakeList as follows:
Boost_STATIC_LIBS: ON
Boost SHARED_LIBS: ON
ENABLE_SSL_SUPPORT: ON
Rabbitmqc_INCLUDE_DIR: C:/rabbitmq-c/include
Rabbitmqc_LIBRARY: C:/rabbitmq-c/lib
Rabbitmqc_SSL_ENABLED: ON
_Rabbitmqc_SSL_HEADER: C:/rabbitmq-c/include/amqp_ssl_socket.h
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(client)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/utilities
)
# Find Boost library
SET(Boost_INCLUDE_DIR C:/local/boost_1_64_0)
SET(Boost_LIBRARY_DIR C:/local/boost_1_64_0/lib64-msvc-14.0)
FIND_PACKAGE(Boost 1.64.0 COMPONENTS chrono system REQUIRED)
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
# Find Rabbitmqc library
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Modules)
FIND_PACKAGE(Rabbitmqc REQUIRED)
INCLUDE_DIRECTORIES(SYSTEM ${Rabbitmqc_INCLUDE_DIRS})
OPTION(ENABLE_SSL_SUPPORT "Enable SSL support." ${Rabbitmqc_SSL_ENABLED})
OPTION(BUILD_SHARED_LIBS "Build client as a shared library" ON)
OPTION(BOOST_STATIC_LIBS "Build Boost as a static library" ON)
IF(WIN32)
SET(PLATFORM_DIR win32)
ELSE(WIN32)
SET(PLATFORM_DIR unix)
ENDIF(WIN32)
set(COMMON_SRCS
utilities/utils.h
utilities/utils.c
${PLATFORM_DIR}/utilities/platform_utils.c
)
SET(client_SRCS
testClient.cxx
)
ADD_EXECUTABLE(client ${client_SRCS})
TARGET_LINK_LIBRARIES(client ${Boost_LIBRARIES} ${Rabbitmqc_LIBRARY} ${OPENSSL_LIBRARIES} ${SOCKET_LIBRARY})
The output of CMake-Gui after generating:
Boost version: 1.64.0
Found the following Boost libraries:
chrono
system
Found Rabbitmqc
Configuring done
WARNING: Target "client" requests linking to directory "C:/rabbitmq-c/lib". Targets may link only to libraries. CMake is dropping the item.
Generating done
I don't understand why the Rabbitmqc library is not linked properly. is the entry ${Rabbitmqc_LIBRARY} in TARGET_LINK_LIBRARIES not enough?
If I compile my client, then I get following errors:
testClient.cxx
#include <iostream>
#include <amqp.h>
#include <amqp_tcp_socket.h>
#include <assert.h>
#include "utilities\utils.h"
int main(int argc, char const *const *argv)
{
char const *hostname;
int port, status;
char const *exchange;
char const *bindingkey;
amqp_socket_t *socket = NULL;
amqp_connection_state_t conn;
amqp_bytes_t queuename;
if (argc < 5)
{
fprintf(stderr, "Usage: amqp_listen host port exchange bindingkey\n");
return 1;
}
hostname = "localhost";
port = atoi("15672");
exchange = "testExchange";
bindingkey = "testMessage";
conn = amqp_new_connection();
socket = amqp_tcp_socket_new(conn);
if(!socket)
{
std::cout<<"Error creating SSL/TLS socket"<<std::endl;
}
status = amqp_socket_open(socket, hostname, port);
if(status)
{
std::cout<<"opening TCP socket"<<std::endl;
}
}
LINK : warning LNK4044: unrecognized option '/lrabbitmq'; ignored
2>testClient.obj : error LNK2019: unresolved external symbol _amqp_new_connection referenced in function _main
2>testClient.obj : error LNK2019: unresolved external symbol _amqp_socket_open referenced in function _main
2>testClient.obj : error LNK2019: unresolved external symbol _amqp_tcp_socket_new referenced in function _main
2>C:\local\boost_1_64_0\lib64-msvc-14.0\boost_chrono-vc140-mt-1_64.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'
2>C:\local\boost_1_64_0\lib64-msvc-14.0\boost_system-vc140-mt-1_64.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'
Thank you for any suggestion!
OS: Win10 64x
Boost: boost_1_64_0 (in path)
rabbitmq-c (in path)
RabbitMQ Server: rabbitmq_server-3.7.6 (in path)
CMake: 3.9.6
OpenSSL: Win32OpenSSL-1_1_0h
IDE: Visual Studio 14(2015)

Related

Unresolved External Symbol LNK2019 CMake

I have here a class called engine and im trying to use, but when i include it i get LNK2019 error. Im running Visual Studio 2019 x86_64 compiler. Any ideas what could be wrong?
I have constructor and destructor defined in cpp file.
#pragma once
namespace NRD {
const int SCREEN_WIDTH(1280);
const int SCREEN_HEIGHT(720);
class Engine {
public:
Engine();
Engine(const Engine&) = delete;
Engine& operator=(const Engine&) = delete;
~Engine();
static Engine& Ref() {
static Engine reference;
return reference;
}
};
static Engine& Core = Engine::Ref();
}
Here is my cpp file:
#include "nrdengine/engine.h"
#include "nrdengine/service_locator.h"
#include "platform/glfw_window.h"
#include <iostream>
namespace NRD {
Engine::Engine() {
std::cout << "Initializing window!" << std::endl;
ServiceLocator::Provide(new CustomWindow());
}
Engine::~Engine() {
ServiceLocator::GetWindow()->DestroyWindow();
}
}
[build] main.obj : error LNK2019: unresolved external symbol "public: __cdecl NRD::Engine::Engine(void)" (??0Engine#NRD##QEAA#XZ) referenced in function "public: static class NRD::Engine & __cdecl NRD::Engine::Ref(void)" (?Ref#Engine#NRD##SAAEAV12#XZ) [C:\Users\Dawid\Desktop\NRD-Engine\build\nrdengine_cpp_application.vcxproj]
[build] main.obj : error LNK2019: unresolved external symbol "public: __cdecl NRD::Engine::~Engine(void)" (??1Engine#NRD##QEAA#XZ) referenced in function "void __cdecl `public: static class Engine::Ref & __cdecl NRD::Engine::Ref(void)'::`2'::`dynamic atexit destructor for 'reference''(void)" (??__Freference#?1??Ref#Engine#NRD##SAAEAV12#XZ#YAXXZ) [C:\Users\Dawid\Desktop\NRD-Engine\build\nrdengine_cpp_application.vcxproj]
[build] C:\Users\Dawid\Desktop\NRD-Engine\build\Debug\nrdengine_cpp_application.exe : fatal error LNK1120: 2 unresolved externals [C:\Users\Dawid\Desktop\NRD-Engine\build\nrdengine_cpp_application.vcxproj]
I have two CMakeList files (one for Engine project, one for App)
APP:
cmake_minimum_required(VERSION 3.5)
project(nrdengine_cpp_application VERSION 0.0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
add_subdirectory(external/engine)
file(GLOB_RECURSE SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/*.c
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
#nrdengine_cpp_application.exe
add_executable(nrdengine_cpp_application ${SOURCE_FILES})
target_link_libraries(nrdengine_cpp_application PUBLIC nrdengine_cpp_engine)
target_include_directories(nrdengine_cpp_application PUBLIC nrdengine_cpp_engine)
ENGINE:
cmake_minimum_required(VERSION 3.5)
project(nrdengine_cpp_engine VERSION 0.0.1 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
#add external libs
#find_package(OpenGL REQUIRED)
# install python and Jinja2
set(GLAD_SOURCES_DIR "${PROJECT_SOURCE_DIR}/external/glad")
add_subdirectory("${GLAD_SOURCES_DIR}/cmake" glad_cmake)
add_subdirectory(external/glfw)
add_subdirectory(external/glm)
add_subdirectory(external/assimp)
file(GLOB_RECURSE SOURCE_FILES
${CMAKE_SOURCE_DIR}/src/*.c
${CMAKE_SOURCE_DIR}/src/*.cpp)
glad_add_library(glad_gl_core_mx_31 REPRODUCIBLE MX API gl:core=3.1)
add_library(nrdengine_cpp_engine ${SOURCE_FILES})
target_include_directories(nrdengine_cpp_engine
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
glm
PRIVATE
glfw
assimp
)
target_link_libraries(${PROJECT_NAME}
PUBLIC
glm
PRIVATE
glad_gl_core_mx_31
glfw
assimp
)```
I'm kinda guessing since your question is kinda hard to answer since it could be a lot of things. But here is my inference.
It's not recommended to glob your source files like you are doing here.
file(GLOB_RECURSE SOURCE_FILES
${CMAKE_SOURCE_DIR}/src/*.c
${CMAKE_SOURCE_DIR}/src/*.cpp)
NOTE: My suggestion requires 3.13 or higher version of CMake.
This causes lots of issues and might be the cause of your problems. Please see this post by one of the CMake maintainers on how to add source files to your project.
https://crascit.com/2016/01/31/enhanced-source-file-handling-with-target_sources/
TLDR:
Make a CMakeLists.txt in your src/ directory like so.
target_sources(foobar PRIVATE
engine.cpp
engine.h
)
And make sure to call add_subdirectory(src) to process that new CMakeLists.txt
If you are interested in why globbing in build systems in general is bad. I can provide links.

Visual Studio 2017 doesn't link the library

I'm trying to build a simple C++ program in Visual Studio 2017. I had no issues while doing it on Linux but for some reason it doesn't work on Windows.
Here is the program:
// CMakeProject1.cpp : Defines the entry point for the application.
//
#include "CMakeProject1.h"
#include "fmt/core.h"
#include "fmt/xchar.h"
#include "spdlog/sinks/win_eventlog_sink.h"
#include "spdlog/sinks/msvc_sink.h"
#include "spdlog/sinks/wincolor_sink.h"
#include "spdlog/spdlog.h"
#include <exception>
#include <vector>
int main()
{
std::vector<spdlog::sink_ptr> sinks;
sinks.push_back(std::make_shared<spdlog::sinks::win_eventlog_sink_mt>("me"));
sinks.push_back(std::make_shared<spdlog::sinks::msvc_sink_mt>());
sinks.push_back(std::make_shared<spdlog::sinks::wincolor_stdout_sink_mt>());
auto logger = std::make_shared<spdlog::logger>("main-logger", begin(sinks), end(sinks));
SPDLOG_LOGGER_CALL(logger, spdlog::level::info, L"{}", L"Hello World!");
return 0;
}
Here is my CMakeLists.txt
# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required(VERSION 3.20)
get_filename_component(Project ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "-" Project ${Project})
project(${Project} CXX C)
set(CMAKE_VERBOSE_MAKEFILE ON)
include(FetchContent)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 8.0.1
)
FetchContent_MakeAvailable(fmt)
if (NOT fmt_POPULATED)
FetchContent_Populate(fmt)
add_subdirectory(${fmt_SOURCE_DIR} ${fmt_BINARY_DIR})
endif()
message(STATUS "fmt_SOURCE_DIR = ${fmt_SOURCE_DIR}")
message(STATUS "fmt_BINARY_DIR = ${fmt_BINARY_DIR}")
FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.9.2
)
FetchContent_MakeAvailable(spdlog)
if (NOT spdlog_POPULATED)
FetchContent_Populate(spdlog)
set(SPDLOG_BUILD_EXAMPLES OFF)
set(SPDLOG_BUILD_BENCH OFF)
set(SPDLOG_BUILD_TESTS OFF)
add_subdirectory(${spdlog_SOURCE_DIR} ${spdlog_BINARY_DIR})
endif()
message(STATUS "spdlog_SOURCE_DIR = ${spdlog_SOURCE_DIR}")
message(STATUS "spdlog_BINARY_DIR = ${spdlog_BINARY_DIR}")
set(SourceDir ${CMAKE_CURRENT_SOURCE_DIR})
set(ExecutableSources ${SourceDir}/main.cpp)
set(LinkLibraries fmt::fmt spdlog::spdlog)
set(Executable ${Project})
message(STATUS CMAKE_VERSION = ${CMAKE_VERSION})
message(STATUS LinkLibraries = ${LinkLibraries})
add_executable(${Executable} ${ExecutableSources})
add_definitions(-DSPDLOG_WCHAR_TO_UTF8_SUPPORT)
target_compile_options(${Executable} PUBLIC ${CompilationFlags})
target_link_libraries(${Executable} PUBLIC ${LinkLibraries})
The way I generate a build files is the same way I do it on Linux
mkdir build
cd build
cmake ..
I then open the solution in Visual Studio 2017 and build it. However I'm getting the following errors:
4>main.cpp
4>main.obj : error LNK2019: unresolved external symbol "void __cdecl spdlog::details::os::wstr_to_utf8buf(class fmt::v8::basic_string_view<wchar_t>,class fmt::v8::basic_memory_buffer<char,250,class std::allocator<char> > &)" (?wstr_to_utf8buf#os#details#spdlog##YAXV?$basic_string_view#_W#v8#fmt##AAV?$basic_memory_buffer#D$0PK#V?$allocator#D#std###56##Z) referenced in function "protected: void __thiscall spdlog::logger::log_<wchar_t const (&)[13]>(struct spdlog::source_loc,enum spdlog::level::level_enum,class fmt::v8::basic_string_view<wchar_t>,wchar_t const (&)[13])" (??$log_#AAY0N#$$CB_W#logger#spdlog##IAEXUsource_loc#1#W4level_enum#level#1#V?$basic_string_view#_W#v8#fmt##AAY0N#$$CB_W#Z)
4>main.obj : error LNK2019: unresolved external symbol "void __cdecl spdlog::details::os::utf8_to_wstrbuf(class fmt::v8::basic_string_view<char>,class fmt::v8::basic_memory_buffer<wchar_t,250,class std::allocator<wchar_t> > &)" (?utf8_to_wstrbuf#os#details#spdlog##YAXV?$basic_string_view#D#v8#fmt##AAV?$basic_memory_buffer#_W$0PK#V?$allocator#_W#std###56##Z) referenced in function "protected: virtual void __thiscall spdlog::sinks::win_eventlog::win_eventlog_sink<class std::mutex>::sink_it_(struct spdlog::details::log_msg const &)" (?sink_it_#?$win_eventlog_sink#Vmutex#std###win_eventlog#sinks#spdlog##MAEXABUlog_msg#details#4##Z)
4>C:\Users\user\source\repos\CMakeProject1\build\Debug\CMakeProject1.exe : fatal error LNK1120: 2 unresolved externals
4>Done building project "CMakeProject1.vcxproj" -- FAILED.
========== Rebuild All: 3 succeeded, 1 failed, 0 skipped ==========
It looks like Visual Studio 2017 is not linking against the libraries. Does anyone know how to fix it?
Expanding on #fabian's comment, you should
set(SPDLOG_WCHAR_TO_UTF8_SUPPORT ON)
before the add_subdirectory call to have CMake set that preprocessor symbol for you.

CMake when FetchContent rabbitmq

I am trying to integrate rabbitmq into one of the modules of my solution in order to switch from mailslots to rabbitmq. The problem is that during the fectcontent, the module "breaks" the links of the other modules. The errors generated are "unresolved external symbols".
##########################
# CODE CMAKELISTS
##########################
file(GLOB sources "src/*.cpp" "src/*.c")
file(GLOB headers "inc/*.hpp" "inc/*.h")
project("${MODULE_NAME}${MODULE_TYPE}")
set(OUTPUT_FILE "${MODULE_NAME}${MODULE_TYPE}")
OPTION(BUILD_TESTS "Build the tests" OFF)
MESSAGE(STATUS "Building : ${PROJECT_NAME}...")
if(BUILD_TESTS)
enable_testing()
ADD_SUBDIRECTORY(test)
MESSAGE(STATUS "Building : ${PROJECT_NAME} test...")
endif()
################################
# RabbitMQ
################################
SET(ENABLE_SSL_SUPPORT OFF CACHE PATH "Shall RabbitMQ be built with ssl support" FORCE)
include(FetchContent)
FetchContent_Declare(
rabbitmq
GIT_REPOSITORY https://github.com/alanxz/rabbitmq-c.git
GIT_TAG v0.10.0
)
FetchContent_GetProperties(rabbitmq)
if(NOT rabbitmq_POPULATED)
FetchContent_Populate(rabbitmq)
add_subdirectory(${rabbitmq_SOURCE_DIR} ${rabbitmq_BINARY_DIR})
endif()
SET_SOURCE_FILES_PROPERTIES( ${sources} PROPERTIES LANGUAGE CXX )
SET_SOURCE_FILES_PROPERTIES( ${headers} PROPERTIES LANGUAGE CXX )
Type of error:
LNK2001 external symbol not resolved "struct fsTUN_GlobalSection_t tun" (?tun##3UfsTUN_GlobalSection_t##A) MOD.LIB fsMOD_maxSpeed.obj 1
LNK2019 external symbol not resolved "long __cdecl fsRTS_MaxSpeed(long,struct _iobuf *,long,long,long,long,struct fs_products *,struct fsSEQ_Adaptation *,double,double,double,double,double *,double *,struct rts_mod *)" (?fsRTS_MaxSpeed##YAJJPEAU_iobuf##JJJJPEAUfs_products##PEAUfsSEQ_Adaptation##NNNNPEAN3PEAUrts_mod###Z) referenced in the function "long __cdecl fsMOD_maxSpeed(struct fs_products *,struct fsSEQ_Adaptation *)" (?fsMOD_maxSpeed##YAJPEAUfs_products##PEAUfsSEQ_Adaptation###Z) MOD.LIB ..\fsMOD_maxSpeed.obj 1

Connect fftw3 library via CMake

The project presents a static library with tests. I add the fftw3 library to it as a submodule, but Microsoft Visual Studio 2017 cannot find this library.
Project Structure:
└───fftw3
└───googletest
└───output_64
└───src
└───tests
└───CMakeLists.txt
└───tests.cpp
└───CMakeLists.txt
└───FFT_lib.cpp
└───FFT_lib.h
└───.gitignore
└───.gitmodules
└───CMakeLists.txt
└───config_folder_and_run_cmake.bat
config_folder_and_run_cmake.bat
git submodule init
git submodule update
"c:\Program Files\CMake\bin\cmake.exe" ^
-H. ^
-Boutput_64 ^
-G"Visual Studio 15 2017 Win64" ^
%*
pause
CMakeLists.txt
cmake_minimum_required(VERSION 3.9.3)
#set the project name
project(FFT)
#set the directories into which libraries and executable files will be collected
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(MSVC)
add_compile_options(
$<$<CONFIG:>:/MT>
$<$<CONFIG:Debug>:/MTd>
$<$<CONFIG:Release>:/MT>
)
endif()
set(CMAKE_CXX_STANDARD 14)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(SRC_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
add_subdirectory(src)
add_subdirectory(googletest)
add_subdirectory(fftw3)
.gitmodules
[submodule "googletest"]
path = googletest
url = https://github.com/google/googletest
[submodule "fftw3"]
path = fftw3
url = https://github.com/FFTW/fftw3
src\CMakeLists.txt
set(SOURCES
FFT_lib.h
FFT_lib.cpp
)
add_library(FFT_lib ${SOURCES})
target_include_directories(FFT_lib PUBLIC ${SRC_ROOT_DIR})
source_group(TREE ${CMAKE_CURRENT_LIST_DIR} FILES ${SOURCES})
#in solution, this library is located in the FFT_lib folder
set_property(TARGET FFT_lib PROPERTY FOLDER "FFT_lib")
add_subdirectory(tests)
src\tests\CMakeLists.txt
set(SOURCES
tests.cpp
)
add_executable(FFT_test ${SOURCES})
# 1. Test library
# 2. gest
# 3. fftw3
target_link_libraries(FFT_test PUBLIC FFT_lib)
target_link_libraries(FFT_test PUBLIC gtest_main)
target_link_libraries(FFT_test PUBLIC fftw3)
set_property(TARGET FFT_test PROPERTY FOLDER "tests/FFT_test")
src\tests\tests.cpp
#include <gtest/gtest.h>
#include "FFT_lib.h"
#include <fftw3.h> //cannot open source file
#include <complex>
#include <vector>
TEST(simple_test, test)
{
using namespace std;
vector<complex<double> > data(64, 1.);
fftw_plan plan = fftw_plan_dft_1d(data.size(), (fftw_complex*)&data[0], (fftw_complex*)&data[0], FFTW_FORWARD, FFTW_ESTIMATE);
fftw_execute(plan);
fftw_destroy_plan(plan);
EXPECT_TRUE(true);
}
int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Linker errors:
1>------ Build started: Project: fftw3, Configuration: Debug x64 ------
2>------ Build started: Project: FFT_test (tests\FFT_test\FFT_test), Configuration: Debug x64 ------
2>tests.cpp
2>C:\Work\...\Task-2.2\src\tests\tests.cpp(5): fatal error C1083: Cannot open include file: 'fftw3.h': No such file or directory
2>Done building project "FFT_test.vcxproj" -- FAILED.
1> Creating library C:/Work/.../Task-2.2/output_64/fftw3/Debug/fftw3.lib and object C:/Work/.../Task-2.2/output_64/fftw3/Debug/fftw3.exp
1>conf.c.obj : error LNK2001: unresolved external symbol fftw_solvtab_dft_standard
1>conf.c.obj : error LNK2001: unresolved external symbol fftw_solvtab_rdft_r2cf
1>conf.c.obj : error LNK2001: unresolved external symbol fftw_solvtab_rdft_r2cb
1>conf.c.obj : error LNK2001: unresolved external symbol fftw_solvtab_rdft_r2r
1>C:\Work\...\Task-2.2\output_64\bin\Debug\fftw3.dll : fatal error LNK1120: 4 unresolved externals
1>Done building project "fftw3.vcxproj" -- FAILED.
========== Build: 0 succeeded, 2 failed, 8 up-to-date, 0 skipped ==========
conf.c.obj is inside the fftw3 library.
In your top-level CMake file, you dive into the src directory first, before adding the googletest and fftw3 sub-directories. So, when you reference the gtest_main and fftw3 targets in your src\tests\CMakeLists.txt file, they are undefined:
target_link_libraries(FFT_test PUBLIC FFT_lib)
# The targets linked here are not yet defined.
target_link_libraries(FFT_test PUBLIC gtest_main)
target_link_libraries(FFT_test PUBLIC fftw3)
You should re-order your top-level CMake file such that CMake can find the dependencies first, then add the src sub-directory:
add_subdirectory(googletest)
add_subdirectory(fftw3)
add_subdirectory(src)
You will also likely need to add the include directory for the fftw3 headers (path containing fftw3.h), with something like this:
add_executable(FFT_test ${SOURCES})
target_include_directories(FFT_test PRIVATE /path/to/fftw3-headers)

Cant build project using Boost CMake vcpkg date_time linking error

I'm trying to use boost::asio through cmake and vcpkg in my project and
everytime I touch something releated to date_time (even implicitly) I get some linking errors releated to gregorian calendar.
Someone knows why this isn't linking?
I'm new to CMake & vcpkg.
Host Environment
OS: Windows 10
Compiler: MSVC++ 14.23
To Reproduce
./vcpkg install Boost
cd $MyProjectDir
mkdir build
cd build
cmake -G "Visual Studio 16 2019" -A x64 ..
cmake --build .
problematic C++ code
#include <boost/asio.hpp>
int main() {
boost::asio::io_service service;
//boost::asio::deadline_timer timer(service); // this one causes error
}
My CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
set(CMAKE_TOOLCHAIN_FILE "C:/Repos/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
project(Backend)
find_package(Boost REQUIRED)
add_executable(Backend
"source/main.cpp"
)
target_link_libraries(Backend PRIVATE ${Boost_LIBRARIES})
target_include_directories(Backend PRIVATE ${Boost_INCLUDE_DIRS})
Failure logs
2>------ Build started: Project: Backend, Configuration: Debug x64 ------
2>Building Custom Rule C:/Repos/fridge/backend/CMakeLists.txt
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl boost::gregorian::greg_month::greg_month(unsigned short)" (__imp_??0greg_month#gregorian#boost##QEAA#G#Z) referenced in function "public: __cdecl boost::gregorian::date::date(enum boost::date_time::special_values)" (??0date#gregorian#boost##QEAA#W4special_values#date_time#2##Z)
2>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl boost::gregorian::greg_month::operator unsigned short(void)const " (__imp_??Bgreg_month#gregorian#boost##QEBAGXZ) referenced in function "public: static unsigned int __cdecl boost::date_time::gregorian_calendar_base<struct boost::date_time::year_month_day_base<class boost::gregorian::greg_year,class boost::gregorian::greg_month,class boost::gregorian::greg_day>,unsigned int>::day_number(struct boost::date_time::year_month_day_base<class boost::gregorian::greg_year,class boost::gregorian::greg_month,class boost::gregorian::greg_day> const &)" (?day_number#?$gregorian_calendar_base#U?$year_month_day_base#Vgreg_year#gregorian#boost##Vgreg_month#23#Vgreg_day#23##date_time#boost##I#date_time#boost##SAIAEBU?$year_month_day_base#Vgreg_year#gregorian#boost##Vgreg_month#23#Vgreg_day#23##23##Z)
2>C:\Repos\fridge\backend\build\Debug\Backend.exe : fatal error LNK1120: 2 unresolved externals
2>Done building project "Backend.vcxproj" -- FAILED.
fix was:
find_package(Boost REQUIRED COMPONENTS date_time)
Without asio because as Alan Birtles pointed out, asio is header only.