I want to import spdlog in my project using CMake. And I use VS Code. But my code doesn't work well. I think I don't have any problem in my code because I copy and paste all professor's code. I think that it is simple setting error, but I don't know the solution.
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
set(PROJECT_NAME cmake_project_example)
set(CMAKE_CXX_STANDARD 17)
project(${PROJECT_NAME})
add_executable(${PROJECT_NAME} src/main.cpp)
include(ExternalProject)
set(DEP_INSTALL_DIR ${PROJECT_BINARY_DIR}/install)
set(DEP_INCLUDE_DIR ${DEP_INSTALL_DIR}/include)
set(DEP_LIB_DIR ${DEP_INSTALL_DIR}/lib)
ExternalProject_Add(
dep-spdlog
GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
GIT_TAG "v1.x"
GIT_SHALLOW 1
UPDATE_COMMAND ""
PATCH_COMMAND ""
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${DEP_INSTALL_DIR}
TEST_COMMAND ""
)
set(DEP_LIST ${DEP_LIST} dep-spdlog)
set(DEP_LIBS ${DEP_LIBS} spdlog$<$<CONFIG:Debug>:d>)
target_include_directories(${PROJECT_NAME} PUBLIC ${DEP_INCLUDE_DIR})
target_link_directories(${PROJECT_NAME} PUBLIC ${DEP_LIB_DIR})
target_link_libraries(${PROJECT_NAME} PUBLIC ${DEP_LIBS})
add_dependencies(${PROJECT_NAME} ${DEP_LIST})
main.cpp
#include <spdlog/spdlog.h>
int main(int argc, const char** argv) {
SPDLOG_INFO("Hello, world!");
return 0;
}
Heres the output:
build Output
[proc] Executing command: D:\Program\CMake\bin\cmake.EXE --build d:/Project/real_cmake/build --config Debug --target all -j 26 --
[build] [ 9%] Performing build step for 'dep-spdlog'
[build] [ 80%] Built target spdlog
[build] [ 90%] Building CXX object example/CMakeFiles/example.dir/example.cpp.obj
[build] In file included from D:/Project/real_cmake/build/dep-spdlog-prefix/src/dep-spdlog/include/spdlog/sinks/udp_sink.h:10,
[build] from D:\Project\real_cmake\build\dep-spdlog-prefix\src\dep-spdlog\example\example.cpp:243:
[build] D:/Project/real_cmake/build/dep-spdlog-prefix/src/dep-spdlog/include/spdlog/details/udp_client-windows.h: In constructor 'spdlog::details::udp_client::udp_client(const string&, uint16_t)':
# **[build] D:/Project/real_cmake/build/dep-spdlog-prefix/src/dep-spdlog/include/spdlog/details/udp_client-windows.h:67:13: error: 'InetPtonA' was not declared in this scope <<<<<< I think this error is critical
# **[build] if (InetPtonA(PF_INET, host.c_str(), &addr_.sin_addr.s_addr) != 1)
[build] ^~~~~~~~~
[build] D:/Project/real_cmake/build/dep-spdlog-prefix/src/dep-spdlog/include/spdlog/details/udp_client-windows.h:67:13: note: suggested alternative: 'GetPropA'
[build] if (InetPtonA(PF_INET, host.c_str(), &addr_.sin_addr.s_addr) != 1)
[build] ^~~~~~~~~
[build] GetPropA
[build] mingw32-make.exe[5]: *** [example\CMakeFiles\example.dir\build.make:76: example/CMakeFiles/example.dir/example.cpp.obj] Error 1
[build] mingw32-make.exe[4]: *** [CMakeFiles\Makefile2:125: example/CMakeFiles/example.dir/all] Error 2
[build] mingw32-make.exe[3]: *** [Makefile:155: all] Error 2
[build] mingw32-make.exe[2]: *** [CMakeFiles\dep-spdlog.dir\build.make:86: dep-spdlog-prefix/src/dep-spdlog-stamp/dep-spdlog-build] Error 2
[build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:110: CMakeFiles/dep-spdlog.dir/all] Error 2
[build] mingw32-make.exe: *** [Makefile:90: all] Error 2
[proc] The command: D:\Program\CMake\bin\cmake.EXE --build d:/Project/real_cmake/build --config Debug --target all -j 26 -- exited with code: 2
[build] Build finished with exit code 2
I tried searching the error on internet, but I can't find any information for this problem. I don't have any knowledge about CMake and spdlog.