LDD可执行OUPUT中没有动态加载库
Absence of dynamic loaded libraries in ldd executable ouput
为什么当您给出LDD可执行名称时,动态加载库不出现?这是真的吗?因为我找不到时找不到。可能是由于动态加载和动态链接。
请帮助我解决这个问题,让我知道您是否需要任何其他细节。
输出如下。
ldd example6
linux-vdso.so.1 => (0x00007ffe63369000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f56a2676000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f56a2372000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f56a1fa9000)
/lib64/ld-linux-x86-64.so.2 (0x00007f56a287a000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f56a1ca3000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f56a1a8d000)
我只能看到libdl.so ...但是我的可执行文件示例6取决于libtriangle.so,它是为某些测试而创建的。
如果您在没有dlopen命令的情况下访问共享库,我可以在可执行文件中找到.so详细信息,因为它是静态加载和动态链接,我感到。
程序的结构
在此处可执行,Main致电共享库,libtriangle.so。共享库,三角形。
末端存在makefile
man.so使用livingbeing.hpp,man.cpp和man.cpp使用pthread apis.man.so so依赖于-lpthread
三角形。三角形。
可执行文件,main取决于三角形。主acccess三角形。因此使用dlopen,dlsym函数。
ldconfig也用于/usr/usr/local/lib/mydir
中的.so文件请找到以下文件。
livingbeing.hpp
#ifndef LIVINGBEING_HPP
#define LIVINGBEING_HPP
#include <iostream>
using namespace std;
class livingbeing {
protected:
double side_length_;
public:
livingbeing()
: side_length_(0) {}
virtual ~livingbeing() {}
void set_length(double side_length) {
side_length_ = side_length;
}
virtual void eat() = 0;
};
typedef livingbeing* get_instance_t();
typedef void destroy_instance_t(livingbeing*);
#endif
man.cpp
#include "livingbeing.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *print_message_function( void *ptr );
class man : public livingbeing {
public:
man()
{
cout<<"man constructorn";
}
~man()
{
cout<<"man destructorn";
}
virtual void eat() {
cout<<"man eatingn";
pthread_t thread1, thread2;
int iret1;
/* Create independent threads each of which will execute function */
iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) NULL);
pthread_join( thread1, NULL);
}
};
void *print_message_function( void *ptr )
{
cout<<"hello thread1 created";
}
extern "C" livingbeing * get_instance()
{
return new man;
}
extern "C" void destroy_instance(livingbeing *lb)
{
delete lb;
}
triangle.cpp
#include "polygon.hpp"
#include "livingbeing.hpp"
#include <cmath>
#include <dlfcn.h>
//#include <iostream>
class triangle : public polygon {
public:
virtual double area() const {
// load the triangle library
void* man = dlopen("/usr/local/lib/ramu/libman.so", RTLD_LAZY);
if (!man) {
cerr << "Cannot load library: " << dlerror() << 'n';
return 1;
}
// reset errors
dlerror();
// load the symbols
get_instance_t* get_instance_man = (get_instance_t*) dlsym(man, "get_instance");
const char* dlsym_error = dlerror();
if (dlsym_error) {
cerr << "Cannot load symbol create: " << dlsym_error << 'n';
return 1;
}
destroy_instance_t* destroy_instance_man = (destroy_instance_t*) dlsym(man, "destroy_instance");
dlsym_error = dlerror();
if (dlsym_error) {
cerr << "Cannot load symbol destroy: " << dlsym_error << 'n';
return 1;
}
// create an instance of the class
livingbeing* living = get_instance_man();
// use the class
living->set_length(7);
cout << "The livingbeing is: ";
living->eat();
cout<<"n";
// destroy the class
destroy_instance_man(living);
// unload the triangle library
dlclose(man);
return side_length_ * side_length_ * sqrt(3) / 2;
}
};
// the class factories
extern "C" polygon* create() {
return new triangle;
}
extern "C" void destroy(polygon* p) {
delete p;
}
main.cpp
#include "polygon.hpp"
#include <iostream>
#include <dlfcn.h>
int main() {
using std::cout;
using std::cerr;
// load the triangle library
// void* triangle = dlopen("./triangle.so", RTLD_LAZY);
void* triangle = dlopen("/usr/local/lib/rakesh/libtriangle.so", RTLD_LAZY);
if (!triangle) {
cerr << "Cannot load library: " << dlerror() << 'n';
return 1;
}
// reset errors
dlerror();
// load the symbols
create_t* create_triangle = (create_t*) dlsym(triangle, "create");
const char* dlsym_error = dlerror();
if (dlsym_error) {
cerr << "Cannot load symbol create: " << dlsym_error << 'n';
return 1;
}
destroy_t* destroy_triangle = (destroy_t*) dlsym(triangle, "destroy");
dlsym_error = dlerror();
if (dlsym_error) {
cerr << "Cannot load symbol destroy: " << dlsym_error << 'n';
return 1;
}
// create an instance of the class
polygon* poly = create_triangle();
// use the class
poly->set_side_length(7);
cout << "The area is: " << poly->area() << 'n';
// destroy the class
destroy_triangle(poly);
// unload the triangle library
dlclose(triangle);
makefile
example6: main.cpp triangle
$(CXX) $(CXXFLAGS) main.cpp -o example6 -L/usr/local/lib/roh -ltriangle -ldl
triangle: man triangle.cpp polygon.hpp
$(CXX) $(CXXFLAGS) -shared -fPIC triangle.cpp -o libtriangle.so
man: man.cpp livingbeing.hpp
$(CXX) $(CXXFLAGS) -shared -fPIC -o man.so man.cpp -lpthread
clean:
rm -f example6 *.so *.o
.PHONY: clean
在其导入表中具有libtriangle
符号的意义上,可执行的main
不依赖于libtriangle
。ldd
不知道使用dlopen
在运行时加载的库,因为它不运行或分析代码。它只查看符号表。请注意,即使您在构建可执行文件时明确链接libtriangle
也没有效果。仅如果可执行文件具有一些未解决的符号,则链接器才会真正链接库,但是如果main
可执行文件,则没有。
相关文章:
- 系统.将数组移交给c#中动态加载的c++DLL时发生AccessViolationException
- 在 Linux 平台的 C++ 中动态加载 DLL
- 在Qt C++单元测试中动态加载QQuickWindow而不是QQuickWidget
- 从动态加载的 dll 内部调用C++函数
- C/C++函数动态加载器(helper)
- 从动态加载的库中记录日志
- 如何将LLDB附加到C# .NET进程并调试动态加载的macOS捆绑包?
- 如何动态加载和调用具有特定于库的类型作为函数参数的符号
- OpenGL 中的动态加载着色器毫无意义吗?
- 使用动态加载库时静态变量为空
- 在动态加载的位置无关的可执行文件中分离错误
- ASAN 检测与动态加载库共享的类的 vtable 的 ODR 违规
- 运行时动态加载库时出错"unresolved external symbol"
- 使用dlopen动态加载共享库
- LDD可执行OUPUT中没有动态加载库
- 调试Android Studio中动态加载的本机库
- C++ 动态加载 DLL 错误
- 动态加载库和运行时误解的显式链接
- 通过在C 中动态加载的LIB分配的基础级指针上调用删除的安全性
- mbed uvisor 动态加载二进制文件