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

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

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

Related

Crow microframework - CMake Error: The following variables are used in this project, but they are set to NOTFOUND

Here is the full error message:
Error CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
C:/Users/DELL/source/repos/CMakeProject1/CMakeProject1/CROW_INCLUDE_DIRS
used as include directory in directory C:/Users/DELL/source/repos/CMakeProject1/CMakeProject1 C:\Users\DELL\source\repos\CMakeProject1\ used as include directory in directory C
I am trying to use the Crow microframework but can't seem to make it work. I have downloaded the Crow package off of Github : https://github.com/ipkn/crow and used CMake to run a hello world from the Crow port. This is what I got in my .txt file
cmake_minimum_required (VERSION 3.8)
find_path(CROW_INCLUDE_DIRS "crow.h")
add_executable (CMakeProject1 "example_with_all.cpp" "crow_all.h")
target_include_directories(CMakeProject1 PRIVATE ${CROW_INCLUDE_DIRS})
My header file is crow_all.h which contains all the libraries and this is where the error is located. The compiler does not recognize all the "#include" used in this header file. I believed it would work because I had downloaded the entire Github repo and included it in my files.
My cpp file just includes the header file and does a Hello World.
I am a beginner at CMake, thank you for the help!
You should check out https://github.com/CrowCpp/Crow. It's an actively maintained version of the framework with a new build system (you should be able to just link it via CMake)
P.S. I suggest you use the master branch since it has quite a few improvements over the latest release.
Wow, crow's build is so broken that its own instructions fail on my system... it also hasn't been updated since 2017 (five years...). Assuming you still want to use it, I would just copy their amalgamated header, crow_all.h, into my source tree under, say, third_party/crow/crow_all.h and then write:
cmake_minimum_required(VERSION 3.22)
project(example)
add_executable(app "example_with_all.cpp")
target_include_directories(app PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/third_party/crow")

cmake + cpp: No such file or directory

I've I'm trying to build this "Hello World" wxWidgets example on Linux, using the following cmake script:
cmake_minimum_required (VERSION 2.6)
project (wxL)
find_package(wxWidgets 3.0.0 REQUIRED
COMPONENTS base core net xml html adv qa richtext
)
file(GLOB SOURCES "src/*.cpp")
add_executable(wxL ${SOURCES})
Building the project yields this error:
src/wxL.cpp:3:10: fatal error: wx/wxprec.h: No such file or directory
The file specified in the include, wx/wxprec.h can be found on disk at this location:
/usr/include/wx-3.0/wx/wxprec.h
Furthermore, another program that I have built from source includes the same file (also using cmake) and builds just fine.
So, how do I use cmake to tell the compiler that the file should be included from somewhere in the system directories?
I know I'm missing something basic, but I can't figure out what.
Although you've found the package, your executable does not know anything about it.
For the executable to compile correctly, it needs to find header files for your package together with the .so / .a files. Following example should get you started:
include_directories(${wxWidgets_INCLUDE_DIRS})
add_executable(wxL <add-source-files-here>)
target_link_libraries(wxL ${wxWidgets_LIBRARIES}) // links wxWidgets libraries to your executable
Please note that using glob is not a recommended way of adding source files to your project.

How to set up sub directory includes in CMake/CLion?

This is similar to Including directories in Clion, but after following the accepted answer there I made no progress.
I'm trying to edit a large OSS project in CLion. It does not use CMake, so CLion has generated a CMakeLists.txt file. When I open a source file, it is unable to resolve includes that use sub directories:
The file this screenshot is from is in the same "opto" subdirectory it is importing from. If I change the imports to not include "opto" it works fine, but I can't do that, since this is a major project and I'm just wanting to write a small patch:
$ find . -type f | wc -l
10532
I've added the file I'm importing directly to add_executable as suggested in the other answer:
# CMakeLists.txt
add_executable(hotspot
[lots of other files]
src/share/vm/opto/compile.hpp
)
And I've added the opto directory to include_directories as outlined in the second answer to the other question:
# CMakeLists.txt
include_directories(
src
src/share/vm/opto)
Neither is helping CLion resolve imports via the opto subdirectory.
What am I missing?
Using include_directories() must do, but you have to mention each sub_directory separately. Below i have included two directories in the same way where one of it is sub_directory.
The Header files have successfully been detected by CLion.

How to print/show included directories in CMakeList

I am trying to build a trivial proof of concept project using CMake, and I am rapidly getting tired of it - to the point that I think it may have been a better idea to handcraft my own damn Makefile.
I have a directory structure that looks something like this:
project:
/extproj
/src/file.cpp
/include/file1.h
My CMakeLists.txt file contains the following section, which I, having read the CMake documentation, rather naively believed, will be specifying the include directories for the project:
INCLUDE_DIRECTORIES (include/
extproj/sdk/math/linearalg/
extproj/sdk/math/nonlinearsolvers/
)
I am trying to build it using the following command
COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${ALL_SOURCES}
Where ${ALL_SOURCES} is a list variable that contains all the C++ files I need to compile. I have verified that this variable contains the correct files.
I can't however, for the life of me, work out what on earth is being passed to the compiler as the include directories.
I searched online, and so a post that recommended using get_directory_properties. I tried that and of course CMake immediately failed to generate the Makefile and complained:
Unknown CMake command "get_directory_properties".
When I create a Makefile and run make on it, the compiler barfs immediately, with the error message:
/path/to/project/src/file1.cpp:1:10: fatal error: 'file1.h' file not
found
Is there ANY WAY, I can find out what on earth is being used as the include paths being passed to my compiler?
I believe the correct way to compile the source files is using
add_executable(executableName ${SRCS}. Then the directories added using include_directories(...) get passed to the compiler automatically.
If you are using a custom command to compile you need to change your CMakeLists.txt file.
set(MY_INCLUDE_DIRS_FLAGS "-Iinclude/ -Iextproj/sdk/math/linearalg/ -Iextproj/sdk/mat/nonlinearsolvers/")
set(MY_COMPILE_COMMAND ${CMAKE_CXX_COMPILER} ${MY_INCLUDE_DIRS_FLAGS} ${CMAKE_CXX_FLAGS} ${ALL_SOURCES}

How to use itkvtkglue to use ITK with VTK?

I wanted to make the example which combines ITK with VTK called IO/ImageFileReader from wiki examples.
I downloaded itkvtkglue, extracted to a folder, configured with cmake and built with visual studio 2010.
but i can't use it when i try to configure the example given. Even though cmake finds the ItkVtkGlue_DIR by itself, it gives the error that he couldn't include the necessary files. Fails to include(${ItkVtkGlue_USE_FILE})
Should I somehow change the folders CMake looks for my ItkVtkGlue header files? Is there other way to use ITK & VTK together?
the error and file content are given below.
CMake Error at CMakeLists.txt:6 (include):
include could not find load file:
C:/Users/Emre
CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 2.6)
project(ImageFileReader)
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
add_executable(ImageFileReader ImageFileReader.cxx)
target_link_libraries(ImageFileReader
ItkVtkGlue ${VTK_LIBRARIES} ${ITK_LIBRARIES})
Thank you all for your help.
This is almost certainly one of the very common problems:
If the path to your tools contains a [space] character in it, then you must protect the file path from being split apart by encapsulating it in quotations "".
To be safe, you should always place file paths in quotations just incase one of your future collaborators tries to build on a path that has spaces in it.
You may also want to review:
http://www.vtk.org/Wiki/ITK/Examples#ItkVtkGlue