CMake when FetchContent rabbitmq - c++

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

Related

Duplicate symbol QT5 mac m1

I'm trying to compile QT5 in C++ with Cmake on mac M1,
For now i can try with Fedora and it's working, but not on my mac.
This is my CMake File :
cmake_minimum_required(VERSION 3.0)
project(rtype)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CPACK_OUTPUT_FILE_PREFIX "pack")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/bin)
add_executable(${PROJECT_NAME} src/ecs/main.cpp)
# Adding QT5 dependencies
find_package(Qt5 COMPONENTS Core Network REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network)
# Adding SFML dependencies
find_package(SFML COMPONENTS system window graphics CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE sfml-system sfml-window sfml-graphics)
# Ajouter les includes pour SFML
target_include_directories(${PROJECT_NAME}
PRIVATE
${SFML_INCLUDE_DIRS})
# Setting up the CPack generator
set(CPACK_GENERATOR ZIP) # for macOS and Linux
set(CPACK_BUNDLE_NAME ${PROJECT_NAME})
set(CPACK_BUNDLE_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist)
set(CPACK_BUNDLE_ICON ${CMAKE_CURRENT_SOURCE_DIR}/icon.icns)
set(CPACK_GENERATOR NSIS) # for Windows
set(CPACK_PACKAGE_NAME "RType")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
include(CPack)
# Setting up the install targets
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin)
install(FILES README.md
DESTINATION .)
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/build.sh
DESTINATION .)
If I transform this :
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network)
to this :
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core)
or this :
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Network)
It's working perfectly, but with both its make this error :
[ 20%] Automatic MOC for target rtype
[ 20%] Built target rtype_autogen
[ 40%] Linking CXX executable /Users/ilaan/Documents/Epitech/Tek3/R-Type/client/bin/rtype
duplicate symbol 'qt_apple_sharedApplication()' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qcore_mac.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qcore_mac.o)
duplicate symbol 'qt_apple_check_os_version()' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qcore_mac.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qcore_mac.o)
duplicate symbol 'qt_apple_isApplicationExtension()' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qcore_mac.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qcore_mac.o)
[...]
duplicate symbol 'RunLoopDebugger::staticMetaObject' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qeventdispatcher_cf.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qeventdispatcher_cf.o)
duplicate symbol 'QEventDispatcherCoreFoundation::staticMetaObject' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qeventdispatcher_cf.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qeventdispatcher_cf.o)
duplicate symbol 'QEventDispatcherCoreFoundation::processEvents(QFlags<QEventLoop::ProcessEventsFlag>)' in:
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib/libQt5Core.a(qeventdispatcher_cf.o)
/Users/ilaan/Documents/Epitech/Tek3/R-Type/vcpkg/installed/arm64-osx/lib//libQt5Core.a(qeventdispatcher_cf.o)
ld: 94 duplicate symbols for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [/Users/ilaan/Documents/Epitech/Tek3/R-Type/client/bin/rtype] Error 1
make[1]: *** [CMakeFiles/rtype.dir/all] Error 2
make: *** [all] Error 2
I don't understand why, is not compatible with M1 Chipset ?
Thank you,
Ilan

Why does CMake fail to link my static library?

I am trying to link a static library which I have compiled from the assimp source to my executable CMake project so that it does not have to compile assimp as often since it's such a large library.
I compiled it using CMake with the following commands:
git clone https://github.com/assimp/assimp/
cd assimp
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=OFF ../CMakeLists.txt
cmake --build .
My project structure looks like this:
.
OpenGL
├── OpenGL
│ ├── res
│ ├── src
│ | └── (my .cpp and .h files)
│ └── CMakeLists.txt
├── libraries
│ └── glfw, glew, imgui...
└── CMakeLists.txt
I now copy assimp/include and assimp/build/bin/Debug/config.h to OpenGL/libraries/assimp/include,
then assimp/build/lib/Debug to OpenGL/libraries/assimp/lib
My CMakeLists.txt(s) look like this:
cmake_minimum_required(VERSION 3.8)
project(OpenGL LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_FIND_DEBUG_MODE)
if (NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
endif()
if (CMAKE_BUILD_TYPE STREQUAL Debug)
add_definitions(-DDEBUG) # preprocessor macro
else()
if (MSVC)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup") # if running on release mode remove the cmd prompt on windows
endif()
endif()
add_subdirectory(OpenGL)
add_subdirectory(libraries/glfw)
add_subdirectory(libraries/glew)
add_subdirectory(libraries/nativefiledialog)
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/libraries/glfw/include
${CMAKE_CURRENT_SOURCE_DIR}/libraries/glew/include
OpenGL/src
libraries
libraries/stb
libraries/assimp/include
libraries/nativefiledialog/src/include
)
and
cmake_minimum_required(VERSION 3.8)
file(GLOB_RECURSE OpenGL_sources *.cpp ../libraries/imgui/*.cpp ../libraries/stb/*.cpp)
add_executable(${PROJECT_NAME} ${OpenGL_sources} "src/engine/input/Key.cpp" "src/engine/input/Buttons.h" "src/engine/input/Button.h" "src/engine/input/Button.cpp" "src/engine/input/MouseButton.h" "src/engine/input/MouseButton.cpp" "src/engine/rendering/objects/Model.h" "src/engine/rendering/objects/Model.cpp")
target_link_libraries(${PROJECT_NAME} PUBLIC
glfw
libglew_static
${CMAKE_SOURCE_DIR}/libraries/assimp/lib/assimp-vc143-mtd.lib
nativefiledialog
)
or
cmake_minimum_required(VERSION 3.8)
add_library( assimp STATIC IMPORTED )
set_property( TARGET assimp PROPERTY IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libraries/assimp/lib/assimp-vc143-mtd.lib)
file(GLOB_RECURSE OpenGL_sources *.cpp ../libraries/imgui/*.cpp ../libraries/stb/*.cpp)
add_executable(${PROJECT_NAME} ${OpenGL_sources} "src/engine/input/Key.cpp" "src/engine/input/Buttons.h" "src/engine/input/Button.h" "src/engine/input/Button.cpp" "src/engine/input/MouseButton.h" "src/engine/input/MouseButton.cpp" "src/engine/rendering/objects/Model.h" "src/engine/rendering/objects/Model.cpp")
target_link_libraries(${PROJECT_NAME} PUBLIC
glfw
libglew_static
assimp
nativefiledialog
)
(Both configurations give the same error)
Running cmake .. from OpenGL/build successfully completes which I think means that CMake was able to find the assimp library.
Now when I run cmake --build . I am greeted with the following error.
assimp-vc143-mtd.lib(AssbinLoader.obj) : error LNK2019: unresolved external symbol uncompress referenced in function "public: virtual void __cdecl Assimp::AssbinImporter::InternReadFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,struct aiScene *,class Assimp::IOSystem *)" (?InternReadFile#AssbinImporter#Assimp##UEAAXAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##PEAUaiScene##PEAVIOSystem#2##Z) [F:\dev\cpp\OpenGL\build\OpenGL\OpenGL.vcxproj]
assimp-vc143-mtd.lib(Compression.obj) : error LNK2019: unresolved external symbol inflate referenced in function "public: unsigned __int64 __cdecl Assimp::Compression::decompress(void const *,unsigned __int64,class std::vector<char,class std::allocator<char> > &)" (?decompress#Compression#Assimp##QEAA_KPEBX_KAEAV?$vector#DV?$allocator#D#std###std###Z) [F:\dev\cpp\OpenGL\build\OpenGL\OpenGL.vcxproj]
etc...
I believe this means that the function bodies were not found which should be compiled within the .lib.
How do I successfully link the library?
These functions (uncompress and inflate) belong to the ZLIB library. Although assimp CMake links ZLIB in order to use it - which is enough to build assimp by itself, you have to link ZLIB directly to your executable as well in order to use it in your executable context.

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.

Linking error for client of rabbitmq-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)

Linker error compiling an executable which uses Boost.Thread linking to a static library using Boost.Thread

I have a static library called MyAwesomeLib. It is built with the CMakeLists.txt below
PROJECT(MyAwesomeLib)
find_package(OpenCV)
find_package(VTK REQUIRED)
find_package(OpenGL)
find_package(GLUT)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
FIND_PACKAGE(Boost COMPONENTS thread)
if(NOT Boost_FOUND)
message(SEND_ERROR "Cannot find Boost Thread")
endif(NOT Boost_FOUND)
link_directories (${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIR} ${GLUT_INCLUDE_DIR})
INCLUDE(${VTK_USE_FILE})
file(GLOB SRCS "*.cpp" "*.c")
file(GLOB HDRS "*.h")
add_library(MyAwesomeLib STATIC ${SRCS} ${HDRS})
target_link_libraries(MyAwesomeLib ${OpenCV_LIBS} ${Boost_LIBRARIES} ${GLUT_LIBRARY} ${OPENGL_LIBRARY})
Now I want to build MyAwesomeExecutable which needs symbols from MyAwesomeLib. Both the executable and the library uses Boost.Thread (thread_group and thread class).
PROJECT(MyAwesomeExecutable)
FIND_PACKAGE(OpenCV REQUIRED)
FIND_PACKAGE(VTK REQUIRED)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
FIND_PACKAGE(Boost COMPONENTS thread)
if(NOT Boost_FOUND)
message(SEND_ERROR "Cannot find Boost Thread")
endif(NOT Boost_FOUND)
link_directories (${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIR} ${GLUT_INCLUDE_DIR})
INCLUDE(${VTK_USE_FILE})
FILE(GLOB SRCS "*.cpp" "*.c")
FILE(GLOB HDRS "*.h")
ADD_EXECUTABLE(MyAwesomeExecutable ${SRCS} ${HDRS})
TARGET_LINK_LIBRARIES(MyAwesomeExecutable MyAwesomeLib ${Boost_LIBRARIES} ${GLUT_LIBRARY} ${OPENGL_LIBRARY} ${OpenCV_LIBS})
When I build MyAwesomeExecutable, Visual Studio 2010 build its dependency MyAwesomeLib automatically. MyAwesomeLib builds just fine. But building MyAwesomeExecutable gives the following linker errors:
2>MyAwesomeExecutable.obj : error LNK2019: unresolved external symbol "public: void __cdecl boost::thread::join(void)" (?join#thread#boost##QEAAXXZ) referenced in function "public: void __cdecl boost::thread_group::join_all(void)" (?join_all#thread_group#boost##QEAAXXZ)
2>MyAwesomeLib.lib(Face.obj) : error LNK2001: unresolved external symbol "public: void __cdecl boost::thread::join(void)" (?join#thread#boost##QEAAXXZ)
2>MyAwesomeExecutable.obj : error LNK2019: unresolved external symbol "public: __cdecl boost::thread::~thread(void)" (??1thread#boost##QEAA#XZ) referenced in function "public: void * __cdecl boost::thread::`scalar deleting destructor'(unsigned int)" (??_Gthread#boost##QEAAPEAXI#Z)
2>MyAwesomeLib.lib(Face.obj) : error LNK2001: unresolved external symbol "public: __cdecl boost::thread::~thread(void)" (??1thread#boost##QEAA#XZ)
2>MyAwesomeExecutable.obj : error LNK2019: unresolved external symbol "private: void __cdecl boost::thread::start_thread(void)" (?start_thread#thread#boost##AEAAXXZ) referenced in function "public: __cdecl boost::thread::thread<class boost::_bi::bind_t<void,void (__cdecl*)(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >),class boost::_bi::list1<class boost::_bi::value<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > >(class boost::_bi::bind_t<void,void (__cdecl*)(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >),class boost::_bi::list1<class boost::_bi::value<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > >,struct boost::thread::dummy *)" (??$?0V?$bind_t#XP6AXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###ZV?$list1#V?$value#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###_bi#boost###_bi#boost###_bi#boost###thread#boost##QEAA#V?$bind_t#XP6AXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###ZV?$list1#V?$value#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###_bi#boost###_bi#boost###_bi#1#PEAUdummy#01##Z)
2>MyAwesomeLib.lib(Face.obj) : error LNK2001: unresolved external symbol "private: void __cdecl boost::thread::start_thread(void)" (?start_thread#thread#boost##AEAAXXZ)
Static library is just a collection of object files. It can compile quite well, because it doesn't use undefined symbols. Several checks can be done to ensure that boost libraries is really linked with your library. Please, do it to provide some more information.
1.Using cmake print out values from Boost_LIBRARY_DIRS and Boost_INCLUDE_DIRSto check linked boost libraries.
2.Check link.txt file generated by cmake. This file is generated for each target like library or executable and on Linux it is placed under buildir/path/to/target/folder/CMakeFiles/targetName.dir/link.txt. link.txt contains compiler command to build and link executable. With it you can check, whether boost thread libraries are actually linked to your executable. In VS link.txt isn't generated, as said in the comment to this answer. Then you can check for linker command-line using VS itself.