How to prevent CMake from installing .lib files - windows

I am cross-compiling a JNI DLL on Windows using MSVC + CMake and I noticed that it is producing a .lib file on install. I am using add_library(mylibname SHARED ...) and install(TARGETS mylibname DESTINATION ${CMAKE_INSTALL_LIBDIR}) to create and install the shared library. Is there a way to prevent this file from being installed as it is not needed for JNI libraries at runtime?

Related

CMake include libraries with executable

I am using CMake and trying to include libraries I use with the executable for distribution. One library I am using is boost for which I am using the statement
find_package(Boost REQUIRED thread filesystem)
This works fine, but I cannot redistribute to a computer where boost is not installed.
I then tried to use fetch_content but when cpack generates the installer, the library files built still aren't included.
set(BOOST_INCLUDE_LIBRARIES thread filesystem)
set(BOOST_ENABLE_CMAKE ON)
FetchContent_Declare(build_boost GIT_REPOSITORY https://github.com/boostorg/boost.git GIT_TAG boost-1.80.0)
FetchContent_GetProperties(build_boost)
if(NOT build_boost_POPULATED)
FetchContent_Populate(build_boost)
add_subdirectory(${build_boost_SOURCE_DIR} ${build_boost_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
How can I package the library files with the executable?

Library's CMake generates DLL. Application's CMake wants LIB

My library has minimal, straightforward CMake code with the pertinent lines
add_library(MyLib <sources>)
install(
TARGETS MyLib
LIBRARY DESTINATION ${destination}/lib
RUNTIME DESTINATION ${destination}/lib
COMPONENT Libraries)
install(
FILES mylib.h
DESTINATION ${destination}/include
COMPONENT Headers)
When executed under Windows, the system generates mylib.dll in ...\build\Release, and mylib.lib and mylib.exp (what's that?) in ...\build\lib\Release. It only installs mylib.dll.
My application has minimal, straightforward CMake code to search for my library:
find_path(MyLib_INCLUDE_DIR mylib.h)
find_library(MyLib_LIBRARIES NAMES MyLib)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MyLib DEFAULT_MSG MyLib_LIBRARIES MyLib_INCLUDE_DIR)
Which works under Linux, but under Windows results in
-- Could NOT find MyLib (missing: MyLib_LIBRARIES)
From experimentation I know that this error occurs whenever there is only a .DLL file, and no associated .LIB import library.
Shall I correct MyLib to install mylib.lib? How?
Or is it possible to modify my application so that it is satisfied with mylib.dll only? How?
Research done so far
This is not about static vs dynamic linking (DLL and LIB files - what and why?, cmake link against dll/lib): I want dynamic linking; if a .LIB file is required, it has nothing to do with static linking.
This link cmake : shared library : how to get the .lib name instead of .dll name? may be pertinent, but is not explicit enough. Two other questions CMake generated VS project expecting lib instead of dll, Linking dll/lib to a cmake project seem related, but have no answer.
Command install classifies .lib file for a shared library as ARCHIVE. This is explicitly stated in the documentation:
For DLL platforms (all Windows-based systems including Cygwin), the DLL import library is treated as an ARCHIVE target.
So you need to add ARCHIVE clause to install() for install .lib file as well:
install(
TARGETS MyLib
ARCHIVE DESTINATION ${destination}/lib
LIBRARY DESTINATION ${destination}/lib
RUNTIME DESTINATION ${destination}/bin
COMPONENT Libraries)
Not also, that RUNTIME DESTINATION is usually specified as bin, the same as destination for executables. This helps the executables on Windows to locate the shared libraries (.dll).

Build dynamic windows library (DLL) from libmcrypt with MinGW

I'm trying to build libmcrypt library to use it with my project. It happened so, that they do not provide any kind of assistance.
First I've faced a problem with -no-undefined flag for gcc which is not further supported. I've replaced -no-undefined with -Wl,-no-undefined in makefiles and it does the trick.
But anyway I'am having problems. Lib is builded in .a files. I can see them in my C:\MinGW\msys\1.0\local\lib folder (it is analogue for /usr/local/lib folder in MinGW). But I need .dll library, not static .a .
So: what else must I change in makefiles to make MinGW build dll with header and debug info for it?

How to generate .lib files with mingw toolchain?

I have installed MingW GCC 4.8.1 in my system. I am trying to build the LLVM source code( with some extra modification). Cmake 2.8.12 is used to generate the makefiles and visual studio solution files. I am able to build the LLVM source (Rel 3.4.2) with Visual Studio 2010 And is generating both lib and dll file. But with MingW I am not able generate .lib files by simply running Make all.
How to make MingW generate .lib file while building the project ?
Use CMAKE_GNUtoMS. Add -DCMAKE_GNUtoMS=ON to the build command. See this CMake issue. As result, a .lib file will be generated along with the .dll.a file.

linker error using qmake with boost thread in windows MSVC

I am using QtCreator on Windows with boost library. right now I am stuck with linking boost threading library against my Application.
In my C:\boost_1_47_0\bin.v2\libs\thread\build directory I see only msvc-10.0 no mingw So I need to choose MSVC2010 as My build configuration instead of mingw.
on compilation its reporting error: LNK1104: cannot open file 'libboost_thread-vc100-mt-gd-1_47.lib'
I can find There is boost_thread-vc100-mt-gd-1_47.lib here in libs directory but no libboost_thread-vc100-mt-gd-1_47.lib (check the extra lib on left)
in my .pro
win32:INCLUDEPATH += C:\boost\include\boost-1_47
win32:CONFIG(debug): LIBS += C:\boost_1_47_0\bin.v2\libs\thread\build\msvc-10.0\debug\threading-multi\boost_thread-vc100-mt-gd-1_47.lib

Resources