This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Static and Dynamic Linking


Okay, I'm trying to get a better understanding of how to do static and
dynamic linking with gcc.  Here is a hypothetical example.  I have
a proprietary graphics library "libgr" that has some functions that
call the ncurses API, and others that call the Xlib API.  I only have
the static and dynamic libraries and the (well-documented) headers for
libgr, not the source.  I have the object code (again, not the source)
for a program "snake" that calls the curses-based functions in libgr,
but none of the X-based ones.  Now, I am on a system with gcc and the
shared and development libraries for ncurses, but no X libraries at all.
What I want to do is link snake.o to libgr _statically_, so that it
can be run on systems without libgr.  I want it linked _dynamically_
to ncurses, because all of my target systems will have it, and I don't
want to waste space.  Obviously, it cannot be linked _at all_ to X11,
because I don't have it.  Optimally, I would like for the X-based code
from libgr not to be statically linked into the executable, because that
would just be a waste of space.  Finally, let's say that libgr also has
some math functions (not dependent on any external libraries) that are not
called by snake at all.  Can I make sure that those functions also take
up no space in my executable?  It can be assummed that the curses, X,
and math functions are all in separate object modules within the static
libgr library, but it would also be nice to have a solution that doesn't
assume this.  I am running gcc 3.2 on Linux.

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]