I've created a very basic c++ sample using the ZeroMQ library on my linux machine.
Building the project
To build the project, I decided to use CMake. Currently my CMakeLists.txt looks like this:
cmake_minimum_required (VERSION 3.9)
project(QSample)
# add ZMQ cmake files and find libzmq
set (ZeroMQ_DIR "/home/vtd/DEV_JOHANN/ZEROMQ/INSTALL_CMAKE/")
find_package(ZeroMQ REQUIRED)
# include also the zmq c++ wrapper
set(SOURCES qSample.cpp /home/vtd/DEV_JOHANN/ZEROMQ/INSTALL/include/zmq.hpp)
add_executable(QSample ${SOURCES})
# add the zmq include path
target_include_directories(QSample PRIVATE "/home/vtd/DEV_JOHANN/ZEROMQ/INSTALL/include")
# add the zmq libs
link_directories("/home/vtd/DEV_JOHANN/ZEROMQ/INSTALL/lib64")
# link the libs
TARGET_LINK_LIBRARIES(QSample libzmq)
# rule to copy the bin to the install folder
install (TARGETS QSample DESTINATION bin)
As you can see, I've changed the default zmq install paths. That's my first attempt to use CMake, so if you find any improvement to my CMakeLists.txt that would be great to know.
Generating the Makefiles through CMake works and if I run sudo make
it builds my project. After that I ran sudo make install
. Now there comes my problem:
Run program within build folder
If I run ./QSample
with in the specified CMake build folder, my application runs like expected.
Output of ldd ./QSample
:
linux-vdso.so.1 (0x00007fff78384000)
libzmq.so.5 => /home/vtd/DEV_JOHANN/ZEROMQ/INSTALL/lib64/libzmq.so.5 (0x00007efeb3f4a000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007efeb3cf9000)
librt.so.1 => /lib64/librt.so.1 (0x00007efeb3af1000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007efeb3965000)
libm.so.6 => /lib64/libm.so.6 (0x00007efeb35d2000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007efeb35b8000)
libc.so.6 => /lib64/libc.so.6 (0x00007efeb31f6000)
/lib64/ld-linux-x86-64.so.2 (0x00007efeb4026000)
Run program within installation folder
If I now switch into my specific installation folder, I can no longer run ./QSample
:
/QSample: error while loading shared libraries: libzmq.so.5: cannot open shared object file: No such file or directory
Output of ldd ./QSample
:
linux-vdso.so.1 (0x00007ffd975d4000)
libzmq.so.5 => not found
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fcac89d3000)
librt.so.1 => /lib64/librt.so.1 (0x00007fcac87cb000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fcac863f000)
libm.so.6 => /lib64/libm.so.6 (0x00007fcac82ac000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fcac8292000)
libc.so.6 => /lib64/libc.so.6 (0x00007fcac7ed0000)
/lib64/ld-linux-x86-64.so.2 (0x00007fcac8c26000)
Right now, it's not clear for me why I can't run it in the installation folder. What do I have to change in my CMake file?