CMake how to find linked absolute path for *.lib files - c++

I have a CMake project which is runnable, with part of the code
target_link_libraries(exec PRIVATE d3d11.lib dwmapi.lib d3dcompiler.lib)
How do I know which *.lib (from where) is used?
Is it possible to print the path?
Thanks
Try to find the path to CMake link library, specifically *.lib files.

Related

CMake Link Static .lib files

I have a library in: C:\vcpkg\installer\x86-windows-static\lib and I would like to link it via this absolute path.
The cmake file resides elsewhere, it is for an executable program (not a library).
Is it possible to link for example example_lib.lib from this absolute path?
Everywhere I read it's just about building the library, but I just want to link on it, .lib specifically.
The CMakes target_link_libraries() allows you to specify the library via an absolute path.

How to use a library created using Bazel

I'm relatively new to Cpp and I was trying to build a simple app for a quant project. I've managed to use Bazel to convert a chunk of my code to a library residing in the bazel-bin directory in my repository as a .lib file.
However, I'm not able to figure out how to use this library in my main.cpp which is outside the library I created. Could anyone help with this? Thanks!
I'm not sure if I understood your question correctly, but I think, there is a .lib file that you want to use it (technically speaking, you need to link that .lib file to another app, or accessing in the main.cpp).
Ok, it depends on what build-system you use.
for MSVC:
Add the full path of the .lib file to Project Property Page -> Linker -> Input -> Additional Dependencies.
and don't forget to add the path to .h files (include path) to Project Property Page -> C/C++ -> General -> Additional Include Directories
It's the same for other build systems, you have to link it to the final built item.
for gcc there is a -L flag for the lib and a -h flag to point to the include directories.
in CMake:
include_directories(
path/to/include/directory
)
link_directories(
path/to/directory/that/lib/lives
)
add_executable(main main.cpp)
target_link_libraries(main lib_file_name)
if the lib file name is lib_file_name.lib you should not include .lib (just for cmake)

CMake and MinGW-w64 include paths

I have a C++ project that needs to be built with CMake and MinGW-W64.
Some libraries (such as zlib, libpng) are in: C:\Dev\mingw64-5.3.0\x86_64-w64-mingw32\
So I use : -DCMAKE_PREFIX_PATH="C:\Dev\mingw64-5.3.0\x86_64-w64-mingw32"
But, I get a compilation error because the following header is outdated and miss important symbols:
C:\Dev\mingw64-5.3.0\x86_64-w64-mingw32\include\float.h
If I add a compiler flag to search into the proper include directory for float.h:
-DCMAKE_CXX_FLAGS="-isystem C:/Dev/mingw64-5.3.0/lib/gcc/x86_64-w64-mingw32/5.3.0/include"
Then, this does not work, since CMake will add this folder after its generated includes_CXX.rsp
How can I handle this issue? Is there a way to enforce header search path priority?
You could also add the include location(s) to environment variable C_INCLUDE_PATH and CPLUS_INCLUDE_PATH.
To locate the libraries you can do the same for the lib with the LIBRARY_PATH environment variable.
For DLL and EXE files you may even need to add the bin path to PATH.

CMake can not find boost libs

I am trying to build C++ progect uses boost and Cmake, but I have a problem with some libs
I already added paths to "Environment Variables"
And even added boost folder to "Path"
But it doesn't work. May somebody give an advice!?
Your BOOST_LIBRARYDIR should be a path to folder containing build boost libraries (typically something like boost_1_64\stage\lib filled with .dll and .lib files) while boost_1_64\libs contains source code. You need to build boost first and then set BOOST_LIBRARYDIR accordingly.

Compiling libraries with CMake under Cygwin

I have been trying to compile TinyXML using CMake as a sort of mini project, trying to learn CMake. As an addition I am trying to make it compile into a dynamic library and install itself so it works.
So far I have managed to get it to compile and install BUT it compiles into a .dll and a .dll.a and the only way to get it to work is to have it install into both /bin and /lib, which makes it install both files in both folders. This setup works but I'm guessing the .dll should be in /bin and the .dll.a should be in /lib. Is this some sort of Cygwin-specific problem or am I doing something wrong?
The .dll is the runtime library file, which must be present on the target system on run time (and be in $PATH there). The .dll.a file is the import library for the .dll, which must be present on the compiling machine at link time. You need to distribute the .dll file to the places where the program should run, and both .dll and .dll.a to places where the library is used to link other programs. you don't need the .dll.a file on the machines running the program only.
When you don't want to create a shared library, you can tell this to cmake with the static keyword in the add_library command:
add_library(mylib STATIC foo.c bar.cpp)
This way there will no shared library created, but the code from the library will be added by the linker into the final executable file.
What you need is to specify a destination for each type of file.
The .dll is considered a RUNTIME library and the .a is an ARCHIVE. Just in case, for other platforms, you probably want the LIBRARY entry (for .so files).
install( TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)