0

For some weird reason I have to add the libraries paths explicitly, (see #1) and cannot do what I think would be simpler and more robust (#2). (it complains on the first nng.lib that I cannot find that file)

I am using CMAKE 3.12 and VS2017 on Windows 10.

1)

set(NNG_LIB ${CMAKE_CURRENT_SOURCE_DIR}/nng/lib/nng.lib)
set(FB_LIB ${CMAKE_CURRENT_SOURCE_DIR}/flatbuffers/lib/flatbuffers.lib)
set(WinsockLib "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17134.0/um/x64/mswsock.lib")
set(ws "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17134.0/um/x64/ws2_32.lib")
set(adv "C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17134.0/um/x64/advapi32.lib")

target_link_libraries(${PROJECT_NAME} ${NNG_LIB} ${FB_LIB} ${WinsockLib} ${ws} ${adv})

2)

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/WinSDK
    ${CMAKE_CURRENT_SOURCE_DIR}/nng/lib 
    ${CMAKE_CURRENT_SOURCE_DIR}/flatbuffers/lib)

target_link_libraries(${PROJECT_NAME} nng.lib flatbuffers.lib mswsock.lib ws2_32.lib advapi32.lib )
Dr.YSG
  • 7,171
  • 22
  • 81
  • 139
  • Possible duplicate of [Cmake cannot find library using "link\_directories"](https://stackoverflow.com/questions/31438916/cmake-cannot-find-library-using-link-directories) – Tsyvarev Jul 17 '18 at 19:28
  • The [first answer](https://stackoverflow.com/a/31471772/3440745) to the referenced question says that the first way is the preferrable. The [second answer](https://stackoverflow.com/a/40554704/3440745) describes why your second approach doesn't work: you should call `link_directories` **before** creating the executable/library target. – Tsyvarev Jul 17 '18 at 19:30
  • But it is before the target_link_libraries – Dr.YSG Jul 17 '18 at 22:16
  • From the `link_directories` [documentation](https://cmake.org/cmake/help/v3.9/command/link_directories.html): "The command will apply only to targets **created** after it is called." – Tsyvarev Jul 17 '18 at 22:48

0 Answers0