UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C++
  • » Library creation problem

#1 2005-02-22 03:13 PM

shiva
Member
From: INDIA
Registered: 2002-08-10
Posts: 94

Re: Library creation problem

I like to create a static library(.a) using a dynamic library(.so). After creating the static library, I shall create the dynamic library using the static library.
Here the tricky is, while creating the static library...the dynamic library includes files only be available no actual dynamic library won't be available(.so).

I tried this concept, but while executing the server using this concept...the server throws re-location error at the static library stack symbol.

Is there any option in G++ compiler to handle this situation?

Thanks in advance.
Shiva

Offline

#2 2005-02-23 02:01 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: Library creation problem

I'm afraid I can't entirely parse what you're saying...  However, I certainly have
created dynamic libs from static libs before (and, commonly use a static lib as a
container archive for library *.o files, before turning them into a shared lib)...  You
need to use the "-Wl,--whole-archive" switch in the gcc command-line when
creating the shared lib, prior to specifying the location of the static lib to create it
from; and then specify "-Wl,--no-whole-archive" after it to turn it back off, so that
stuff from glibc and elsewhere doesn't get sucked in, as well...

Oh, but realize you still should compile all the *.o files in the static lib with "-fPIC",
the same as you would for a shared lib, since you're going to need to turn them
into a shared lib later...

Offline

#3 2005-02-23 04:09 PM

shiva
Member
From: INDIA
Registered: 2002-08-10
Posts: 94

Re: Library creation problem

Rob, Thanks for yr response.Let me explain the problem further.

The scenario is as follows

While compiling the folllowing modules

Module (1)
----------
Using the "xxx.so" library (This is not yet created...only including the header files...is this possible to do so with g++ compiler options..if any)

Creating a "yyy.a" library
createing  "xyz" executable

Module(2)
---------
Creating the actual "xxx.so" library using the "yyy.a" library generated from the Module(1).

/******* COMPILATION OVER ******************/

Trying to execute the program.
While executing the executable "xyz"...we get the fatal:relocation error.

This is due to
Executable "xyz" calls a function from "xxx.so" lib and in turn the "xxx.so" library calls a method from "yyy.a" lib.

Can this be taken care in the compilation time itself or I need to change the programs in the module in order to take care of the build hirarchy.

It's an interesting problem and finding a solution for this.

Offline

#4 2005-02-23 10:35 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,847
Website

Re: Library creation problem

Are you currently compiling the files which make up "yyy.a" with the "-fPIC" switch?
If not, definitely give that a try, and see if it helps...

Offline

#5 2005-02-24 12:28 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Library creation problem

shiva's problem seems to be a circular dependency between the two libs, -fPIC won't help for that I think. Perhaps the --unresolved-symbols linker option is helpful (see man ld).

Offline

  • Index
  • » C++
  • » Library creation problem

Board footer

Powered by FluxBB