madler / zlib

A massively spiffy yet delicately unobtrusive compression library.
http://zlib.net/
Other
5.69k stars 2.45k forks source link

cross compiling from 64bit system to 32bit #143

Open tele1 opened 8 years ago

tele1 commented 8 years ago
$ CC="gcc -m32" CXX="g++ -m32" ; ./configure --archs="-arch i386 -arch x86_64"
Checking for gcc...
Compiler error reporting is too harsh for ./configure (perhaps remove -Werror).
** ./configure aborting.

Without options "--archs=..." I have $ objdump -p libz.so.1.2.8 | grep format libz.so.1.2.8: file format elf64-x86-64

zlib 1.2.8

mtl1979 commented 8 years ago

@tele1 You should post relevant lines from configure.log and make output when configure finishes. I would try removing --archs parameter because most likely your gcc doesn't support -arch parameter, which is Apple-specific flag.

-m32 doesn't actually imply 32-bit binary format, you should use -march=i686.

tele1 commented 8 years ago

1. I needed it for build dependencies and it for build mesa 32bit for 64bit system, I disabled build any archiver (because I had problem like above) however now I compiled mesa and working. ( so I don't need archiver for now ) Probably Steam need more dependencies ( alsa ), but let others take some to work. Tree dependencies is in link /topic,137358.0.html

2.

./configure CC="gcc -m32" CXX="g++ -m32" \ --build=x86_64-pc-linux-gnu \ --host=i686-pc-linux-gnu \

This is from http://www.mesa3d.org/autoconf.html

I used also " export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig " because my 32bit *.pc files are in other path. Edited: Or for source code which use cmake

cmake -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32"

3. Logs, I did not know. Thanks, now I will know about the log. $ CC="gcc -march=i686" CXX="g++ -march=i686" ; ./configure --archs="-arch i386 -arch x86_64" Checking for gcc... Compiler error reporting is too harsh for ./configure (perhaps remove -Werror). ** ./configure aborting. configure.log

--------------------
./configure --archs=-arch i386 -arch x86_64
pią, 20 maj 2016, 15:22:40 CEST
Checking for gcc...
=== ztest9697.c ===
extern int getchar();
int hello() {return getchar();}
===
gcc -c ztest9697.c
... using gcc

Checking for obsessive-compulsive compiler options...
=== ztest9697.c ===
int foo() { return 0; }
===
gcc -c -O3 -arch i386 -arch x86_64 ztest9697.c
gcc: error: i386: Nie ma takiego pliku ani katalogu
gcc: error: x86_64: Nie ma takiego pliku ani katalogu
gcc: error: unrecognized command line option ‘-arch’
gcc: error: unrecognized command line option ‘-arch’
(exit code 1)
Compiler error reporting is too harsh for ./configure (perhaps remove -Werror).
** ./configure aborting.
--------------------

And without arch, I used fresh source code from github what you have

$ CC="gcc -march=i686" CXX="g++ -march=i686" ; ./configure
Checking for gcc...
Checking for shared library support...
Building shared library libz.so.1.2.8 with gcc.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.

configure.log

--------------------
./configure
pią, 20 maj 2016, 15:28:40 CEST
Checking for gcc...
=== ztest10457.c ===
extern int getchar();
int hello() {return getchar();}
===
gcc -c ztest10457.c
... using gcc

Checking for obsessive-compulsive compiler options...
=== ztest10457.c ===
int foo() { return 0; }
===
gcc -c -O3 ztest10457.c

Checking for shared library support...
=== ztest10457.c ===
extern int getchar();
int hello() {return getchar();}
===
gcc -w -c -O3 -fPIC ztest10457.c
gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -o ztest10457.so ztest10457.o
Building shared library libz.so.1.2.8 with gcc.

=== ztest10457.c ===
#include <sys/types.h>
off64_t dummy = 0;
===
gcc -c -O3 -D_LARGEFILE64_SOURCE=1 ztest10457.c
Checking for off64_t... Yes.
Checking for fseeko... Yes.

=== ztest10457.c ===
#include <string.h>
#include <errno.h>
int main() { return strlen(strerror(errno)); }
===
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o ztest10457 ztest10457.c
Checking for strerror... Yes.

=== ztest10457.c ===
#include <unistd.h>
int main() { return 0; }
===
gcc -c -O3 -D_LARGEFILE64_SOURCE=1 ztest10457.c
Checking for unistd.h... Yes.

=== ztest10457.c ===
#include <stdarg.h>
int main() { return 0; }
===
gcc -c -O3 -D_LARGEFILE64_SOURCE=1 ztest10457.c
Checking for stdarg.h... Yes.

=== ztest10457.c ===
#include <stdio.h>
#include <stdarg.h>
#include "zconf.h"
int main()
{
#ifndef STDC
  choke me
#endif
  return 0;
}
===
gcc -c -O3 -D_LARGEFILE64_SOURCE=1 ztest10457.c
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().

=== ztest10457.c ===
#include <stdio.h>
#include <stdarg.h>
int mytest(const char *fmt, ...)
{
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
  vsnprintf(buf, sizeof(buf), fmt, ap);
  va_end(ap);
  return 0;
}
int main()
{
  return (mytest("Hello%d\n", 1));
}
===
gcc -O3 -D_LARGEFILE64_SOURCE=1 -o ztest10457 ztest10457.c
Checking for vsnprintf() in stdio.h... Yes.

=== ztest10457.c ===
#include <stdio.h>
#include <stdarg.h>
int mytest(const char *fmt, ...)
{
  int n;
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
  n = vsnprintf(buf, sizeof(buf), fmt, ap);
  va_end(ap);
  return n;
}
int main()
{
  return (mytest("Hello%d\n", 1));
}
===
gcc -c -O3 -D_LARGEFILE64_SOURCE=1 ztest10457.c
Checking for return value of vsnprintf()... Yes.

=== ztest10457.c ===
#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
int ZLIB_INTERNAL foo;
int main()
{
  return 0;
}
===
gcc -c -O3 -D_LARGEFILE64_SOURCE=1 ztest10457.c
Checking for attribute(visibility) support... Yes.

ALL = static shared all64
AR = ar
ARFLAGS = rc
CC = gcc
CFLAGS = -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
CPP = gcc -E
EXE =
LDCONFIG = ldconfig
LDFLAGS =
LDSHARED = gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map
LDSHAREDLIBC = -lc
OBJC = $(OBJZ) $(OBJG)
PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
RANLIB = ranlib
SFLAGS = -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
SHAREDLIB = libz.so
SHAREDLIBM = libz.so.1
SHAREDLIBV = libz.so.1.2.8
STATICLIB = libz.a
TEST = all teststatic testshared test64
VER = 1.2.8
Z_U4 =
exec_prefix = ${prefix}
includedir = ${prefix}/include
libdir = ${exec_prefix}/lib
mandir = ${prefix}/share/man
prefix = /usr/local
sharedlibdir = ${libdir}
uname = Linux
--------------------
mtl1979 commented 8 years ago

Like I suspected, gcc doesn't support '-arch' parameter... If you look closely, you will also notice that due to the semicolon ';' before ./configure, it doesn't actually pass '-march=i686' to configure and thus gcc.

tele1 commented 8 years ago

And without '-arch' I have for example minigzip64 and minigzip but

$ file minigzip
minigzip: ELF 64-bit LSB executable, x86-64, version 1
$ file minigzip64
minigzip64: ELF 64-bit LSB executable, x86-64, version 1
mtl1979 commented 8 years ago

Yes, because it ignored CC and CXX.

tele1 commented 8 years ago

Ok , thanks If you don't need any next log , you can close this topic ;-) I maybe I will change the distribution of linux ... Maybe I will use Manjaro, I don't know.

mtl1979 commented 8 years ago

You should try:

CC="gcc -m32 -march=i686" ./configure

or

./configure --archs="-m32 -march=i686"

zlib is C-only, so CXX is always ignored... removing the semicolon makes it use CC correctly. Setting '-march' to 'i686' makes it work on all modern processors, both Intel and AMD...

tele1 commented 8 years ago

CC="gcc -m32 -march=i686" ./configure

$ file minigzip
minigzip: ELF 32-bit LSB executable, Intel 80386, version 1 
$ file minigzip64
minigzip64: ELF 32-bit LSB executable, Intel 80386, version 1

Anyway I see now 32bit :-) So something working.

configure.log

--------------------
./configure
sob, 21 maj 2016, 09:07:12 CEST
=== ztest17151.c ===
extern int getchar();
int hello() {return getchar();}
===
gcc -m32 -march=i686 -c ztest17151.c
... using gcc

Checking for obsessive-compulsive compiler options...
=== ztest17151.c ===
int foo() { return 0; }
===
gcc -m32 -march=i686 -c -O3 ztest17151.c

Checking for shared library support...
=== ztest17151.c ===
extern int getchar();
int hello() {return getchar();}
===
gcc -m32 -march=i686 -w -c -O3 -fPIC ztest17151.c
gcc -m32 -march=i686 -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -o ztest17151.so ztest17151.o
Building shared library libz.so.1.2.8 with gcc -m32 -march=i686.

=== ztest17151.c ===
#include <sys/types.h>
off64_t dummy = 0;
===
gcc -m32 -march=i686 -c -O3 -D_LARGEFILE64_SOURCE=1 ztest17151.c
Checking for off64_t... Yes.
Checking for fseeko... Yes.

=== ztest17151.c ===
#include <string.h>
#include <errno.h>
int main() { return strlen(strerror(errno)); }
===
gcc -m32 -march=i686 -O3 -D_LARGEFILE64_SOURCE=1 -o ztest17151 ztest17151.c
Checking for strerror... Yes.

=== ztest17151.c ===
#include <unistd.h>
int main() { return 0; }
===
gcc -m32 -march=i686 -c -O3 -D_LARGEFILE64_SOURCE=1 ztest17151.c
Checking for unistd.h... Yes.

=== ztest17151.c ===
#include <stdarg.h>
int main() { return 0; }
===
gcc -m32 -march=i686 -c -O3 -D_LARGEFILE64_SOURCE=1 ztest17151.c
Checking for stdarg.h... Yes.

=== ztest17151.c ===
#include <stdio.h>
#include <stdarg.h>
#include "zconf.h"
int main()
{
#ifndef STDC
  choke me
#endif
  return 0;
}
===
gcc -m32 -march=i686 -c -O3 -D_LARGEFILE64_SOURCE=1 ztest17151.c
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().

=== ztest17151.c ===
#include <stdio.h>
#include <stdarg.h>
int mytest(const char *fmt, ...)
{
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
  vsnprintf(buf, sizeof(buf), fmt, ap);
  va_end(ap);
  return 0;
}
int main()
{
  return (mytest("Hello%d\n", 1));
}
===
gcc -m32 -march=i686 -O3 -D_LARGEFILE64_SOURCE=1 -o ztest17151 ztest17151.c
Checking for vsnprintf() in stdio.h... Yes.

=== ztest17151.c ===
#include <stdio.h>
#include <stdarg.h>
int mytest(const char *fmt, ...)
{
  int n;
  char buf[20];
  va_list ap;
  va_start(ap, fmt);
  n = vsnprintf(buf, sizeof(buf), fmt, ap);
  va_end(ap);
  return n;
}
int main()
{
  return (mytest("Hello%d\n", 1));
}
===
gcc -m32 -march=i686 -c -O3 -D_LARGEFILE64_SOURCE=1 ztest17151.c
Checking for return value of vsnprintf()... Yes.

=== ztest17151.c ===
#define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
int ZLIB_INTERNAL foo;
int main()
{
  return 0;
}
===
gcc -m32 -march=i686 -c -O3 -D_LARGEFILE64_SOURCE=1 ztest17151.c
Checking for attribute(visibility) support... Yes.

ALL = static shared all64
AR = ar
ARFLAGS = rc
CC = gcc -m32 -march=i686
CFLAGS = -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
CPP = gcc -m32 -march=i686 -E
EXE =
LDCONFIG = ldconfig
LDFLAGS =
LDSHARED = gcc -m32 -march=i686 -shared -Wl,-soname,libz.so.1,--version-script,zlib.map
LDSHAREDLIBC = -lc
OBJC = $(OBJZ) $(OBJG)
PIC_OBJC = $(PIC_OBJZ) $(PIC_OBJG)
RANLIB = ranlib
SFLAGS = -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
SHAREDLIB = libz.so
SHAREDLIBM = libz.so.1
SHAREDLIBV = libz.so.1.2.8
STATICLIB = libz.a
TEST = all teststatic testshared test64
VER = 1.2.8
Z_U4 =
exec_prefix = ${prefix}
includedir = ${prefix}/include
libdir = ${exec_prefix}/lib
mandir = ${prefix}/share/man
prefix = /usr/local
sharedlibdir = ${libdir}
uname = Linux
--------------------

-------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------

$ ./configure --archs="-m32 -march=i686"
Checking for gcc...
Compiler error reporting is too harsh for ./configure (perhaps remove -Werror).
** ./configure aborting.

configure.log

===
gcc -c -O3 i686 ztest15555.c
gcc: error: i686: File or folder not found
(exit code 1)
Compiler error reporting is too harsh for ./configure (perhaps remove -Werror).
** ./configure aborting.
--------------------

Edit: CC="gcc -m32" ./configure also working like ( CC="gcc -m32 -march=i686" ./configure )

mtl1979 commented 8 years ago

--archs="-m32 -march=i686" doesn't work because the regular expression that parses the flag in configure is buggy... it cuts the string from last '=' character instead of first.

    -a*=* | --archs=*) ARCHS=`echo $1 | sed 's/[^=]*=//'`; shift ;;
tele1 commented 7 years ago

Thanks help everyone !

Are these fixed? #119 I can not check, I did not have support from PCLinuxOS ( my topic about 32bit mesa for 64bit system for Steam was removed, because PCLinuxOS not support 32bit ) If you saw above I used workaround.

My spec looks like this and probably worked ( I can not prove now )

# 32/64bit spec-file
#
%define lib_major 1
%define lib_name %{name}_%{lib_major}-arch32
%define develname zlib-arch32-devel

%define build_biarch 0

Summary:    The zlib compression and decompression library
Name:       zlib
Version:    1.2.8
Release:    %mkrel 5
Group:      System/Libraries
License:    BSD
URL:        http://www.gzip.org/zlib/
Source0:    http://prdownloads.sourceforge.net/libpng/%{name}-%{version}.tar.xz
BuildRequires:  util-linux-ng
BuildRoot:  %{_tmppath}/%{name}-%{version}-%{release}-buildroot
Requires:   glibc >= 2.20

%description
The zlib compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed
data.  This version of the library supports only one compression method
(deflation), but other algorithms may be added later, which will have
the same stream interface.  The zlib library is used by many different
system programs.

#------------------------------------------------------
%package -n %{lib_name}
Summary:    The zlib compression and decompression library
Group:      System/Libraries
Provides:   %{lib_name} = %{version}-%{release} 

%description -n %{lib_name}
The zlib compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed
data.  This version of the library supports only one compression method
(deflation), but other algorithms may be added later, which will have
the same stream interface.  The zlib library is used by many different
system programs.
#------------------------------------------------------

#--------------------------
%package -n %{develname}
Summary:    Header files and libraries for developing apps which will use zlib
Group:      Development/Libraries
Requires:   %{lib_name} = %{version}-%{release}
Provides:   %{develname} = %{version}-%{release}

%description -n %{develname}
The zlib-devel package contains the header files and libraries needed
to develop programs that use the zlib compression and decompression
library.

Install the zlib-devel package if you want to develop applications that
will use the zlib library.
#--------------------------

%prep
%setup -q

%build
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
CC="gcc -m32" CXX="g++ -m32"
CFLAGS=-m32
CFLAGS=`linux32 rpm --eval %%optflags|sed -e 's#i586#pentium4#g'` LDFLAGS="%{?ldflags}" 
#CC="%{__cc} -m32"

./configure  --shared --archs="-arch i386 -arch x86_64"

%make

%install
rm -rf %{buildroot}

%makeinstall_std

%clean
rm -fr %{buildroot}

%files -n %{lib_name}
%defattr(-, root, root)
%doc README
/usr/local/lib/*.so.*
/usr/local/lib/libz.a

%files -n %{develname}
%defattr(-, root, root)
%doc README ChangeLog doc/algorithm.txt
/usr/local/lib/pkgconfig/*.pc
/usr/local/include/*.h
/usr/local/lib/*.so
/usr/local/share/man/man3/zlib.3

%changelog
* Sun Apr 10 2016 tele <tele> 0.13.4-1pclos2016

My spec files maybe not are beautiful, but worked. I mean, Steam 32bit worked with 32bit mesa driver on 64 bit PCLinuxOS and Dota ( game ). More games not worked because need more 32bit dependencies. But for me this was great adventure and great success.

My conclusions: Nvidia can use driver 32bit for use other 64bit libs. I don't know how, but this is possible. My work turned out to be not useful, but my knowledge is bigger now. Most linux developers used second road with Mesa. I mean, they rebuild all needed dependencies and Mesa. This huge work, allows users with open source Mesa drivers install and run Steam games on Fedora, Arch Linux, Debian and maybe more. Thanks ! :-)

For me this topic is old and you can close. New user can always open a new topic.