如何使用 .so 文件而不在命令行中运行 g++
我创建了一个名为 car.so 的 .so 文件。我想在 test.cc 代码中测试和使用这个库。在命令行中我想编译:g++ test.cc -o test.我不想也链接(包含)库 car.so。
怎么做呢?
我的 test.cc 代码如下所示:
void* handle = dlopen("/home/v3/car.so", RTLD_LAZY);
Car* (*create)();
void (*destroy)(Car*);
create = (Car* (*)())dlsym(handle, "create_object");
destroy = (void (*)(Car*))dlsym(handle, "destroy_object");
Car* carr = (Car*)create();
carr->brake();
destroy( carr );
我还想问一下是否可以在一个 .so 文件中包含 3 个 .so 文件。
编辑:
我正在 Ubuntu/Linux 上工作
I've created a .so file called car.so. I would like to test and work with this library in a test.cc code . In the command line i would like to compile: g++ test.cc -o test. I don't want to also link (include) the library car.so.
How to do that?
My test.cc code looks like this:
void* handle = dlopen("/home/v3/car.so", RTLD_LAZY);
Car* (*create)();
void (*destroy)(Car*);
create = (Car* (*)())dlsym(handle, "create_object");
destroy = (void (*)(Car*))dlsym(handle, "destroy_object");
Car* carr = (Car*)create();
carr->brake();
destroy( carr );
I would also like to ask if it's possible to include 3 .so file in a single .so file.
edit:
I am working on Ubuntu/Linux
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,您应该在(应用程序)/ test.cc 中包含 .so 库的 .h 文件,然后通过链接该 .so 文件和 来编译该 test.cc 文件。使用生成的二进制文件。
我认为这个链接真的会对你有帮助..
http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
in General you should include .h file of your .so library in your (application)/ test.cc then compile that test.cc file by linking that .so file & use generated binaray.
i think this link will realy help you..
http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html