1

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?

Rachid K.
  • 4,490
  • 3
  • 11
  • 30
Frank
  • 1,406
  • 2
  • 16
  • 42
  • 1
    "Should I enclose the implemenation of the C function foo with extern "C" linkage to resolve this problem?" - have you tried it? did it resolve the problem? – user253751 Jan 02 '16 at 01:45
  • Maybe something to do with `C++` name mangling? Did you make the entry function `C` linkage? – Galik Jan 02 '16 at 01:46
  • @immibis, I will try your suggestion in 5 minutes. Thank you and Happy New Year. – Frank Jan 02 '16 at 01:46
  • @Galik, I will try to make the entry function C linkage shortly. Happ New Year. – Frank Jan 02 '16 at 01:48
  • Can't you format the post clearly please? – Lightness Races in Orbit Jan 02 '16 at 01:49
  • I wrapped the entry point lib_entry in exten "C" linkage and compiled with Accessing a corrupted shared library – Frank Jan 02 '16 at 02:24
  • @immibis,@Galik I tried extern "C" linkage and compiled with g++ -shared -fPIC -DLINUX -I /home/venkat/Downloads/waitForMultipleObjects -I /home/venkat/developmentMono/SmartCamXi_Hybrid/Include -efunc DataServer.cpp DataServerLib.cpp DataTransferClient.cpp CWinEventHandle.cpp WinEvent.cpp -lpthread -lrt -o myprogBC.so Then I ran this ; $ ./myprogBC.so. Then I got the error message: Accessing a corrupted shared library which means that I am on a 64 bit system trying to make a 32 bit library. When I try: g++ -m32, I get : bits/c++config.h: No such file/directory : How do I fix this? – Frank Jan 02 '16 at 02:52
  • @LightnessRacesinOrbit, Could you please try to solve this problem? Even when I use g++ -m64 , I get the error message: Accessing a corrupted shared library. Thank you. – Frank Jan 02 '16 at 06:50

2 Answers2

0

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

Community
  • 1
  • 1
Frank
  • 1,406
  • 2
  • 16
  • 42
  • @Lightness Races in Orbit, Could you please try to solve this problem? Even when I use g++ -m64 , I get the error message: Accessing a corrupted shared library. Thank you. – Frank Jan 02 '16 at 06:51
-1

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

Frank
  • 1,406
  • 2
  • 16
  • 42