Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13 (Read 11300 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Hi.

I need to build oggenc from Vorbis-Tools, but with a custom libvorbis (containing some experimental modifications). Consequently, I need to make sure that it won't link against the system-provided libvorbis. Also I need to link my libvorbis statically, so it will use my libvorbis at runtime - instead of loading the system-provided shared libvorbis. I'm on Ubuntu 13.10.

So, building libvorbis and libogg as static libraries was straight forward. I now have my libs and the corresponding includes in "/home/john_doe/dev/ogg" and "/home/john_doe/dev/vorbis", respectively. Like "/home/john_doe/dev/vorbis/include/vorbis/codec.h" and "/home/john_doe/dev/vorbis/lib/libvorbis.a". The big problem is building Vorbis-Tools in the right way!

If I build Vorbis-Tools with a standard "./configure" followed by "make", it will build "oggenc" nicely, but the resulting binary uses the system's shared libvorbis from "/usr/lib/libvorbis.0.so". So I need to prevent "./configure" from picking up the system libraries/includes and instead of using mine. By the way, uninstalling the "libvorbis" packet via Synaptic is not an option, because a Zillion of applications depend on it.

Now what I have tried is like "./configure --with-ogg=/home/john_doe/dev/ogg --with-vorbis=/home/john_doe/dev/vorbis", which is supposed to work according to the help screen. But it had ZERO effect: The resulting oggenc still links against the system-provided libogg and libvorbis. Bummer! I even tried with "--with-vorbis-includes=(...) --with-vorbis-libraries=(...)", but again it had ZERO effect 

Now, as these ./configure options obviously don't work (or I use them wrong???), I ended up using the environment variables like this:
Code: [Select]
OGG_CFLAGS=-I/home/dev/libs/ogg/include OGG_LIBS="-L/home/dev/libs/ogg/lib -logg" VORBIS_CFLAGS=-I/home/dev/libs/vorbis/include VORBIS_LIBS="-L/home/dev/libs/vorbis/lib -lvorbis -lvorbisenc" ./configure


This finally had some effect! It's now linking against the correct libraries, I think. But now I get a zillion of errors like:
Code: [Select]
vorbis/lib/libvorbis.a(psy.o): In function `_vp_psy_init':
psy.c:(.text+0x2b65): undefined reference to `__log_finite'
psy.c:(.text+0x2df4): undefined reference to `__exp_finite'
psy.c:(.text+0x2f23): undefined reference to `atan'


To my understanding, those are system functions that should be provided by "libc" or "libgcc", but why it suddenly doesn't resolve those symbols? I even tried adding "-lc -lgcc" explicitly, but it didn't change anything...

What am I missing here? 

Thanks in advance,
MuldeR

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Reply #1
So, to clarify in both our minds, you want to create a binary that statically includes specific versions of libvorbis and libogg, but obviously not system libraries such as libc.  I don't think the configure options you've tried can achieve this, nor are they meant to.  They are just for distinguishing between different available libraries.

To do this you need to do two different things.  First is to set the load paths so that your libraries are picked up instead of the real ones.  I think you've taken care of this with your path commands in your environment variables.  The configure options should also do this.

So now you want to link certain libraries statically into your binary.  Assuming the makefile links using gcc (most do, but I haven't check this one) then you can use the -Wl option with the -Bstatic and -Bdynamic (or -Bshared which means the same) options to control which libraries get link statically and which are left to be link at run time.  You only have to do this when there are both static and dynamic libraries which gcc might find, so most people never see or need these options.  Order is important, and the option that comes last will apply to all the l;libraries not explicitly listed (eg. system libraries).  So something like -Wl,-Bstatic -lvorbis -logg -Wl,-Bshared should do the trick.

You could also try specifying the exact library to link using the -l: option so that it is statically linked.  Note that you'll have to specify the full path to the library file and the colon is critical, although documentation on this feature is sparse so you might have to experiment.

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Reply #2
Thanks for reply!

So, to clarify in both our minds, you want to create a binary that statically includes specific versions of libvorbis and libogg, but obviously not system libraries such as libc.


Yes, I need my own (static) versions of libvorbis and libogg to be linked into the oggenc binary. Whether libc and friends get linked statically or as shared library is not that important for me (since the "standard" versions will work fine). A fully static binary would be slightly preferred though, because I sometimes experiences libc incompatibility on other distributions...

To do this you need to do two different things.  First is to set the load paths so that your libraries are picked up instead of the real ones.  I think you've taken care of this with your path commands in your environment variables.  The configure options should also do this.


Well, they should, but they apparently didn't. Setting the CFLAGS and LDFLAGS explicitly via the "influential" environment variables like VORBIS_CFLAGS (they are also mentioned in the ./configure --help) did have and effect. I don't know why only the environment variables worked, but that's how it is, apparently.

So now you want to link certain libraries statically into your binary. Assuming the makefile links using gcc (most do, but I haven't check this one) then you can use the -Wl option with the -Bstatic and -Bdynamic (or -Bshared which means the same) options to control which libraries get link statically and which are left to be link at run time.  You only have to do this when there are both static and dynamic libraries which gcc might find, so most people never see or need these options.  Order is important, and the option that comes last will apply to all the l;libraries not explicitly listed (eg. system libraries).  So something like -Wl,-Bstatic -lvorbis -logg -Wl,-Bshared should do the trick.


Okay, I will definitely give that a try. But currently it seems that it's not linking in some fundamental system libraries (lib, libgcc, ???) at all. Those missing references should be in libc/libgcc, I think. Libraries I normally do not have to link explicitly...

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Reply #3
Okay, I have tried as you have suggested, but the result is still the same.

Linker command is now executed like this:
Code: [Select]
/bin/bash ../libtool --tag=CC --mode=link gcc  -O2 -Wall -ffast-math -fsigned-char -g -O2   -o oggenc    oggenc.o audio.o encode.o platform.o resample.o skeleton.o ../share/libutf8.a ../share/libgetopt.a -lvorbisenc -L/home/mulder/oggenc/libs/vorbis/lib -Wl,-Bstatic -lvorbis -lvorbisenc -lvorbisfile -Wl,-Bdynamic  -L/home/mulder/oggenc/libs/ogg/lib -Wl,-Bstatic -logg -Wl,-Bdynamic


And the errors I get are still like:
Code: [Select]
/home/mulder/oggenc/libs/vorbis/lib/libvorbis.a(psy.o): In function `_vp_psy_init':
psy.c:(.text+0x2b65): undefined reference to `__log_finite'
psy.c:(.text+0x2df4): undefined reference to `__exp_finite'
psy.c:(.text+0x2f23): undefined reference to `atan'



Quote
You could also try specifying the exact library to link using the -l: option so that it is statically linked.


Do you have any suggestion which one that would be in this case?

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Reply #4
Do you have any suggestion...

Hi
I do this to build oggenc with libvorbis-aoTuV, though I usually use system libogg.
Maybe something similar will work for you.
This is a method for Ubuntu...

Make a build folder in home directory.
Code: [Select]
cd ~/; mkdir build


Compile local static libogg.

Code: [Select]
cd ~/build; wget downloads.xiph.org/releases/ogg/libogg-1.3.1.tar.xz -qO-| tar -xJ; cd libogg-*

./configure --prefix=$HOME/build --disable-shared --disable-dependency-tracking

make; make install


Compile local static libvorbis-aoTuV.

Code: [Select]
cd ~/build; wget www.geocities.jp/aoyoume/aotuv/source_code/libvorbis-aotuv_b6.03.tar.bz2 -qO- | tar -xj; cd aotuv-*

chmod +x *; ./autogen.sh

CFLAGS="-I$HOME/build/include" \
LDFLAGS="-L$HOME/build/lib" \
PKG_CONFIG_PATH="$HOME/build/lib/pkgconfig" \
./configure --prefix=$HOME/build --disable-shared --disable-dependency-tracking

make; make install


Compile vorbis-tools.
Code: [Select]
cd ~/build; wget downloads.xiph.org/releases/vorbis/vorbis-tools-1.4.0.tar.gz -qO- | tar -xz; cd vorbis-tools-*

CFLAGS="-I$HOME/build/include" \
LDFLAGS="-L$HOME/build/lib" \
PKG_CONFIG_PATH="$HOME/build/lib/pkgconfig" \
./configure

make

sudo checkinstall --pakdir "$HOME/Desktop" --pkgname vorbis-tools \
--pkgversion 1.4.0.1 \
--backup=no --fstrans=no --default; sudo ldconfig



When I use command:-
Code: [Select]
oggenc foo.wav


Mediainfo shows aoTuV:-
Code: [Select]
General
Complete name           : foo.ogg
Format                  : OGG
File size               : 808 KiB
Duration                : 1mn 0s
Overall bit rate mode   : Variable
Overall bit rate        : 109 Kbps

Audio
ID                      : 2134113488 (0x7F33FCD0)
Format                  : Vorbis
Format settings, Floor  : 1
Duration                : 1mn 0s
Bit rate mode           : Variable
Bit rate                : 112 Kbps
Channel(s)              : 2 channels
Sampling rate           : 44.1 KHz
Compression mode        : Lossy
Stream size             : 827 KiB
Writing library         : aoTuV 20110424 (UTC 2011-04-24)


EDIT
I think that oggenc still links to system libogg though :-(
Probably best not to build local libogg after all.
@Xubuntu:~$ ldd /usr/local/bin/./oggenc
   linux-gate.so.1 =>  (0xb7790000)
   libFLAC.so.8 => /usr/lib/i386-linux-gnu/libFLAC.so.8 (0xb7738000)
   libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb76f2000)
   libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7542000)
   libogg.so.0 => /usr/lib/i386-linux-gnu/libogg.so.0 (0xb7539000)
   /lib/ld-linux.so.2 (0xb7791000)

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Reply #5
Thanks a lot, bat_guano!

I strictly followed your instructions and this time it worked right away 

Now quite sure what this does differently though:
Code: [Select]
/bin/bash ../libtool --tag=CC --mode=link gcc  -O2 -Wall -ffast-math -fsigned-char -I/home/mulder/build/include  -L/home/mulder/build/lib -o oggenc    oggenc.o audio.o encode.o platform.o resample.o skeleton.o ../share/libutf8.a ../share/libgetopt.a -lvorbisenc -L/home/mulder/build/lib -lvorbis    -L/home/mulder/build/lib -logg
libtool: link: gcc -O2 -Wall -ffast-math -fsigned-char -I/home/mulder/build/include -o oggenc oggenc.o audio.o encode.o platform.o resample.o skeleton.o  -L/home/mulder/build/lib ../share/libutf8.a ../share/libgetopt.a /home/mulder/build/lib/libvorbisenc.a /home/mulder/build/lib/libvorbis.a -lm /home/mulder/build/lib/libogg.a
make[1]: Leaving directory `/home/mulder/oggenc/vorbis-tools-1.4.0/oggenc'


But apparently it works now! Also I don't see any dependency on shared libogg/libvorbis anymore:
Code: [Select]
~/oggenc/vorbis-tools-1.4.0/oggenc$ ldd oggenc
    linux-vdso.so.1 =>  (0x00007fffa2447000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5e7afc3000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5e7abfb000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f5e7b2dc000)


Now, if I could make a fully-static binary, it would be perfect 

Regards.

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Reply #6
Now, if I could make a fully-static binary...

Hi
You might be able to do this by adding -static to vorbis-tools config.
I've used this method to build a static FFmpeg, but not sure if it works with oggenc.

Like this:-
Code: [Select]
CFLAGS="-I$HOME/build/include" \
LDFLAGS="-static -L$HOME/build/lib" \
PKG_CONFIG_PATH="$HOME/build/lib/pkgconfig" \
./configure

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Reply #7
The main difference seems to be that you built static versions of the library objects.  Maybe you didn't have those before?

To build a fully static binary, you'll need the static objects of all the dependant libraries.  Not so many in this case, maybe you could actually do it, but they aren't included in the normal library packages.  You'll need the dev packages, for example libc6-dev.  It will be big!  Also, I'm not sure what purpose it would serve.

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Reply #8
Just adding "-static" to the LDFLAGS didn't change anything. Adding "-Wl,-Bstatic" did! But then it complained about missing libgcc_s, so I also had to add "-static-libgcc". But then it complained about a missing reference to some function I was able to locate in libc. Finally I ended up with:
Code: [Select]
CFLAGS="-I$HOME/build/include" LDFLAGS="-Wl,-Bstatic -static-libgcc -l:/usr/lib/x86_64-linux-gnu/libc.a -L$HOME/build/lib" PKG_CONFIG_PATH="$HOME/build/lib/pkgconfig" ./configure


And the result:
Code: [Select]
~/oggenc/vorbis-tools-1.4.0/oggenc$ ldd ./oggenc 
    not a dynamic executable


 

Thanks again for your help !!!

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Reply #9
Go on, satisfy my curiosity ... how big?

Build oggenc with *custom* libvorbis (static) - under Linux (Ubuntu 13

Reply #10
2.2 MB, stripped.