The dynamic library I'm building needs to depend on ws2_32.lib, but I don't know how to do it in cmake accordingly

Viewed 9

I intend to write a cross-platform tinyhttp server, but programming in a windows environment makes it a bit difficult for a newcomer like me.Here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.2)

project(MYHTTP_SHARED_LIB)

include_directories(${CMAKE_SOURCE_DIR}/inc)

if(WIN32)
    set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})
    add_library(win_tinyfunction SHARED ${CMAKE_SOURCE_DIR}/src/win_tinyfunction.cpp)
    install(TARGETS win_tinyfunction LIBRARY DESTINATION dll)
    target_link_directories(win_tinyfuncion ws2_32)
elseif(UNIX)
    set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR})
    add_library(linux_tinyfunction SHARED ${CMAKE_SOURCE_DIR}/src/linux_tinyfunction.cpp)
    install(TARGETS linux_tinyfunction LIBRARY DESTINATION so)
endif()

Mabe it is the probelm:

target_link_directories(win_tinyfuncion ws2_32)

and the cmake error is:

 Cannot specify link libraries for target "win_tinyfuncion" which is not built by this project.

How to correct it, please!

1 Answers

Sorry, it was just my carelessness that caused this problem, some names were mistyped, maybe I need to take a break

Related