Skip to content

Commit da14258

Browse files
authored
Fix MinGW build issue on example (#2642)
* Fix MinGW build issue on example #2638 * Move the cmake change to example\CMakeLists.txt * Update CMakeLists.txt on the example
1 parent 927cc29 commit da14258

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ if(SPDLOG_SYSTEM_INCLUDES)
176176
set(SPDLOG_INCLUDES_LEVEL "SYSTEM")
177177
endif()
178178

179-
180179
target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB)
181180
target_include_directories(spdlog ${SPDLOG_INCLUDES_LEVEL} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>"
182181
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")

example/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ endif()
1212
# Example of using pre-compiled library
1313
# ---------------------------------------------------------------------------------------
1414
add_executable(example example.cpp)
15-
target_link_libraries(example PRIVATE spdlog::spdlog)
15+
target_link_libraries(example PRIVATE spdlog::spdlog $<$<BOOL:${MINGW}>:ws2_32>)
1616

1717
# ---------------------------------------------------------------------------------------
1818
# Example of using header-only library

include/spdlog/details/udp_client-windows.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
#include <stdio.h>
1616
#include <string>
1717

18-
#pragma comment(lib, "Ws2_32.lib")
19-
#pragma comment(lib, "Mswsock.lib")
20-
#pragma comment(lib, "AdvApi32.lib")
18+
#if defined(_MSC_VER)
19+
# pragma comment(lib, "Ws2_32.lib")
20+
# pragma comment(lib, "Mswsock.lib")
21+
# pragma comment(lib, "AdvApi32.lib")
22+
#endif
2123

2224
namespace spdlog {
2325
namespace details {
2426
class udp_client
2527
{
2628
static constexpr int TX_BUFFER_SIZE = 1024 * 10;
2729
SOCKET socket_ = INVALID_SOCKET;
28-
sockaddr_in addr_ = {0};
30+
sockaddr_in addr_ = {};
2931

3032
static void init_winsock_()
3133
{

0 commit comments

Comments
 (0)