Coder Social home page Coder Social logo

Comments (9)

vasi avatar vasi commented on July 20, 2024

Hmm, I'm not sure whether that version of xz should be ok. But it's definitely possible to compile statically, if you set the right flags.

from pixz.

vasi avatar vasi commented on July 20, 2024

I was able to do the following:

  • Configure xz 5.0.5 with --prefix=$HOME/prefix , make, make install
  • Build pixz against the static liblzma with make LIBPREFIX="$HOME/root" LIBADD="-lpthread -larchive $HOME/root/lib/liblzma.a"

from pixz.

lasso012 avatar lasso012 commented on July 20, 2024

Thanks! I was modifying the makefile to do the static linking at first. I've modified what I was doing with your way.

Statically Link to libarchive and liblzma

  • Download http://www.libarchive.org/downloads/libarchive-3.1.2.tar.gz
  • Download http://tukaani.org/xz/xz-5.0.5.tar.gz
  • Extract the tarballs to a temporary directory. We'll use /tmp/pixz_build for now.
  • Clone the pixz repository to /tmp/pixz_build/pixz.
  • Build libarchive:
    • cd /tmp/pixz_build/libarchive-3.1.2 && ./configure --prefix="/tmp/pixz_build" && make && make install
  • Build xz-utils:
    • cd /tmp/pixz_build/xz-5.0.5 && ./configure --prefix="/tmp/pixz_build" && make && make install
  • Build pixz and statically link to the above libraries:
    • cd "/tmp/pixz_build/pixz" && make LIBPREFIX="/tmp/pixz_build" LIBADD="-lpthread -Wl,-Bstatic -llzma -larchive -Wl,-Bdynamic -lm"
  • Copy pixz to /usr/local/bin
  • Delete /tmp/pixz_build

This was done on Scientific Linux 6.5 (updated as of this writing) with only the "Development tools" group installed on top of the base "Desktop" installation type.

I haven't done much testing. I just compressed and decompressed a few small directories. I also decompressed a few *.tar.xz archives I made under Xubuntu 12.04.4 (compiled pixz using libarchive-dev and liblzma-dev) and those worked fine.

Notes with passing -lm:

  • Using -lm by itself didn't work:
make LIBPREFIX="/tmp/pixz_build" LIBADD="-lpthread -lm -Wl,-Bstatic -llzma -larchive"
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o pixz.o pixz.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o common.o common.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o endian.o endian.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o cpu.o cpu.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o read.o read.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o write.o write.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o list.o list.c
gcc -L/tmp/pixz_build/lib -g -O0 -Wall  -o pixz pixz.o common.o endian.o cpu.o read.o write.o list.o -lpthread -lm -Wl,-Bstatic -llzma -larchive
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
make: *** [pixz] Error 1
  • Using -Wl,-Bdynamic -lm before the static options didn't work either:
make LIBPREFIX="/tmp/pixz_build" LIBADD="-lpthread -Wl,-Bdynamic -lm -Wl,-Bstatic -llzma -larchive"
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o pixz.o pixz.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o common.o common.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o endian.o endian.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o cpu.o cpu.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o read.o read.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o write.o write.c
gcc -I/tmp/pixz_build/include -g -O0 -std=gnu99 -Wall -Wno-unknown-pragmas -DPIXZ_VERSION='"1.0.2"'  -c -o list.o list.c
gcc -L/tmp/pixz_build/lib -g -O0 -Wall  -o pixz pixz.o common.o endian.o cpu.o read.o write.o list.o -lpthread -Wl,-Bdynamic -lm -Wl,-Bstatic -llzma -larchive
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
make: *** [pixz] Error 1

I'm not really a developer so I don't know why I get those errors based on how -lm is passed. I documented them here anyway in case someone can explain why.

from pixz.

 avatar commented on July 20, 2024

Following these steps, I still couldn't get a static pixz binary

./src/pixz: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=9d4c4a920ceb1d4b0707257578d63b55d98efe32, not stripped

pixz was built with

make CFLAGS="-I$MYPREFIX/include/" LIBPREFIX=$MYPREFIX LIBADD="-lpthread -Wl,-Bstatic -llzma -larchive -Wl,-Bdynamic -lm"

from pixz.

wookietreiber avatar wookietreiber commented on July 20, 2024

@voltagex I assume, you are still on an older version. Please check out the latest release which builds the project using autotools.

To link statically, you first need to have all the dependencies as static libraries, i.e. libarchive.a and liblzma.a. Then, you can build with:

export LDFLAGS="-static"
./configure
make

This should statically link pixz.

from pixz.

cicku avatar cicku commented on July 20, 2024

/usr/bin/ld: cannot find -lgcc_s

Something wrong with shared object linker

from pixz.

cicku avatar cicku commented on July 20, 2024

,-Bstatic -llzma -larchive

You were trying to link shared libraries to static objects, but not static libraries at all.

from pixz.

tomck avatar tomck commented on July 20, 2024

This should be retitled RHEL6, because it affects CentOS 6 too:

xz (XZ Utils) 4.999.9beta
liblzma 4.999.9beta

I'm also having issues with the static compiling, even with export LDFLAGS="-static", I have the .a files in the location that I'm setting for LIBARCHIVE_LIBS and also copied in the folder I'm building from, so I'm not sure what I'm missing.

checking for LIBARCHIVE... no
configure: error: Package requirements (libarchive) were not met:

No package 'libarchive' found

I tried on a CentOS 7 system with the new method since my xz and libarchive are ok, but, if I set LDFLAGS to -static, it fails, and if I don't, it succeeds.

[root@dal pixz-1.0.6]# export LDFLAGS=""
[root@dal pixz-1.0.6]# ./configure prefix=$HOME
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for gcc option to accept ISO C99... -std=gnu99
checking for gcc -std=gnu99 option to accept ISO Standard C... (cached) -std=gnu99
checking for src/pixz.1... yes
checking for ceil in -lm... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking if compiler needs -Werror to reject unknown flags... no
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... no
checking for PTHREAD_PRIO_INHERIT... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for LIBARCHIVE... yes
checking for LZMA... yes
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for stdint.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for unistd.h... (cached) yes
checking for off_t... yes
checking for size_t... yes
checking for ssize_t... yes
checking for uint16_t... yes
checking for uint32_t... yes
checking for uint64_t... yes
checking for uint8_t... yes
checking for special C compiler options needed for large files... no
checking for _FILE_OFFSET_BITS value needed for large files... no
checking for stdlib.h... (cached) yes
checking for GNU libc compatible malloc... yes
checking for stdlib.h... (cached) yes
checking for GNU libc compatible realloc... yes
checking for working strtod... yes
checking for memchr... yes
checking for memmove... yes
checking for memset... yes
checking for strerror... yes
checking for strtol... yes
checking whether htole64 is declared... no
checking whether htole64 is declared... (cached) no
checking whether le64toh is declared... yes
checking whether le64toh is declared... (cached) yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating test/Makefile
config.status: creating config.h
config.status: executing depfiles commands
[root@dal pixz-1.0.6]# export LDFLAGS="-static"
[root@dal pixz-1.0.6]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/root/pixz-1.0.6':
configure: error: C compiler cannot create executables
See `config.log' for more details
[root@dal pixz-1.0.6]# 

Fortunately I solved my issue by just grabbing an RPM from opensuse, it seems to be statically linked already: http://software.opensuse.org/download.html?project=home%3AAndreasStieger%3Abranches%3AArchiving&package=pixz

from pixz.

andreasstieger avatar andreasstieger commented on July 20, 2024

Yes, in this package I use the following:

export LIBARCHIVE_LIBS="-Wl,-Bstatic -larchive -Wl,-Bdynamic,-lbz2"
export LZMA_LIBS="-Wl,-Bstatic -llzma -Wl,-Bdynamic"

I also provide static libraries for libarchive and lzma in the same project as build dependencies, in versions required for pixz to work. These are not available on the stock target distribution, and static linking prevents version incompatibilities.

A platform not having the required build dependencies is not really a bug in pixz. So if we take my package as a demonstrator on how to build pixz on Scientific Linux 6.5, the issue can be closed.

from pixz.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.