Обсуждение: Compile errors when building 32-bit on 64-bit system

Поиск
Список
Период
Сортировка

Compile errors when building 32-bit on 64-bit system

От
Andy Shellam
Дата:
I was going to post this to pgsql-hackers but figured it might be more
suitable on this list first.  I'm trying to compile a 32-bit PostgreSQL
client on a 64-bit system, however the SPI module is not respecting the
CFLAGS and LDFLAGS option "-m32."

My configure line is as follows:

CFLAGS="-m32" LD="ld -m32 -melf_i386" ./configure
--prefix=/opt/nmail32/pgsql --enable-thread-safety --with-openssl
--with-libxml --with-includes="..." --with-libraries="..."

All libraries listed in the --with-libraries are 32-bit.  The "make"
command fails at the "contrib/spi" module with the error:

/usr/bin/ld: warning: i386 architecture of input file `refint.o' is
incompatible with i386:x86-64 output

The 2 commands before it are:

gcc -m32 -Wall -Wmissing-prototypes -Wpointer-arith -Winline
-Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing
-fwrapv -fpic -DREFINT_VERBOSE -I. -I../../src/include -D_GNU_SOURCE
-I/opt/nmail32/libxml2/include/libxml2 -I/opt/nmail32/zlib/include
-I/opt/nmail32/readline/include -I/opt/nmail32/openssl/include  -c -o
refint.o refint.c
gcc -shared -o refint.so refint.o

The first command (the compile) has the "-m32" flag set, however the
linking command doesn't - causing the above message.  If I run the above
2 commands manually, but add "-m32" in the second one (i.e. gcc -m32
-shared -o refint.so refint.o) it succeeds.  The same failure also
occurs for the "autoinc.c" file in the same contrib module.

Thanks,
Andy


Re: Compile errors when building 32-bit on 64-bit system

От
Tom Lane
Дата:
Andy Shellam <andy-lists@networkmail.eu> writes:
> I was going to post this to pgsql-hackers but figured it might be more
> suitable on this list first.  I'm trying to compile a 32-bit PostgreSQL
> client on a 64-bit system, however the SPI module is not respecting the
> CFLAGS and LDFLAGS option "-m32."

> My configure line is as follows:

> CFLAGS="-m32" LD="ld -m32 -melf_i386" ./configure

Doubtless, your problem is that you're setting LD not LDFLAGS.

            regards, tom lane

Re: Compile errors when building 32-bit on 64-bit system

От
Andy Shellam
Дата:
Tom,

> Doubtless, your problem is that you're setting LD not LDFLAGS.
>

Nope, I originally had LDFLAGS set to "-m32" instead of LD, and it
failed with another error trying to link the localtime.o object (which
it had compiled as 64-bit) to create SYS-something-or-other.o (which it
was trying to create as 32-bit.)  A quick Google revealed setting that
flag in the LD environment variable, which got it a bit further but then
bought up this error.

Everything else compiled fine then, it's just the contrib/spi module.

Andy

Re: Compile errors when building 32-bit on 64-bit system

От
Tom Lane
Дата:
Andy Shellam <andy-lists@networkmail.eu> writes:
> Tom,
>> Doubtless, your problem is that you're setting LD not LDFLAGS.

> Nope, I originally had LDFLAGS set to "-m32" instead of LD, and it
> failed with another error trying to link the localtime.o object (which
> it had compiled as 64-bit) to create SYS-something-or-other.o (which it
> was trying to create as 32-bit.)

That sounds like you hadn't yet figured out to set CFLAGS too.

> A quick Google revealed setting that
> flag in the LD environment variable, which got it a bit further but then
> bought up this error.

Google or no Google, you're setting the wrong variable.

You might possibly have better luck using 8.4 for this, as we got rid of
the intermediate SUBSYS.o files, which tend to confuse matters in a
multiarch environment.

            regards, tom lane

Re: Compile errors when building 32-bit on 64-bit system

От
Andy Shellam
Дата:
Tom,
> That sounds like you hadn't yet figured out to set CFLAGS too.
>
Actually if you see my first post, the only thing I'd changed was
replaced "LDFLAGS="-m32"" with the "LD" variable and I had also tried
adding that back in alongside CFLAGS and LD but to no avail.

I compiled the module by hand - all that required was the linking
command that compiled the two files for the contrib/spi module to have
the flag "-m32" as defined in the configure line.
> Google or no Google, you're setting the wrong variable.
>
Like I said, I had already tried LDFLAGS (and, yes, CFLAGS too) which
threw up the problem with the SUBSYS.o file.
> You might possibly have better luck using 8.4 for this, as we got rid of
> the intermediate SUBSYS.o files, which tend to confuse matters in a
> multiarch environment.
>
I'm due to migrate onto 8.4 shortly so we'll see how things go then.


Re: Compile errors when building 32-bit on 64-bit system

От
Andy Shellam
Дата:
> That sounds like you hadn't yet figured out to set CFLAGS too.
>
> Google or no Google, you're setting the wrong variable.
>

I had to install PG 8.3.7 on another couple of machines today, and got
exactly the same issue (setting all 3 variables) again on the SPI
module.  Please see as follows:

Configure line:  CFLAGS="-m32" LD="ld -melf_i386" LDFLAGS="-m32"
./configure .... etc ....

"make" fails with the error:

gcc -shared -o refint.so refint.o
/usr/bin/ld: warning: i386 architecture of input file `refint.o' is
incompatible with i386:x86-64 output
refint.o: In function `check_primary_key':
refint.c:(.text+0x8f): undefined reference to `elog_start'
refint.c:(.text+0xa5): undefined reference to `elog_finish'
... etc ...

Running the following commands manually allows the install to continue -
notice how I have to add "-m32" to the second gcc command:

# cd contrib/spi
# gcc -m32 -Wall -Wmissing-prototypes -Wpointer-arith -Winline
-Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing
-fwrapv -fpic -DREFINT_VERBOSE -I. -I../../src/include -D_GNU_SOURCE
-I/opt/nmail32/libxml2/include/libxml2
-I/opt/nmail32/libxml2/include/libxml2 -I/opt/nmail32/zlib/include
-I/opt/nmail32/readline/include -I/opt/nmail32/openssl/include
-I/opt/nmail32/ncurses/include  -c -o refint.o refint.c
# gcc -m32 -shared -o refint.so refint.o

And the same for "autoinc.o":

# gcc -m32 -Wall -Wmissing-prototypes -Wpointer-arith -Winline
-Wdeclaration-after-statement -Wendif-labels -fno-strict-aliasing
-fwrapv -fpic -DREFINT_VERBOSE -I. -I../../src/include -D_GNU_SOURCE
-I/opt/nmail32/libxml2/include/libxml2
-I/opt/nmail32/libxml2/include/libxml2 -I/opt/nmail32/zlib/include
-I/opt/nmail32/readline/include -I/opt/nmail32/openssl/include
-I/opt/nmail32/ncurses/include  -c -o autoinc.o autoinc.c
# gcc -m32 -shared -o autoinc.so autoinc.o

# make
........
All of PostgreSQL successfully made. Ready to install.

So it appears the SPI module is respecting CFLAGS, but ignoring LDFLAGS.

Re: Compile errors when building 32-bit on 64-bit system

От
Tom Lane
Дата:
Andy Shellam <andy-lists@networkmail.eu> writes:
> I had to install PG 8.3.7 on another couple of machines today, and got
> exactly the same issue (setting all 3 variables) again on the SPI
> module.  Please see as follows:

FWIW, it does appear that 8.4 makes this better.

            regards, tom lane

Re: Compile errors when building 32-bit on 64-bit system

От
Andy Shellam
Дата:
> FWIW, it does appear that 8.4 makes this better.
>

OK cheers, I have got plans to migrate over the next month or two; just
wanted to point out the issue.

Andy