spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

Building using MinGW-W64 fails with "'InetPton' was not declared in this scope"

Open i3abghany opened this issue 3 years ago • 3 comments

I use CMake to generate a ninja.build file, which I use to try to build the library. However, it fails with the following output:

nil@DESKTOP-0K54F8M MINGW64 /path/to/spdlog/build (v1.x)
$ ninja
[4/10] Building CXX object example/CMakeFiles/example.dir/example.cpp.obj
FAILED: example/CMakeFiles/example.dir/example.cpp.obj
C:\PROGRA~1\MINGW-~1\X86_64~1.0-P\mingw64\bin\C__~1.EXE  -DSPDLOG_COMPILED_LIB -I../include -O3 -DNDEBUG   -std=c++11 -MD -MT example/CMakeFiles/example.dir/example.cpp.obj -MF example\CMakeFiles\example.dir\example.cpp.obj.d -o example/CMakeFiles/example.dir/example.cpp.obj -c ../example/example.cpp 
In file included from ../include/spdlog/sinks/udp_sink.h:10,
                 from ../example/example.cpp:232:
../include/spdlog/details/udp_client-windows.h: In constructor 'spdlog::details::udp_client::udp_client(const string&, uint16_t)':
../include/spdlog/details/udp_client-windows.h:67:13: error: 'InetPton' was not declared in this scope
         if (InetPton(PF_INET, TEXT(host.c_str()), &addr_.sin_addr.s_addr) != 1)
             ^~~~~~~~
../include/spdlog/details/udp_client-windows.h:67:13: note: suggested alternative: 'inet_ntoa'
         if (InetPton(PF_INET, TEXT(host.c_str()), &addr_.sin_addr.s_addr) != 1)
             ^~~~~~~~
             inet_ntoa
[8/10] Building CXX object CMakeFiles/spdlog.dir/src/spdlog.cpp.obj
ninja: build stopped: subcommand failed.

Can someone please help me with how to debug/overcome this issue, please?

i3abghany avatar Dec 28 '21 20:12 i3abghany

Did you overcome this issue ?which version of ming2 are you using ?

gabime avatar Feb 12 '22 12:02 gabime

Under the Windows Platform, Open as Administrator the x64 Native Tools Command Prompt for VS 2022 command prompt window execution:

$ cd spdlog && mkdir build && cd build
$ cmake .. -G "Ninja" && ninja install

config CMakeLists.txt :

cmake_minimum_required(VERSION 3.21)
project(01-hello)

set(CMAKE_PREFIX_PATH C:/Program Files (x86))
find_package(spdlog REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE spdlog::spdlog spdlog::spdlog_header_only)

baagod avatar Feb 19 '22 13:02 baagod

Same issue here.

A simple workaround is to set -DSPDLOG_BUILD_EXAMPLE=OFF since this issue is in example codes

irvingzhang0512 avatar Apr 14 '22 01:04 irvingzhang0512