[cmake-developers] Patch for FindBZip2.cmake BZIP2_NEED_PREFIX issue with cross compiled mingw32 applications
Ralf Habacker
ralf.habacker at freenet.de
Sun Jul 19 15:07:15 EDT 2015
Hi,
the appended patch fixes an issue I have with recent cmake (3.2.3) with
cross compiling an mingw32 application. The applications requires bzip2
library which is handled by cmake provided FindBZip2.cmake. The problem
is that BZIP2_NEED_PREFIX is not set where it should be and results
into linker failure not finding bzip2 related symbols.
Some details:
FindBZip2.cmake uses BZ2_bzCompressInit to detect if BZIP2_NEED_PREFIX
should be set.
CHECK_LIBRARY_EXISTS("${BZIP2_LIBRARIES}" BZ2_bzCompressInit ""
BZIP2_NEED_PREFIX)
The check is performed with CheckFunctionExists.c, which converts the
function name into a prototype of the form 'char BZ2_bzCompressInit()',
while in real it is
int BZ2_bzCompressInit ( bz_stream *strm,
int blockSize100k,
int verbosity,
int workFactor );
The compiler converts this function to the symbol '_BZ2_bzCompressInit',
which is not in the related import library.
Taking a look into the related import library shows that there is
objdump -x /usr/i686-w64-mingw32/sys-root/mingw/lib/libbz2.dll.a | grep
CompressInit
[ 6](sec 1)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000
_BZ2_bzCompressInit at 16
[ 7](sec 3)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000
__imp__BZ2_bzCompressInit at 16
The '@16' indicates the size of the parameter list
(https://msdn.microsoft.com/en-us/library/zxk0tw93.aspx) with does match
the used prototype 'char BZ2_bzCompressInit().'
The fix is to use a function which do not have parameters like
BZ2_decompress.
objdump -x /usr/i686-w64-mingw32/sys-root/mingw/lib/libbz2.dll.a | grep
decompress
[ 6](sec 1)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000 _BZ2_decompress
[ 7](sec 3)(fl 0x00)(ty 0)(scl 2) (nx 0) 0x00000000
__imp__BZ2_decompress
The appended patch fixes this issue.
Regards
Ralf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: findbzip2-need-prefix.patch
Type: text/x-patch
Size: 541 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20150719/bfa38b92/attachment.bin>
More information about the cmake-developers
mailing list