Why does not ldd output the libraries that I have linked when generating the executable file?

只谈情不闲聊 提交于 2020-12-06 05:42:20

问题


I have linked the project with ATLAS library, -llapack -lf77blas -lcblas -latlas -lgfortran, and it could compile successfully. But when I use the ldd command to view the dependency libraries, the output is as follows:

    ubuntu@ubuntu-desktop:~/Desktop/qt_output$ldd test_atlas
linux-vdso.so.1 =>  (0x00007fffa99ff000)
libopencv_core.so.2.4 => /home/ubuntu/Documents/3rdparty/lib/libopencv_core.so.2.4 (0x00007fe0577d7000)
libgfortran.so.3 => /usr/lib/x86_64-linux-gnu/libgfortran.so.3 (0x00007fe057477000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fe057173000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe056e76000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fe056c60000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe0568a1000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fe056689000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fe05646c000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fe056264000)
libcudart.so.5.0 => /usr/local/cuda-5.0/lib64/libcudart.so.5.0 (0x00007fe056009000)
libnpp.so.5.0 => /usr/local/cuda-5.0/lib64/libnpp.so.5.0 (0x00007fe05051c000)
libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007fe0502e0000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe057e31000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe0500db000)
    ubuntu@ubuntu-desktop:~/Desktop/qt_output$ 

Why does not it have the libatlas.so or libatlas.a? Thanks.

UPDATED:

   CFLAGS        = -pipe -O2 -Wall -W $(DEFINES)
   CXXFLAGS      = -pipe -std=c++0x -O2 -Wall -W $(DEFINES)
   INCPATH       = -I../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/linux-g++ -I../../Documents/3rdparty/include -I../../Documents/3rdparty/include/opencv2 -I../../Documents/3rdparty/include/opencv -I/usr/local/MATLAB/R2013a/extern/include  -I.
    LINK          = g++
    LFLAGS        = -Wl,-O1 -Wl,-rpath,/home/ubuntu/QtSDK/Desktop/Qt/4.8.1/gcc/lib
    LIBS          = $(SUBLIBS)   -L/home/ubuntu/Documents/3rdparty/lib/ -lopencv_core -lopencv_imgproc -lopencv_highgui -llapack -lf77blas -lcblas -latlas -lgfortran 

回答1:


The linker is looking for .so files in the system library paths and user defined paths (like /home/ubuntu/Documents/3rdparty/lib/). These .so files are defined by -l argument. For example the -latlas corresponds to libatlas.so.

If libatlas.so file is not found then the linker will look for libatlas.a. This file is basically an ar (archive) file of all .o library files. The .a files are treated same as objects and are included inside the executable. So they do not appear in ldd command.

If you use -static argument with g++ then you force the linker to look only for .a files and then ldd returns nothing.

In order to make dynamic link to libatlas.so you need to add this file in /home/ubuntu/Documents/3rdparty/lib/.



来源:https://stackoverflow.com/questions/19171908/why-does-not-ldd-output-the-libraries-that-i-have-linked-when-generating-the-exe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!