运行可执行文件时,CLion找不到共享库 [英] CLion can't find shared library when running an executable
问题描述
我正在做一个项目。到目前为止,我一直在使用一个简单的编辑器以及我自己的Makefile来构建它。不过,我想切换到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.
根据这个问题,您可以告诉CMake运行您的Makefile。所以我的 CMake.txt
看起来像这样:
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.
在我的项目中,我使用 cppunit 1.13
进行测试。但是找不到共享库:
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
指向
echo $LD_LIBRARY_PATH
/usr/local/lib
并且 / usr / local / lib
包含库:
ls /usr/local/lib/
libcppunit-1.13.so.0@ libcppunit-1.13.so.0.0.2* libcppunit.a libcppunit.la* libcppunit.so@ pkgconfig/
ldd
显示如下:
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)
那么CLion为什么找不到它?如果我从控制台运行二进制文件,一切都会正常。
So why can't CLion find it? Everything works if I run the binary from console.
推荐答案
作为 oLen 正确指出,通过GUI启动时,CLion似乎没有以我的用户身份启动(在我的情况下为Gnome)。我不知道它是从什么开始的,但是在 / etc / profile
LD_LIBRARY_PATH = / usr / local / lib >,然后重新启动(或重新配置资源),它就可以工作-简而言之,没有为运行CLion的任何用户设置该变量。
As oLen correctly pointed out, CLion doesn't seem to start as my user when launched via the GUI (Gnome in my case). I don't know as what it starts, but setting LD_LIBRARY_PATH=/usr/local/lib
in /etc/profile
and rebooting (or resourcing) it makes it work - in a nutshell the variable wasn't set for whatever user is running CLion.
另一种方法是运行->编辑配置-> (选择您的应用程序)->环境变量
。在这里,您可以手动将 LD_LIBRARY_PATH
设置为您需要的任何值,在我的情况下为 / usr / local / lib
。
Another way is Run -> Edit Configurations -> (select your application) -> Environment variables
. Here you can manually set LD_LIBRARY_PATH
to whatever you need, in my case to /usr/local/lib
.
这篇关于运行可执行文件时,CLion找不到共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!