0

I am trying to add the -lWs2_32 compiler flag for my CMake configuration. I have tried using both add_compile_options(-lWs2_32) and set(CMAKE_CXX_FLAGS -lWs2_32)

The flag is necessary for the HTTPRequest.hpp library.

Directory structure:

project
└───include
│   └───chessgame
│       │   chess.cc
│       │   chess.h
│   └───HTTPRequest
│       │   HTTPRequest.hpp
│   └───nlohmann
│       │   json.hpp
└───src
    │   ...

CMakeLists.txt:

cmake_minimum_required(VERSION 3.20.1) 

project(chessengine C CXX)

set(HEADERS
    src/constants.hpp
    src/consoleapp.hpp
    src/opening.hpp
    src/middlegame.hpp
    src/endgame.hpp
    src/engine.hpp
)
set(SOURCES
    src/consoleapp.cpp
    src/opening.cpp
    src/middlegame.cpp
    src/endgame.cpp
    src/engine.cpp
    src/main.cpp
)

# Neither of these work
add_compile_options(-lWs2_32)
set(CMAKE_CXX_FLAGS -lWs2_32)

add_executable(engine ${HEADERS} ${SOURCES})

add_subdirectory(include)

target_link_libraries(engine json chess httprequest)

CMakeLists in include directory:

add_library(chess chessgame/chess.cc chessgame/chess.h)
add_library(httprequest INTERFACE HTTPRequest)
add_library(json INTERFACE nlohmann)
lennertcl
  • 93
  • 6
  • `Ws2_32` is a link option / library to link. Should be added with `target_link_libraries` – drescherjm Apr 24 '21 at 18:16
  • Thank you! Problem solved by changing `target_link_libraries(engine json chess httprequest)` to `target_link_libraries(engine Ws2_32 json chess httprequest)` – lennertcl Apr 24 '21 at 18:20

0 Answers0