如何更改从多个源文件编译的g++生成的Linux共享库的入口点
How to change the entry point of a g++ generated Linux shared library compiled from multiple source files?
今天,我读了一篇web博客文章《如何制作可执行共享库》。在本文中,它指出,如果在Linux命令提示符下键入:
gcc -shared service.c -o libservice.so -Wl,-soname,libservice.so -W1,-e lib_entry
然后是
./libservice.so, then we can directly executer the lib_entry function.
然而,当我运行类似的g++命令时:
g++ -shared one.cpp two.cpp three.cpp -o libservice.so -Wl,-soname,libservice.so -W1,-e lib_entry
其中lib_entry
是two.cpp
中定义的C
函数,我得到警告消息:
找不到入口点lib_entry点。
如何修复此警告消息,以便可以直接运行入口点lib_entry
?我应该附上C
函数foo
与extern "C"
链接的实现来解决这个问题吗?
这是我的答案:缺少include";bits/c++配置h";在Ubuntu中在32位上交叉编译64位程序时
sudo apt-get安装gcc-4.9-multilib g++-4.9-multilib
请忽略前面的答案。下面的答案测试成功。谢谢你的耐心。步骤1
#include <stdio.h>
#include <unistd.h>
#ifdef __LP64__
const char service_interp[] __attribute__((section(".interp"))) = "/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2";
#else
const char service_interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2";
#endif
void lib_service(void)
{
printf("This is a service of the shared libraryn");
} // lib_service
void lib_entry(void)
{
printf("Entry point of the service libraryn");
_exit(0);
}
步骤2。
vendor@clickit:~/Downloads/DataServerLib$ g++ -shared -fPIC -DLINUX -Wl,-soname,libdataserver.so -efunc -I /home/vendor/Downloads/waitForMultipleObjects -I /home/vendor/development/Test/Include DataServer.cpp DataServerLib.cpp DataTransferClient.cpp CWinEventHandle.cpp WinEvent.cpp -o libDataServer.so -lpthread -lrt
maryych@uwash.edu:~/Downloads/DataServerLib$ chmod 777 libDataServer.so
maryych@uwash.edu:~/Downloads/DataServerLib$ ./libDataServer.so
内部入口点测试仪1添加用户
相关文章:
- 在为LINUX创建共享库时,如何避免STL的私有/弱副本
- 共享库 (.so) 没有扩展名的 Linux 可执行文件之间的区别?
- Linux 可执行文件通过 dlopen 在emplace_back崩溃打开共享库
- Linux c++.在预加载的共享库中定义的基类的崩溃调用函数
- 如何在 Linux 中构建共享库时使未定义引用的链接器失败
- 在 Linux 上,在 C++ 程序中,如何找到已加载共享库的路径?
- 卸载自身的 Linux 共享库
- Linux 共享库链接错误(未定义的符号)
- 如何对 Linux 共享库进行签名?
- 正在从Visual Studio 2017创建Linux共享库
- Linux共享内存,带有C :分段故障
- Linux 共享库 init 和 deinit 也使用 c++ 静态初始值设定项
- Linux 共享内存只允许读取访问
- C/C++ Linux 共享库能否通过将磁盘上自己的文件覆盖到较新版本来自动更新
- 如何更改从多个源文件编译的g++生成的Linux共享库的入口点
- Linux共享库中全局变量的单个副本
- 在同一程序中使用Linux C++共享库和静态库
- 我可以用shmctl调整Linux共享内存的大小吗?
- linux共享库支持多线程应用程序回调
- Linux共享库加载两次