Problem Description
link
Regarding the solution to create a dynamic library by yourself in the ubuntu environment, an error occurs during the running phase, and it cannot be loaded into this library
dargon@dd:~/桌面/CSAPP/TestCode$ ./snooze
./snooze: error while loading shared libraries: libcsapp.so: cannot open shared object file: No such file or directory
-
Method 1: The current location of the library under export
At this time, because it will
libcsapp.so
be placed/usr/local/lib
under the directory, but it is added for the first time,link
when the program is in the stage, an error will occur.-
# 查看下变量 LD_LIBRARY_PATH dargon@dd:~/桌面/CSAPP/TestCode$ echo $LD_LIBRARY_PATH # 设置 LD_LIBRARY_PATH # Note: 第一次用,应该直接export,否则会报错:No command exist dargon@dd:~/桌面/CSAPP/TestCode$ export LD_LIBRARY_PATH=/usr/local/lib # 设置后,在进行查看一下 dargon@dd:~/桌面/CSAPP/TestCode$ echo $LD_LIBRARY_PATH /usr/local/lib # ./it can run my prog dargon@dd:~/桌面/CSAPP/TestCode$ ./snooze 10 ^CSlept for 2 of 10 escs.
-
Disadvantage, it is only valid for the current shell window, when restarting a window, it needs to be reconfigured
-
-
Method 2: Direct setting
ldconfig
-
# 直接进行配置一下 link dynamic library sudo ldconfig
-
Description of the function of this command
ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib).
-