This time I'm trying to build openhevc statically on both linux and osx and I came across an annoying issue. My solution may not be the best one, if someone has a better idea I'll take it.
The problem: to build a static lib, we first build libavutil.alibavcodec.alibopenhevc.a (with only openhevc.o in it), and then combine the 3 to have a proper libopenhevc.a containing all symbols.
The current way of doing the combining is to extract all the contents of the .a libs with ar -x and then repackage all the extracted .o files into libopenhevc.a.
This approach has two problems:
if different libs have files of the same name they'll be overwritten when extracting
if a lib have multiple files of the same name in sub-directories, ar -x will only extract one of them
1 is easily fixable (just extract into different directories for example), but 2. is more tricky.
For example, libavcodec has simple_idct.c and x86/simple_idct.c. When creating libavcodec.a, ar will create two sections called simple_idct.o. When extracting (ar -x libavcodec.a) it will only extract one simple_idct.o containing the symbols of one the source files.
Solution 1: To get around that, GNU ar can use MRI scripts, for example :
$ cat lib.mri
create libopenhevc.a
addlib libopenhevc/libopenhevc.a
addlib libavcodec/libavcodec.a
addlib libavutil/libavutil.a
save
end
$ ar -M < lib.mri
This will generate a proper library, except.. that this doesn't work on OSX (which has BSD ar instead of GNU ar). Great.
Solution 2: The only way I've found to do this that work on both linux and osx, is to save the list of .o files when creating a library so that we can do ar <big list of .o files> libopenhevc.a to build the static lib without having to extract from the intermediary libs.
This may not be the prettiest solution but it seems to work.
Hi,
This time I'm trying to build openhevc statically on both linux and osx and I came across an annoying issue. My solution may not be the best one, if someone has a better idea I'll take it.
The problem: to build a static lib, we first build
libavutil.a
libavcodec.a
libopenhevc.a
(with onlyopenhevc.o
in it), and then combine the 3 to have a properlibopenhevc.a
containing all symbols.The current way of doing the combining is to extract all the contents of the .a libs with
ar -x
and then repackage all the extracted .o files intolibopenhevc.a
.This approach has two problems:
1 is easily fixable (just extract into different directories for example), but 2. is more tricky.
For example,
libavcodec
hassimple_idct.c
andx86/simple_idct.c
. When creatinglibavcodec.a
, ar will create two sections calledsimple_idct.o
. When extracting (ar -x libavcodec.a
) it will only extract onesimple_idct.o
containing the symbols of one the source files.Solution 1: To get around that, GNU ar can use MRI scripts, for example :
This will generate a proper library, except.. that this doesn't work on OSX (which has BSD ar instead of GNU ar). Great.
Solution 2: The only way I've found to do this that work on both linux and osx, is to save the list of .o files when creating a library so that we can do
ar <big list of .o files> libopenhevc.a
to build the static lib without having to extract from the intermediary libs.This may not be the prettiest solution but it seems to work.