Today, I read the web blog article , How to make executable shared libraries. In this article it states that if one types at a Linux command prompt:
gcc -shared service.c -o libservice.so -Wl,-soname,libservice.so -W1,-e lib_entry
followed by
./libservice.so, then we can directly executer the lib_entry function.
However, when I run a similar g++ command:
g++ -shared one.cpp two.cpp three.cpp -o libservice.so -Wl,-soname,libservice.so -W1,-e lib_entry
where lib_entry
is a C
function defined in two.cpp
I get the warning message:
No entry point lib_entry point found.
How do I fix this warning message so I can directly run the entry point, lib_entry
? Should I enclose the implementation of the C
function foo
with extern "C"
linkage to resolve this problem?
This is my answer: Missing include "bits/c++config.h" when cross compiling 64 bit program on 32 bit in Ubuntu
sudo apt-get install gcc-4.9-multilib g++-4.9-multilib
Please disregard the previous answer. The answer below was tested successfully. Thank you for your patience. Step 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 library\n");
} // lib_service
void lib_entry(void)
{
printf("Entry point of the service library\n");
_exit(0);
}
Step 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
Inside entry point tester 1 AddUser
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.