0

I am kind of a newbie in C++. I am struggling using a third party library. I am sorry if this sounds obvious to many. However, if anyone could help that would be nice.

Thanks a lot

I am trying to compile and use a third party library called XXXX. So I followed the instruction to compile XXXX. It compiled fine using Visual Studio 2019 16.5.

The library file is in:

  • D:\Workspace\XXXX\build\src\C++\Debug\XXXXd.lib
  • D:\Workspace\XXXX\build\src\C++\Debug\XXXX.lib (I copied the dedbug file without the suffix "d"...)
  • D:\Workspace\XXXX\build\src\C++\Release\XXXX.lib

I am getting the following error:

NMAKE : fatal error U1073: don't know how to make 'XXXX.lib'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.

Using this cmake file

cmake_minimum_required(VERSION 3.10)
project(Ahahah)

set(CMAKE_CXX_STANDARD 17)
add_compile_definitions(HAVE_STD_UNIQUE_PTR=1)
add_compile_definitions(_HAS_AUTO_PTR_ETC=1)


INCLUDE_DIRECTORIES(D:/Workspace/XXXX/include)
link_directories(D:/Workspace/XXXX/build/src/C++/Debug)
add_library(XXXX STATIC D:/Workspace/XXXX/build/src/C++/Debug)
set_target_properties(XXXX PROPERTIES LINKER_LANGUAGE CXX)

add_executable(Ahahah
        Ahahah/src/Common/CommandLineConsole/Command.cpp
        Ahahah/src/Common/CommandLineConsole/Command.h)
target_link_libraries(Ahahah PUBLIC XXXX)

If I comment out add_library and set_target_properties, with this cmake:

cmake_minimum_required(VERSION 3.10)
project(Ahahah)

set(CMAKE_CXX_STANDARD 17)
add_compile_definitions(HAVE_STD_UNIQUE_PTR=1)
add_compile_definitions(_HAS_AUTO_PTR_ETC=1)


INCLUDE_DIRECTORIES(D:/Workspace/XXXX/include)
link_directories(D:/Workspace/XXXX/build/src/C++/Debug)


add_executable(Ahahah
        Ahahah/src/Common/CommandLineConsole/Command.cpp
        Ahahah/src/Common/CommandLineConsole/Command.h)
target_link_libraries(Ahahah PUBLIC XXXX)

I get this error

lgo2.exe : fatal error LNK1120: 23 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2019.3.5\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.
Mr_Kaz
  • 73
  • 1
  • 9
  • There are already a few solutions on Stack Overflow for importing and using external libraries in CMake. This [response](https://stackoverflow.com/a/10550334/3987854) might be most helpful to you. Also, it looks like you are using the `add_library()` command incorrectly. This command does not accept **paths** as an argument, only *source* files (e.g. `.cpp`). See the linked answer for how you can use `add_library()` for the XXXX library. – Kevin May 02 '20 at 17:19
  • The second part of my question mention what you propose. I was not using add_libary, I simply used INCLUDE_DIRECTORIES(D:/Workspace/XXXX/include) link_directories(D:/Workspace/XXXX/build/src/C++/Debug) target_link_libraries(Ahahah PUBLIC XXXX) I edited my initial question so it is clearer. – Mr_Kaz May 02 '20 at 17:27
  • A simple tutorial: https://www.youtube.com/watch?v=or1dAmUO8k0 (Static linking) , https://www.youtube.com/watch?v=pLy69V2F_8M (Dynamic linking) – Adam May 02 '20 at 17:46
  • Neither of these CMake files is uses `add_library()` as suggested in the linked response. The use of `link_directories()` is unnecessary (and discouraged by CMake documentation itself) when using `add_library(XXXX STATIC IMPORTED)` and setting the `IMPORTED_LOCATION` property as the other solution proposes. – Kevin May 02 '20 at 18:03
  • 2
    The error `fatal error LNK1120: 23 unresolved externals` means that linker has **found** and **processed** all libraries you give to it (including `XXXX` library from `target_link_libraries(Ahahah PUBLIC XXXX)` call). But you still has some symbols not defined. The problem is not in the `CMakeLists.txt` but **somewhere else**. – Tsyvarev May 02 '20 at 20:20
  • Thanks a lot your answers. It was indeed an issue with other libraries that were missing. I was importing a library that was linking with OpenSSL in windows. I had symbols missing. Therefore, I simply added libcrypto libssl ws2_32 to XXXXX inside the target_libraries() Thanks a lot – Mr_Kaz May 09 '20 at 15:12

0 Answers0