JSH
JSH

Reputation: 59

C++ CMake Linking error: LNK1181: Cannot open input file "x.lib"

Despite to the fact that I am quite new to C++ I got this project to expose one old C++ library to Python for which I am using Pybind11 and CMake. The C++ library links against a file here called "problematic_old_library.lib". This .lib is living on a server drive. When binding the C++ code to Python a CMakeList.txt - file is needed including includes and links to required files. Since I have no experience of CMake I am quite sure that I am doing something wrong here.

Here is my CMakeList.txt file for reference (names of the files are changed):

cmake_minimum_required(VERSION 2.8.12)
project(some_project) 

add_subdirectory(pybind11)

pybind11_add_module(some_project
    src/main.cpp
    src/mapping.cpp
    )
link_directories(Z:/folder/subfolder/lib)
TARGET_LINK_LIBRARIES(some_project PUBLIC problematic_old_library)

Now, this CMakeList.txt is included in a folder named "some_project". Inside folder "some_project" are "CMakeList.txt" and folder named "src"( with the two files listed above).The file "mapping.cpp" uses the 3rd party library named "problematic_old_library. However, This produces 1 fatal error.

LINK: fatal error LNK1181: cannot open input file 'problematic_old_library.lib'

What is causing this?

I tried to search for help from the documentation. However, I find it very confusing to understand the ${something} notation when using CMake. What I would like to have is "hard coded" example of how to link against an old library preferably without the ${something} notation if possible.

///////////////

For further reference below is a appended version of my CMakeList.txt file that includes all the combinations for paths leading to this problematic "x.lib" file:

make_minimum_required(VERSION 2.8.12)
project(blpbind)

add_subdirectory(pybind11)


pybind11_add_module(blpbind src/main.cpp

    src/mapping.cpp

    )

# Cannot open
#link_directories("Z:\\blpapi_cpp\\lib")

# Cannot open
#link_directories("Z://blpapi_cpp//lib")

# Cannot open
#link_directories(Z:\\blpapi_cpp\\lib)

#  Cannot open
#link_directories(Z://blpapi_cpp//lib)

# Cannot open
#link_directories(Z:/blpapi_cpp/lib)

# Cannot open
#link_directories(Z:/ILMAPI/lib/PROD/LATEST/src/alphalib/blpbind/src/lib)

# Cannot open
#link_directories("Z:/ILMAPI/lib/PROD/LATEST/src/alphalib/blpbind/src/lib")

# Cannot open
link_directories(Z://ILMAPI//lib//PROD//LATEST//src//alphalib//blpbind//src//lib)

# Cannot open
link_directories("Z://ILMAPI//lib//PROD//LATEST//src//alphalib//blpbind//src//lib")


 TARGET_LINK_LIBRARIES(blpbind PUBLIC blpapi3_32)

I tried all the following and I confirm that I still receive exactly the same error in each case.

Br and thanks

Upvotes: 0

Views: 5849

Answers (1)

Dardan Iljazi
Dardan Iljazi

Reputation: 827

It seems that the LNK1181 error appears when the file can't be found (https://msdn.microsoft.com/en-us/library/y6b12xkc.aspx)

Maybe your path contains spaces in it. When you use spaces, you have to escape them like with \

The path Z:/folder with space name/subfolder/lib

Should be like this:

Z:/folder\ with\ space\ name/subfolder/lib

In other side, it seems that you can use double \ to the folder like this:

"Z:\\folder with space name\\subfolder\\lib"

Try both to see results

Upvotes: 1

Related Questions