1

I've got the following file tree:

   C:.
    │   CMakeLists.txt
    │   myLibraryHeader.h
    │   test.c
    │
    └───myLib
        ├───win32
        │       myLibrary.a
        │
        └───win64
                myLibrary.a

And the following CMake file:

cmake_minimum_required(VERSION 2.8)
project(myProject)
link_directories(myLib/win32) 
add_executable(main test.c)
target_link_libraries(main myLib/win32/myLibrary.a)

myLibraryHeader.h is the header, while the implementation is in the .a files. test.c uses functions declared in myLibraryHeader.h.

However, when I try to compile it using VS2013 compiler, I get this error:

Error   1   error LNK1104: cannot open file 'myLibrary.lib'

What is the reason that VS is looking for a .lib file instead of .a file?

How can it be fixed?

Nave Tseva
  • 371
  • 2
  • 6
  • 16
  • According to the [doc](https://cmake.org/cmake/help/latest/command/target_link_libraries.html) I believe that you either need a full path or maybe just the library name. Can you amend the library path to be `${CMAKE_CURRENT_SOURCE_DIR}/myLib/win32/myLibrary.a`? How does that do? – compor Sep 05 '18 at 08:43
  • Static library `myLibrary.a` is NOT "win32" library. This library is for *Linux*, because it has `.a` extension . The library also could be used by MinGW compiler/linker. But on *Windows* a static library should have `.lib` extension (so, they should be built by the appropriate compiler). This is why VS2013 looks for `.lib` file. – Tsyvarev Sep 05 '18 at 11:53
  • @Tsyvarev, given the library has only C stuff (public) the `a` library should be consumed by MSVC w/o any problem. – ixSci Sep 08 '18 at 09:04
  • @ixSci: First time here that MSVC may work with `.a` libraries. Aren't libraries for MSVC should have format different from `.a` one? – Tsyvarev Sep 08 '18 at 09:10
  • @Tsyvarev, they have to be compatible to support C-interface. I can't say about difference in the format but MSVC has no choice but support it. – ixSci Sep 08 '18 at 10:42

1 Answers1

0

Try the following:

unset(CMAKE_LINK_LIBRARY_SUFFIX)

But note that it will affect any lib name passed to the target_link_libraries from this line on.

ixSci
  • 13,100
  • 5
  • 45
  • 79