Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLion can't find shared library when running an executable

Tags:

c++

cmake

clion

I am working on a project. I've been using a simple editor so far and my own Makefile to build it. I would like to switch to CLion, though.

According to this question you can tell CMake to run your Makefile. So my CMake.txt looks like this:

cmake_minimum_required(VERSION 3.6)
project(rekotrans_testbed_simulator)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

add_custom_target(rekotrans_testbed_simulator COMMAND make -C ${rekotrans_testbed_simulator_SOURCE_DIR} CLION_EXE_DIR=${PROJECT_BINARY_DIR})

It builds fine. I also set the working directory and pointed at the correct executable.

In my project I test using cppunit 1.13. However it can't find the shared library:

/home/kunterbunt/dev/comnets/git-repository/rekotrans-testbed-simulator/rekotrans-testbed-simulator-tests: error while loading shared libraries: libcppunit-1.13.so.0: cannot open shared object file: No such file or directory

LD_LIBRARY_PATH points to

echo $LD_LIBRARY_PATH 

/usr/local/lib

and /usr/local/lib contains the library:

ls /usr/local/lib/

libcppunit-1.13.so.0@  libcppunit-1.13.so.0.0.2*  libcppunit.a  libcppunit.la*  libcppunit.so@  pkgconfig/

ldd shows this:

ldd /home/kunterbunt/dev/comnets/git-repository/rekotrans-testbed-simulator/rekotrans-testbed-simulator-tests

linux-vdso.so.1 (0x00007ffc257e8000)
libboost_thread.so.1.63.0 => /usr/lib/libboost_thread.so.1.63.0 (0x00007f1c73254000)
libboost_system.so.1.63.0 => /usr/lib/libboost_system.so.1.63.0 (0x00007f1c73050000)
libboost_date_time.so.1.63.0 => /usr/lib/libboost_date_time.so.1.63.0 (0x00007f1c72e3f000)
libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f1c72c22000)
libboost_program_options.so.1.63.0 => /usr/lib/libboost_program_options.so.1.63.0 (0x00007f1c729a4000)
libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f1c727a0000)
libcppunit-1.13.so.0 => /usr/local/lib/libcppunit-1.13.so.0 (0x00007f1c72563000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f1c721db000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007f1c71ed7000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f1c71cc0000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007f1c71922000)
librt.so.1 => /usr/lib/librt.so.1 (0x00007f1c7171a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1c7347c000)

So why can't CLion find it? Everything works if I run the binary from console.

like image 412
kunterbunt Avatar asked Feb 05 '23 04:02

kunterbunt


1 Answers

Have a look at How to set the environmental variable LD_LIBRARY_PATH in linux:

If you add your custom library path to the LD configuration, then CLion will find your libraries automatically and you don't have to add them to the run configurations.

On Ubuntu/Debian, you can configure LD by creating a new .conf file

sudo nano /etc/ld.so.conf.d/myLocalLibs.conf

that simply contains the path to your libraries: /usr/local/lib. Finally, call

sudo ldconfig

to update the LD configuration.

Note that on some systems (Ubuntu/Debian) you cannot set the LD_LIBRARY_PATH in /etc/profile or /etc/environment:

Since Ubuntu 9.04 Jaunty Jackalope, LD_LIBRARY_PATH cannot be set in $HOME/.profile, /etc/profile, nor /etc/environment files. You must use /etc/ld.so.conf.d/*.conf configuration files. See Launchpad bug #366728 for more information. (help.ubuntu.com)

like image 187
Joe M. Avatar answered Feb 07 '23 17:02

Joe M.