LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-16-2006, 01:14 PM   #1
futhark
Member
 
Registered: Nov 2003
Location: Montréal (Can)
Distribution: FC4
Posts: 110

Rep: Reputation: 15
How to compile statically?


Hi there,

I've been trying to statically link streamdvd against libdvdread-0.9.4, without success so far. Is there anyone with experience in that domain who could lend me a hand?

First, I have modified streamdvd make file so the compilation uses libdvdread-0.9.4.

gcc -g -Wall -I../libdvdread-0.9.4/ -c requant.c streamdvd.c
gcc -g -Wall -I../libdvdread-0.9.4/ -L../libdvdread-0.9.4/dvdread/.libs/ -ldvdread -lm -o streamdvd streamdvd.o requant.o

No problem so far, but that'll use shared libraries. This is not what I want. I googled around and one suggestion was to move libdvd *.so files away to force use of *.a library. That didn't work. I also tried adding the static keyword on the second line. That does not work either. In both cases I have the linker complaining about undefined symbols. It is like the linker does not see the static libraries.

Here's the output I get when compiling with the "static" keyword.

gcc -g -Wall -I../libdvdread-0.9.4/ -c requant.c streamdvd.c
streamdvd.c: In function ‘stream_vob’:
streamdvd.c:107: warning: pointer targets in passing argument 1 of ‘identify_stream’ differ in signedness
gcc -v -g -Wall -I../libdvdread-0.9.4/ -L../libdvdread-0.9.4/dvdread/.libs/ -ldvdread -lm -o streamdvd streamdvd.o requant.o
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=i386-redhat-linux
Thread model: posix
gcc version 4.0.2 20051125 (Red Hat 4.0.2-8)
/usr/libexec/gcc/i386-redhat-linux/4.0.2/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o streamdvd /usr/lib/gcc/i386-redhat-linux/4.0.2/../../../crt1.o /usr/lib/gcc/i386-redhat-linux/4.0.2/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.0.2/crtbegin.o -L../libdvdread-0.9.4/dvdread/.libs/ -L/usr/lib/gcc/i386-redhat-linux/4.0.2 -L/usr/lib/gcc/i386-redhat-linux/4.0.2 -L/usr/lib/gcc/i386-redhat-linux/4.0.2/../../.. -ldvdread -lm streamdvd.o requant.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i386-redhat-linux/4.0.2/crtend.o /usr/lib/gcc/i386-redhat-linux/4.0.2/../../../crtn.o
streamdvd.o(.text+0x156): In function `stream_vob':
/phil/src/stream/StreamDVD-0.3/streamdvd.c:93: undefined reference to `DVDOpenFile'
 
Old 04-16-2006, 01:27 PM   #2
futhark
Member
 
Registered: Nov 2003
Location: Montréal (Can)
Distribution: FC4
Posts: 110

Original Poster
Rep: Reputation: 15
I found found an extra bit of information here. The button for finding similar thread is a nice feature!

http://www.linuxquestions.org/questi...d.php?t=435668

I have changed the way to reference the library. I explicitely point to ../libdvdread-0.9.4/dvdread/.libs/libdvdread.a.

gcc -v -g -Wall -I../libdvdread-0.9.4/ -o streamdvd streamdvd.o requant.o -lm ../libdvdread-0.9.4/dvdread/.libs/libdvdread.a

I am still getting undefined symbols errors, but they're different. Instead of referring to libdvdread function they refer to linker functions (dlopen, dlsym, etc). How can this be fixed?
 
Old 04-16-2006, 01:39 PM   #3
futhark
Member
 
Registered: Nov 2003
Location: Montréal (Can)
Distribution: FC4
Posts: 110

Original Poster
Rep: Reputation: 15
I found the solution!

The missing option was -ldl. My make file ends up being like that:

Code:
gcc -g -Wall -I../libdvdread-0.9.4/ -c requant.c streamdvd.c
gcc -v -g -Wall -I../libdvdread-0.9.4/ -o streamdvd streamdvd.o requant.o -lm ../libdvdread-0.9.4/dvdread/.libs/libdvdread.a -ldl
The important points are the following:
  1. Point to *.a library directly. Forget -static and -L.
  2. Add -ldl option.
  3. Careful with order of libraries.
Here's the proof! No ref to libdvd! The program executes! Yay!!!

Code:
[phil@phil StreamDVD-0.3]$ ldd streamdvd
        linux-gate.so.1 =>  (0x00766000)
        libm.so.6 => /lib/libm.so.6 (0x007f7000)
        libdl.so.2 => /lib/libdl.so.2 (0x0081e000)
        libc.so.6 => /lib/libc.so.6 (0x00111000)
        /lib/ld-linux.so.2 (0x006ae000)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[gcc] how to statically link my program? G00fy Programming 5 04-16-2006 04:35 PM
g++ statically link stdc++ problem berty Programming 1 05-16-2005 06:00 PM
What is a statically compiled binary? james_cwy Linux - Newbie 4 11-09-2003 10:51 PM
Can't compile MPlayer statically. Nezzo Linux - Software 3 11-04-2003 06:29 PM
How do I statically compile a src.rpm? WeNdeL Linux - General 1 05-19-2003 10:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:59 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