尝试在 64 位计算机上构建 32 位应用程序时跳过不兼容的库

问题描述 投票:0回答:1

我尝试将我的应用程序(使用 Makefile)制作为 64 位计算机上的 32 位应用程序。由于

skipping incompatible
消息和
cannot find -l<library>
消息,链接阶段失败。

  • 编程语言:C
  • LSB版本:
    core-4.1-amd64:core-4.1-ia32:core-4.1-noarch
  • 操作系统:
    CentOS Linux release 7.6.1810 (Core)
  • 海湾合作委员会版本:
gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  • 安装了很多库,我相信我得到了所有 32 位版本。
  • 有关 GCC 的 yum 信息:
sudo yum info gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: download.cf.centos.org
 * epel: d2lzkl7pfhq30w.cloudfront.net
 * extras: download.cf.centos.org
 * updates: download.cf.centos.org
Installed Packages
Name        : gcc
Arch        : x86_64
Version     : 4.8.5
Release     : 44.el7
Size        : 37 M
Repo        : installed
From repo   : base
Summary     : Various compilers (C, C++, Objective-C, Java, ...)
URL         : http://gcc.gnu.org
License     : GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
Description : The gcc package contains the GNU Compiler Collection version 4.8.
            : You'll need this package in order to compile C code.

这是结果的子集:

/usr/bin/ld: skipping incompatible /home/<User>lib/odbc/3.0/libodbcifV3_10.so when searching for -lodbcifV3_10
/usr/bin/ld: cannot find -lodbcifV3_10
/usr/bin/ld: cannot find -lodbcbaseV3_28
/usr/bin/ld: cannot find -lodbcdV3_28
/usr/bin/ld: cannot find -lodbccV3_28
/usr/bin/ld: skipping incompatible /usr/local/easysoft/unixODBC/lib//libodbc.so when searching for -lodbc
/usr/lib/libaspell.so: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
make: *** [wmscentosdev2/webClient] Error 1
[<User>:v10_odbc:V3_28:mysql]> objdump -a /home/<User>lib/odbc/3.0/libodbcifV3_10.so 

/home/<User>lib/odbc/3.0/libodbcifV3_10.so:     file format elf32-i386
/home/<User>lib/odbc/3.0/libodbcifV3_10.so

[<User>:v10_odbc:V3_28:mysql]> objdump -a wmscentosdev2/clientMain.o                        

wmscentosdev2/clientMain.o:     file format elf32-i386
wmscentosdev2/clientMain.o

[<User>:v10_odbc:V3_28:mysql]> 

顺便说一句,忽略拼写问题,我想我需要重新编译那个问题,因为这是一个完全不同的问题。

我添加了

-m32
,目标文件看起来不错,
file
说它们是386个文件(
file format elf32-386
)。但是当它尝试链接文件时,它找不到各种共享库,给出“跳过不兼容”消息。当我查看共享库时,它们也是相同的文件格式。事实上,它们在我的生产机器上运行良好。我只是无法针对它们进行编译。我什至尝试添加
-march=i686
-march=i386
,万一链接器仍在查看 64 位内容。请注意,它找不到的东西就在那里,就在它说正在搜索的地方,只是出于某种原因不喜欢它们。

我可以很好地编译静态库,因此编译阶段似乎可以工作。据我所知,生成的“.a”文件具有与上面相同的文件格式。

是的,我安装了开发库、静态库等。在 CentOS 上,我找不到这些库的 multilib 版本。我安装了 i686 变体。也许问题是这些库是在旧机器上用 i386 变体编译的?这会引起问题吗?

最后,我制作了一个简单的 hello world 应用程序,它编译得很好。

> objdump -a hello64

hello64:     file format elf64-x86-64
hello64

> objdump -a hello64

hello64:     file format elf64-x86-64
hello64

> hello64
Hello World!
> objdump -a hello32

hello32:     file format elf32-i386
hello32

> hello32
Hello World!

由于上述工作有效,我认为它是我的 makefile 中隐藏的东西。它们非常复杂。否则我就把它们放在这里。我认为这种复杂性中隐藏的某些东西导致了问题,但我无法轻松地简化它以隔离问题。我怎样才能找出不匹配的地方?有没有办法告诉链接器更明确地指出错误在哪里?

顺便说一句,这些应用程序在较旧的 32 位系统上编译得很好,所以这不是应用程序本身。

我也许能够重新编译其中一些

so
文件,但我无法重新编译所有这些文件 - 我没有一两个文件的源代码。

抱歉,如果我错过了一个明显的帖子。有很多关于此类问题的帖子,大多数都提到了我已经尝试过的上述事情的一些变化。也许我只是需要听到不同的解释。

c makefile centos7
1个回答
0
投票

看来你做这件事很困难。我希望

CC=/usr/bin/i686-linux-gnu-gcc make
能够修复您所有的库路径。

简化交叉编译的技巧是对每个单独的调用(包括链接调用)使用 $(CC)。这实际上适用于 .s 文件(通常不应该有)。

© www.soinside.com 2019 - 2024. All rights reserved.