我是CMAKE的初学者。下面是一个简单的cmake文件,在mingw环境窗口中效果很好。问题显然与target_link_libraries()我链接libwsock32.a的CMAKE函数有关。在Windows中,这行得通,我得到结果。
target_link_libraries()
但是,正如预期的那样,在Linux中,/usr/bin/ld将查找-lwsock32Linux OS上没有的遗嘱。
/usr/bin/ld
-lwsock32
我的问题是:如何指示CMAKE避免在Linux OS中链接wsock32库???
任何帮助将不胜感激。
我的简单CMake文件:
PROJECT(biourl) set (${PROJECT_NAME}_headers ./BioSocketAddress.h ./BioSocketBase.h ./BioSocketBuffer.h ./BioSocketCommon.h ./BioSocketListener.h ./BioSocketPrivate.h ./BioSocketStream.h ./BioUrl.h BioDatabase.h ) set (${PROJECT_NAME}_sources BioSocketAddress.C BioSocketBase.C BioSocketCommon.C BioSocketStream.C BioUrl.C BioDatabase.C ) add_library(${PROJECT_NAME} STATIC ${${PROJECT_NAME}_headers} ${${PROJECT_NAME}_sources} ) # linkers #find_library(ws NAMES wsock32 PATHS ${PROJECT_SOURCE_DIR} NO_SYSTEM_ENVIRONMENT_PATH NO_DEFAULT_PATH) target_link_libraries(${PROJECT_NAME} bioutils wsock32) install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib/archive )
采用
if (WIN32) #do something endif (WIN32)
要么
if (UNIX) #do something endif (UNIX)
if (MSVC) #do something endif (MSVC)
或类似
请参阅CMake有用变量 和CMake检查平台