Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails because of missing bzlib.h + libbz2.a #279

Closed
nagelp opened this issue Mar 11, 2022 · 3 comments · Fixed by #280
Closed

Build fails because of missing bzlib.h + libbz2.a #279

nagelp opened this issue Mar 11, 2022 · 3 comments · Fixed by #280

Comments

@nagelp
Copy link

nagelp commented Mar 11, 2022

Great tool, thanks a lot, Hou Sisong.

I've tried to build it from source on my Linux x86_64 machine, but encountered an issue with bzip2. I cloned your bzip2 repo (https://github.com/sisong/bzip2.git), built the libbz2.a and changed the Makefile in this repo so that preprocessor and linker can find header + lib. But if you were to apply this patch to the Makefile, you would also have to instruct people to build the bzip2 lib first. And maybe you want to make bzip2 support optional, like you do it with lzma and zstd?

Anyway, I got it built, but wanted to give you this feedback :)

diff --git a/Makefile b/Makefile
index b0f496c..8d459af 100644
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,8 @@ HPATCH_OBJ := \
     libHDiffPatch/HPatch/patch.o \
     file_for_patch.o
 
+BZLIB_PATH := ../bzip2
+
 ifeq ($(DIR_DIFF),0)
 else
   HPATCH_OBJ += \
@@ -127,7 +129,8 @@ DEF_FLAGS := \
     -D_CompressPlugin_zlib  \
     -D_CompressPlugin_bz2  \
     -D_IS_NEED_ALL_ChecksumPlugin=0 \
-    -D_IS_NEED_DEFAULT_ChecksumPlugin=0 
+    -D_IS_NEED_DEFAULT_ChecksumPlugin=0 \
+    -L../bzip2
 ifeq ($(DIR_DIFF),0)
   DEF_FLAGS += -D_IS_NEED_DIR_DIFF_PATCH=0
 else
@@ -153,7 +156,7 @@ ifeq ($(ZSTD),0)
 else
   DEF_FLAGS += \
     -D_CompressPlugin_zstd -DZSTD_DISABLE_ASM -I$(ZSTD_PATH) -I$(ZSTD_PATH)/common \
-       -I$(ZSTD_PATH)/compress -I$(ZSTD_PATH)/decompress
+       -I$(ZSTD_PATH)/compress -I$(ZSTD_PATH)/decompress -I$(BZLIB_PATH)
 endif
 
 ifeq ($(MT),0)
@sisong
Copy link
Owner

sisong commented Mar 11, 2022

Yes, bzip2 source code support in MakeFile maybe an option.
Thank you for the patch.

In MakeFile, I used PATCH_LINK := -lz -lbz2 to link zlib & bzip2;
It's working well all along on Linux & MacOS.
Try $ apt-get install libbz2 or $ sudo apt-get install libbz2-dev or $ yum -y install bzip2 ... to install bzip2;
or clone bzip2 source code repo, and $ make && make install.

@nagelp
Copy link
Author

nagelp commented Mar 11, 2022

Ok, my bad, I didn't see the '-lbz2', only looked for 'bzip2'.

Indeed, when I install libbz2-dev on my Ubuntu system, it links just fine against the system library.

So instead of the Makefile patch, here is a README.md patch ;)

diff --git a/README.md b/README.md
index 9ee8a7e..f05749e 100644
--- a/README.md
+++ b/README.md
@@ -19,19 +19,26 @@ a C\C++ library and command-line tools for Diff & Patch between binary files or
 [Download from latest release](https://github.com/sisong/HDiffPatch/releases) : Command line app for Windows, Linux, MacOS; and .so patch lib for Android.     
 ( release files build by projects in path `HDiffPatch/builds` )   
 
-## Builds
+## Build it yourself
 `$ cd <dir>/HDiffPatch`   
-if on linux or macos, try :   
+### Linux or MacOS X ###
+
+Try:
 `$ make LZMA=0 ZSTD=0 MD5=0`   
-or    
+if the build fails with `fatal error: bzlib.h: No such file or directory`, use your system's package manager to install the libbz2-dev package and try again.
+
+Alternatively, get the optional library headers (+bzip2 library) and build completely:
+
 ```
 $ git clone https://github.com/sisong/lzma.git   ../lzma
 $ git clone https://github.com/facebook/zstd.git ../zstd
 $ git clone https://github.com/sisong/libmd5.git ../libmd5
+$ git clone https://github.com/sisong/bzip2.git ../bzip2 && pushd ../bzip2 && make && sudo make install && popd
 $ make
 ```    
    
-if on windows, befor compile `builds/vc/HDiffPatch.sln` by `Visual Studio` 
+### Windows ###
+Before you build `builds/vc/HDiffPatch.sln` with `Visual Studio`, first get the libraries into sibling folders, like so:
 ```
 $ git clone https://github.com/sisong/lzma.git   ../lzma
 $ git clone https://github.com/facebook/zstd.git ../zstd
@@ -40,7 +47,7 @@ $ git clone https://github.com/sisong/zlib.git   ../zlib
 $ git clone https://github.com/sisong/bzip2.git  ../bzip2
 ```
    
-build libhpatchz.so for Android:   
+### libhpatchz.so for Android ###
 * install Android NDK
 * `$ cd <dir>/HDiffPatch/builds/android_ndk_jni_mk`
 * `$ build_libs.sh`  (or `$ build_libs.bat` on windows, then got \*.so files)

@nagelp
Copy link
Author

nagelp commented Mar 15, 2022

Great, thanks a lot, make LZMA=0 ZSTD=0 MD5=0 BZIP2=0 BSD=0 works perfectly now 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants