LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-08-2003, 01:36 PM   #1
neorich
LQ Newbie
 
Registered: Aug 2003
Location: South Africa
Distribution: Mandrake 9
Posts: 15

Rep: Reputation: 0
Finding and Linking Static Libraries with gcc


i've written a c++ program (compiled with gcc 3.2 on Mandrake 9) that dynamically links to the following (as per 'ldd')

libglut.so.3 => /usr/lib/libglut.so.3 (0x40020000)
libGLU.so.1 => /usr/lib/libGLU.so.1 (0x40053000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x400e2000)
libc.so.6 => /lib/i686/libc.so.6 (0x401a6000)
libGL.so.1 => /usr/lib/libGL.so.1 (0x402c6000)
libm.so.6 => /lib/i686/libm.so.6 (0x40498000)
libpthread.so.0 => /lib/i686/libpthread.so.0 (0x404bb000)
libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x404cf000)
libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x404d9000)
libXmu.so.6 => /usr/X11R6/lib/libXmu.so.6 (0x404f0000)
libXt.so.6 => /usr/X11R6/lib/libXt.so.6 (0x40506000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x4055f000)
libXi.so.6 => /usr/X11R6/lib/libXi.so.6 (0x4056f000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x40577000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x40642000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
libdl.so.2 => /lib/libdl.so.2 (0x4064b000)

now my mission is to give this GLUT-dependent application to someone who is running RedHat 7 and lacks some of these libraries (most, to my knowledge).
can someone tell me how i can statically link in all the relevant libraries such that he can execute the binary on his system without having to install ANYTHING whatsoever?
if so, where can i get all the relevant libraries (i'm new to linux-programming, and as such don't have much of a clue when it comes to this sort of issue).
if anyone can help, please give me step-by-step instructions.

if it helps at all, here's my makefile:

LIBS = -lglut -lGLU -lstdc++
FILES = main.cpp String.cpp Init.cpp
DEPENDENCIES = $(FILES)

main: $(DEPENDENCIES)
gcc $(FILES) -o roost $(LIBS)


while i'm at it, is there any easy-to-use library that can generate .eps figures from vector information?

much appreciation.
 
Old 08-08-2003, 01:49 PM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
just add the -static flag to gcc

gcc -static $(FILES) -o ...etc

btw g++ is just like gcc with libstdc++ linked automatically. also your makefile kinda misses the entire point of makefiles. the idea is if one source file changes the others do NOT have to be recompiled. i havnt written a makefile in a long time but maybe something like this:

Code:
PROGNAME=roost
OBJECTS=main.o string.o init.o
CFLAGS=-static -O2 -Wall
LIBS= -lglut -lGLU 

$(PROGNAME) : $(OBJECTS)
    g++ $(CFLAGS) -o roost $(OBJECTS) $(LIBS)

%.o : %.c
    gcc -c -o $@ $<
now only the changed files are recompiled

Last edited by kev82; 08-08-2003 at 02:03 PM.
 
Old 08-08-2003, 01:55 PM   #3
neorich
LQ Newbie
 
Registered: Aug 2003
Location: South Africa
Distribution: Mandrake 9
Posts: 15

Original Poster
Rep: Reputation: 0
i've tried that option before... thing is, it complains as follows:

/usr/bin/ld: cannot find -lglut
collect2: ld returned 1 exit statis
make: *** [main] Error 1

i can't for the life of me figure out how to satisfy gcc on this one... please help!
 
Old 08-08-2003, 02:05 PM   #4
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
can you find libglut.a, if not then you need to install it, once you have it try again and if it still complains use the -L option to give g++ the path to it
 
Old 08-08-2003, 02:08 PM   #5
neorich
LQ Newbie
 
Registered: Aug 2003
Location: South Africa
Distribution: Mandrake 9
Posts: 15

Original Poster
Rep: Reputation: 0
i have 'libglut.la'... is this related somehow to 'libglut.a'?
 
Old 08-08-2003, 02:27 PM   #6
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
i dont know, do file /path/to/libglut.la if its an ar archive then its what you want, if its a shared object then its not
 
Old 08-09-2003, 05:20 AM   #7
neorich
LQ Newbie
 
Registered: Aug 2003
Location: South Africa
Distribution: Mandrake 9
Posts: 15

Original Poster
Rep: Reputation: 0
i apologise... i was silly enough not to realise that it was simply text. this is the contents of 'libglut.la':

# libglut.la - a libtool library file
# Generated by ltmain.sh - GNU libtool 1.4 (1.920 2001/04/24 23:26:18)
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libglut.so.3'

# Names of this library.
library_names='libglut.so.3.7.1 libglut.so.3 libglut.so'

# The name of the static archive.
old_library=''

# Libraries that this one depends upon.
dependency_libs=' -L/usr/src/Mesa-5.0/si-glu -L/usr/X11R6/lib -lSM -lICE -lXmu -lXext -lXi -lX11'

# Version information for libglut.
current=10
age=7
revision=1

# Is this an already installed library?
installed=yes

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/usr/lib'


i'm not quite sure if 'the static archive' is referring to the static library... anway, it doesn't seem to exist:

old_library=''

man, i'm lost.
thanks for the help though...
 
Old 08-09-2003, 06:27 AM   #8
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
you need to locate a libglut.a, im not at all familiar with rpm based distros so i cant really tell you where to look, all i can say is i got glut from mesa, so maybe mesa-version-devel.rpm may contain it but i find it very surprising that you have the libglut headers/shared libraries without the static archive.
 
Old 08-09-2003, 06:39 AM   #9
neorich
LQ Newbie
 
Registered: Aug 2003
Location: South Africa
Distribution: Mandrake 9
Posts: 15

Original Poster
Rep: Reputation: 0
i agree with you... it's incredibly strange.
i downloaded MesaDemos-5.0.tar.gz and MesaLib-5.0.tar.bz2 (apparently the latest) from sourceforge.

they come with a wealth of files, but no libglut.a

i know it exists, as i've seen it listed in rpm's.
but i can't install these ones (they complain about dependency issues which i suspect are version-related)...

i'm trying now to locate a libglut.a in any form from anywhere (stand-alone one)...
 
Old 08-09-2003, 07:06 AM   #10
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
ignore this post unless MasterC's rpm doesnt have what you need

what you downloaded was(i think) a source distribution, unpack mesalib, cd into the directory and do

./configure --help | less

now you want to find the options to enable the build of static libraries and to make glut. dont worry about the prefix option your not gonna install it, once you have chosen your options do another ./configure but with the options you want, hopefully that'll run without error, then do make, hopefully that will also run without error. now somewhere(sometimes in a hidden directory) should be libglut.a copy that to your source directory

now in your make file replace -lglut with /path/to/libglut.a and all should go well, i hope.

i have a libglut.a but its optimised for an athlon-xp so its probably no good to you.

Last edited by kev82; 08-09-2003 at 07:39 AM.
 
Old 08-09-2003, 07:37 AM   #11
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
ftp://ftp.orst.edu/pub/mandrake/9.1/...-3mdk.i586.rpm

Cool

{EDIT}
That's mandy 9.1, I'll hunt down one for 9...
{/EDIT}
 
Old 08-09-2003, 07:47 AM   #12
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
ftp://csociety-ftp.ecn.purdue.edu/pu...-6mdk.i586.rpm

That one was rough!

Cool
 
Old 08-09-2003, 09:21 AM   #13
neorich
LQ Newbie
 
Registered: Aug 2003
Location: South Africa
Distribution: Mandrake 9
Posts: 15

Original Poster
Rep: Reputation: 0
i'm not at my linux machine now... hafta wait a couple of hours before i continue the war.. but,

kev82 - thanks for the configure advice... there's definitely merit to that approach and i'll give it a try (if need be)

MasterC - good searching. i've got the rpm - hopefully this spells the end of my rainy days.

later...
 
Old 08-09-2003, 01:45 PM   #14
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
how's it going? im dying to find out which other static libraries mandrake decided were not worth installing.
 
Old 08-10-2003, 03:14 PM   #15
neorich
LQ Newbie
 
Registered: Aug 2003
Location: South Africa
Distribution: Mandrake 9
Posts: 15

Original Poster
Rep: Reputation: 0
oh man... it was plain hell..

refer to my first post in this thread.
every library there had to have its '.a' counterpart.
i eventually got them all (save the last two) and started getting more strange (linking) errors. i think i popped a vessel.
i've got to say, its not really in my spirit to quit but this struggle has lead me to believe that even if i do get it working on my distro, it most likely won't work on any other one.
so i'm going to just try the shared library approach.
i'm also quite keen to hear from higher authorities how static linking (in an X11 context) is supposed to be done.
really crazy.
your help has been invaluable, though.
thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking static and shared libraries in the KDevelop Environment tristanm Programming 15 11-27-2006 09:59 PM
Linking old libraries to new one? winterhunter Linux - Software 7 10-24-2005 04:37 AM
Linking Libraries, Dependencies Killbot_5000 Linux - Software 4 09-28-2004 08:59 AM
Problem with linking libraries using gcc shortyzms Linux - Software 1 03-29-2004 08:13 PM
Shared libraries and linking., devin Programming 3 04-08-2003 03:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration