制作 32 位和 64 位版本库的指南(在 Linux 中)

发布于 2024-12-29 15:35:48 字数 772 浏览 5 评论 0原文

我在 Ubuntu 中安装了 64 位构建环境。假设我下载了某个库的源代码,并且我想使用单个源代码构建它的 32 位和 64 位版本。

该库附带 ./configure 脚本,因此有人可以成功地将其配置为 64 位版本,如下所示:

./configure --prefix=/opt/libtvzombie --with-opengl --with-other-option1

... 并将其构建并安装到 /opt/libtvzombie ,如下所示:

make
sudo make install
sudo sh -c 'echo /opt/libtvzombie/lib > /etc/ld.so.conf.d/tvzombie.conf'
sudo ldconfig

问题是:

  1. 如何强制普通的 ./configure 脚本在 64 位系统上以 32 位模式进行编译?我知道我可以在 g++ 中使用 -m32 编译开关,但这不是 autotools 的方式,因为 ./configure 识别出我正在 64 位环境中进行编译。

  2. 我需要将此 32 位版本安装到哪里?也许到 /opt/libzombie32

  3. 32 位和 64 位版本的同名库不会出现名称冲突吗?

I have a 64 bit build environment installed in Ubuntu. Let's say I downloaded a source code of some library and I'd like to build 32 and 64 bit versions of it using single source code.

The library comes with ./configure script so someone may successfully configure it for 64 bit version like this:

./configure --prefix=/opt/libtvzombie --with-opengl --with-other-option1

... and build and install it to /opt/libtvzombie as follows:

make
sudo make install
sudo sh -c 'echo /opt/libtvzombie/lib > /etc/ld.so.conf.d/tvzombie.conf'
sudo ldconfig

The questions are:

  1. How can I force the average ./configure script to compile in 32 bit mode on a 64 bit system? I know I can use -m32 compile switch with g++, but that's not the way with autotools, because ./configure recognizes that I’m compiling in a 64 bit environment.

  2. Where do I need to install this 32 bit version to? Maybe to /opt/libzombie32?

  3. Won't there be any name conflicts between 32 bit and 64 bit versions of the library with the same name?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

再浓的妆也掩不了殇 2025-01-05 15:35:48

由于configure不知道-m32标志意味着“32位”(毕竟,它可能意味着与另一个编译器完全不同的东西 - 它甚至可能被拒绝,例如在ia64上),你应该还告诉它主机类型。如果程序是这样编码的,主机类型也可以用于选择独立于 CC 和 CFLAGS 的某些行为,如果您要运行的配置不是自动检测的配置,则应始终指定 --host=。

./configure --host=i686-linux-gnu CFLAGS="-m32" LDFLAGS="-m32"

Since configure does not know that the -m32 flag means "32-bit" (after all, it could mean something completely different with another compiler—it might even be rejected, e.g. on ia64), you should also tell it the host type. The host type may, if the program is so coded, also be used to select certain behavior independent of CC and CFLAGS, --host= should always be specified if the config you want to run as is not the one that is autodetected.

./configure --host=i686-linux-gnu CFLAGS="-m32" LDFLAGS="-m32"
随心而道 2025-01-05 15:35:48

如果要安装在/opt/libzombie32中,只需指定--prefix=/opt/libzombie32并在CFLAGS中指定-m32即可。就我个人而言,我认为为每个包安装在单独的目录中是一个坏主意,你最好这样做:

$ sudo sh -c 'echo CFLAGS="$CFLAGS -m32" > /opt/lib32/share/config.site'

然后使用 --prefix=/opt/lib32 进行配置。通过在 config.site 中指定 CFLAGS,任何使用 --prefix=/opt/lib32 配置的自动工具项目都将获得 CFLAGS 中指定的 -m32。您可能还想指定 CXXFLAGS 来处理 C++。

If you want to install in /opt/libzombie32, you just need to specify --prefix=/opt/libzombie32 and specify -m32 in CFLAGS. Personally, I think it is a bad idea to install in a separate directory for each package, and you'd be better off doing something like:

$ sudo sh -c 'echo CFLAGS="$CFLAGS -m32" > /opt/lib32/share/config.site'

And then configure with --prefix=/opt/lib32. By specifying CFLAGS in the config.site, any autotooled project configured with --prefix=/opt/lib32 will get -m32 specified in CFLAGS. You may want to specify CXXFLAGS as well, to handle C++.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文