How to install static libz.dll.a,libssl.dll.a, etc on MinGW/MSYS2? - windows

I'm getting this on my project's linking process (compiles with cmake):
[100%] Linking CXX executable roosek2.exe
/usr/lib/gcc/x86_64-pc-msys/9.1.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lC:/msys64/mingw64/lib/libz.dll.a
/usr/lib/gcc/x86_64-pc-msys/9.1.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lC:/msys64/mingw64/lib/libssl.dll.a
/usr/lib/gcc/x86_64-pc-msys/9.1.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lC:/msys64/mingw64/lib/libcrypto.dll.a
/usr/lib/gcc/x86_64-pc-msys/9.1.0/../../../../x86_64-pc-msys/bin/ld: cannot find -lC:/msys64/mingw64/lib/libzstd.dll.a
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/roosek2.dir/build.make:578: roosek2.exe] Error 1
make[2]: Leaving directory '/home/LZ/roosek_ocr2'
make[1]: *** [CMakeFiles/Makefile2:77: CMakeFiles/roosek2.dir/all] Error 2
make[1]: Leaving directory '/home/LZ/roosek_ocr2'
make: *** [Makefile:84: all] Error 2
This happens when I compile with static qt5 from MSYS2 in MinGW shell. Here's my CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(roosek2 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
add_executable(roosek2
main.cpp
qml.qrc
ImageStream.cpp
YuvUtils.cpp
CameraView.cpp
)
add_library(ctmedia_codec MODULE IMPORTED)
add_library(ctstream MODULE IMPORTED)
add_library(maincore MODULE IMPORTED)
#link_directories(${CMAKE_CURRENT_SOURCE_DIR}/win_bin/lib/x64)
set_target_properties(ctmedia_codec PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/win_bin/lib/x64/CTMedia.lib)
set_target_properties(ctstream PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/win_bin/lib/x64/CTStream.lib)
set_target_properties(maincore PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/win_bin/lib/x64/WPMainCore.lib)
include_directories("include")
target_compile_definitions(roosek2
PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
target_link_libraries(roosek2
PRIVATE Qt5::Core Qt5::Quick ctmedia_codec ctstream maincore)
How do I install these libraries? Why are they being required? Do I really need them?

Install these packages:
For X86_64 (64 bit):
pacman -S mingw-w64-x86_64-openssl mingw-w64-x86_64-zlib mingw-w64-x86_64-zstd
For X86 (32 bit):
pacman -S mingw-w64-i686-openssl mingw-w64-i686-zlib mingw-w64-i686-zstd

Related

class_loader failed when cross compiling ROS Melodic for aarch64 with buildroot

I'm trying to cross compiling ROS Melodic for aarch64 on raspberry pi 3 with toolchain that created by buildroot.
I followed the document http://wiki.ros.org/ROS/CrossCompiling/RaspberryPi/Cross-Compile%20ROS%20for%20the%20RaspberryPi, the source of ROS I try to build comes from:
rosinstall_generator ros_comm --rosdistro melodic --deps --tar > melodic-ros_comm.rosinstall
wstool init -j8 src melodic-ros_comm.rosinstall
And I got the error messages like these:
[100%] Linking CXX shared library /home/developer/ros_pi/ros_catkin_ws/devel_isolated/class_loader/lib/libclass_loader.so
/home/developer/buildroot-2020.02.1/output/host/lib/gcc/aarch64-buildroot-linux-gnu/8.4.0/../../../../aarch64-buildroot-linux-gnu/bin/ld: /home/developer/buildroot-2020.02.1/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/lib/libboost_thread.so: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
CMakeFiles/class_loader.dir/build.make:180: recipe for target '/home/developer/ros_pi/ros_catkin_ws/devel_isolated/class_loader/lib/libclass_loader.so' failed
make[2]: *** [/home/developer/ros_pi/ros_catkin_ws/devel_isolated/class_loader/lib/libclass_loader.so] Error 1
CMakeFiles/Makefile2:195: recipe for target 'CMakeFiles/class_loader.dir/all' failed
make[1]: *** [CMakeFiles/class_loader.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
<== Failed to process package 'class_loader':
Command '['/home/developer/ros_pi/ros_catkin_ws/install_isolated/env.sh', 'make', '-j8', '-l8']' returned non-zero exit status 2
Reproduce this error by running:
==> cd /home/developer/ros_pi/ros_catkin_ws/build_isolated/class_loader && /home/developer/ros_pi/ros_catkin_ws/install_isolated/env.sh make -j8 -l8
Command failed, exiting.
This is my toolchain.cmake:
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_LIBRARY_ARCHITECTURE aarch64)
set( CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "/home/developer/buildroot-2020.02.1/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/include/")
set( CMAKE_C_COMPILER aarch64-linux-gcc)
set( CMAKE_CXX_COMPILER aarch64-linux-g++)
set(CMAKE_FIND_ROOT_PATH "/home/developer/buildroot-2020.02.1/output/host/aarch64-buildroot-linux-gnu/sysroot")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
include_directories(/home/developer/buildroot-2020.02.1/output/host/aarch64-buildroot-linux-gnu/sysroot/usr/include/)
I guess the problem comes from boost?
The version of boost which I used is 1.65.1
All the steps I tried is contained in Dockerfile as link as below:
https://github.com/i-am-neet/cc-ros/blob/master/Dockerfile
Thank you for your patience

undefined reference to symbol '_ZN5boost6system15system_categoryEv' /

this is not the first time I meet this error, but [previous solution][1] doesn't make sense.
[100%] Linking CXX executable ../bin/qttest
/usr/bin/x86_64-linux-gnu-ld: CMakeFiles/qttest.dir/src/main.cpp.o:
undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols:
DSO missing from command line collect2: error: ld returned 1 exit
status
here is my cmakelists
cmake_minimum_required(VERSION 2.4.6)
set(OpenCV_DIR "/usr/local/opencv-2.4.9/share/OpenCV")
include_directories("/usr/local/opencv-2.4.9/include")
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
find_package(Qt4 COMPONENTS QtCore QtGui)
find_package(OpenCV 2.4.9 REQUIRED)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
rosbuild_init()
rosbuild_genmsg()
find_package(Boost COMPONENTS system REQUIRED)
set(qt_srcs
src/mainwindow.cpp
src/listnerthr.cpp
src/ros_thr.cpp
src/CreatDataBuffer.cpp
src/CreatBuffer.cpp
src/pid_controller.cpp
src/low_pass_filter.cpp
src/plot_publisher.cpp)
set(qt_hdrs
src/mainwindow.h
src/listnerthr.h
src/ros_thr.h
src/CreatDataBuffer.h
src/HelperFunctions.h
src/CreatBuffer.h
src/pid_controller.h
src/low_pass_filter.h
src/plot_publisher.h)
qt4_automoc(${qt_srcs})
QT4_WRAP_CPP(qt_moc_srcs ${qt_hdrs})
QT4_WRAP_UI(uis_h src/mainwindow.ui)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
rosbuild_add_executable(qttest src/main.cpp
${uis_h} ${qt_srcs} ${qt_moc_srcs})
target_link_libraries(qttest ${QT_LIBRARIES}${Boost_LIBARAIES }${OpenCV_LIBARAIES})
any clues would be appreciated.
I got another problem after changing the cmakelists
*** No rule to make target '/usr/lib/x86_64-linux-gnu/libboost_system.so/usr/lib/x86_64-linux-gnu/libboost_system.so', needed by '../bin/qttest'. Stop. CMakeFiles/Makefile2:425: recipe for target 'CMakeFiles/qttest.dir/all' failed –
You should pass boost libraries to the target_link_libraries command. The smallest change to your file will be as follows:
target_link_libraries(qttest ${QT_LIBRARIES} ${LIBS})
But since you are using find_package for Boost and you do not actually use your LIBS variable anywhere, you should stick with something like this:
find_package(Boost COMPONENTS system REQUIRED)
...
target_link_libraries(qttest ${QT_LIBRARIES} ${OpenCV_LIBS} ${Boost_LIBRARIES})
And remove LIBS altogether.

Create a shared lib that depends on dlib using Cmake

I'm building a shared library in C++ that depends on dlib using CMake.
While it has been possible for me to build and install a shared dlib using make and make install, so far I haven't figured out the way to link to this shared dlib library.
The examples of usage given in the DLib website always link to a static library.
This is what I have so far:
cmake_minimum_required(VERSION 2.8.12)
project(face_align)
set(CMAKE_CXX_STANDARD 11)
find_package(dlib)
add_library(face_align SHARED src/mylib.cpp)
target_link_libraries(face_align dlib::dlib)
The linker complains like so:
/usr/bin/ld: cannot find -ldlib::dlib
collect2: error: ld returned 1 exit status
CMakeFiles/face_align.dir/build.make:94: recipe for target 'libface_align.so' failed
make[2]: *** [libface_align.so] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/face_align.dir/all' failed
make[1]: *** [CMakeFiles/face_align.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
If I remove the SHARED from
add_library(face_align SHARED src/mylib.cpp) the project builds successfully. This makes me think that dlib:dlib is pointing to the static library. I see that there is a dlib:dlib_shared but no success linking to this one either.
The answer seems to be (1) linking to dlib as a static library (2) making the code linking to dlib position independent:
cmake_minimum_required(VERSION 2.8.12)
project(face_align)
set(CMAKE_CXX_STANDARD 11)
# Unfortunately, this only links dlib as static library
add_subdirectory(libs/dlib dlib_build)
add_library(face_align SHARED src/mylib.cpp)
# This makes the target position independent, allowing to link an static library to a dynamic one.
set_target_properties(face_align PROPERTIES POSITION_INDEPENDENT_CODE ON) # This made it work
# Link Dlib
target_link_libraries(face_align dlib::dlib)
EDIT:
Also, in Linux (I haven't tested this in other S.O.s) CMake does some magic and, after installing dlib library in shared mode:
$ cd $DLIB
$ mkdir build && cd build
$ cmake ../dlib
$ make && make install
Is possible to simply add the library using target_link_libraries as follows:
cmake_minimum_required(VERSION 2.8.12)
project(face_align)
set(CMAKE_CXX_STANDARD 11)
add_library(face_align SHARED src/mylib.cpp)
# Link Dlib
target_link_libraries(face_align dlib)
Then, in your code, include headers as follows:
#include <dlib/your_dlib_header_here.h>

How to link jemalloc shared library using cmake

I'm trying to link the jemalloc library into my application at build time using it as a generic implementation. According to https://github.com/jemalloc/jemalloc/wiki/Getting-Started the linking flags to use are:
-L`jemalloc-config --libdir` -Wl,-rpath,`jemalloc-config --libdir` -ljemalloc `jemalloc-config --libs`
So I did the following CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.12.2)
project(widget)
include_directories(include)
file(GLOB SOURCES "src/*.cpp")
add_executable(widget ${SOURCES})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L`jemalloc-config --libdir` -Wl,-rpath,`jemalloc-config --libdir` -ljemalloc `jemalloc-config --libs`")
But when I do make I get the following errors:
Linking CXX executable widget
c++: error: `jemalloc-config: No such file or directory
c++: error: unrecognized command line option ‘--libdir`’
c++: error: unrecognized command line option ‘--libdir`’
c++: error: unrecognized command line option ‘--libs`’
make[2]: *** [widget] Error 1
make[1]: *** [CMakeFiles/widget.dir/all] Error 2
For future generations, as this still comes up as one of the first links on Google.
Jemalloc comes with pkg-config setup, which can be used like this:
find_package(PkgConfig REQUIRED)
pkg_check_modules (JEMALLOC jemalloc)
pkg_search_module(JEMALLOC REQUIRED jemalloc)
include_directories(${JEMALLOC_INCLUDE_DIRS})
target_link_libraries(your_target_name ${JEMALLOC_LIBRARIES})
execute_process() command is your friend. Use it to run jemalloc-config executable and then put its output into CMake variables.
find you root_dir of jemalloc. Mine is /Users/lion/homebrew/Cellar/jemalloc/5.2.1_1/lib/
(I install jemalloc by brew on macOS)
link (soft link) all its lib to your local lib ln -s /Users/lion/homebrew/Cellar/jemalloc/5.2.1_1/lib/* /usr/local/lib
Then it works!

Trying to add Boost libraries to Cmake.txt (Clion Ide)

I see a lot of questions that are similar to this though not the same.
I'm having an issue getting boost recognized/working in Cmake using Clion I've tried a handful of ways including the incboost template included with Clion, moving on.
Cmake version 3.4
Boost version 1.60.0
find_package(Boost)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
endif()
That's the auto generated incboost I mentioned above, This produces no results.
Second attempt is the following
set(Boost_Dir "C:\\Program Files (x86)\\boost_1_60_0\\")
find_package(Boost 1.60.0 COMPONENTS filesystem)
include_directories(${Boost_Dir})
CmakeFiles\Svp.dir/objects.a(main.cpp.obj):
In function`_static_initialization_and_destruction_0':
C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:221: undefined reference
to `boost::system::generic_category()'
C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:222: undefined
reference to `boost::system::generic_category()'
C:/PROGRA~2/BOOST_~1/boost/system/error_code.hpp:223: undefined
reference to `boost::system::system_category()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [Svp.exe] Error 1
CMakeFiles\Svp.dir\build.make:96: recipe for target 'Svp.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/Svp.dir/all' failed
mingw32-make.exe[2]: *** [CMakeFiles/Svp.dir/all] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/Svp.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/Svp.dir/rule] Error 2
Makefile:117: recipe for target 'Svp' failed
mingw32-make.exe: *** [Svp] Error 2
My Third attempt produces this
set(boost "C:\\Program Files (x86)\\boost_1_60_0\\boost\\")
INCLUDE_DIRECTORIES(${boost})
fatal error: boost/filesystem/config.hpp: No such file or directory
# include <boost/filesystem/config.hpp>
^
compilation terminated.
mingw32-make.exe[3]: *** [CMakeFiles/Svp.dir/main.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/Svp.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/Svp.dir/rule] Error 2
And finally the solutions given here How do you add boost libraries in CMakeLists.txt have not changed my error output.
here's how I use it, in a portable way, in my projects:
if (WIN32)
set(BOOST_ROOT "C:/Program Files (x86)/boost_1_60_0/")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREAD ON)
include_directories(${BOOST_ROOT})
link_directories(${BOOST_ROOT}/stage/lib) # add this before add_executable()
endif()
# Here call your add_executable method
# add_executable(TARGET_NAME ... )
if(NOT MSVC)
find_package(Boost REQUIRED COMPONENTS date_time filesystem wserialization system serialization thread regex)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(TARGET_NAME ${Boost_LIBRARIES})
endif()
endif()
You sometime need to specify the Boost_USE_STATIC_LIBS and Boost_USE_MULTITHREAD variables to help find_package find boost.
Also please specify the correct path to boost library with set(BOOST_ROOT, $path). Moreover, specify the boost packages you need in find_package. For instance
find_package(Boost REQUIRED COMPONENTS date_time filesystem thread regex)
if you only need the date_time filesystem thread regex packages
let me know if it works or not for you.

Resources