32 位编译在 64 位 Ubuntu 16.04 上失败

32 位编译在 64 位 Ubuntu 16.04 上失败

问题描述:

我有一个应用程序需要使用 glib 和第三方提供的 32 位库.

I have an application that requires the use of glib and a 32 bit library supplied by a third party.

当我在 32 位 Ubuntu 上编译时,应用程序构建并成功运行.但是,当我在 64 位 Ubuntu 上尝试相同的操作时,由于以下错误而无法构建:

When I compile on 32 bit Ubuntu the application builds and runs successfully. However when I try the same on 64 bit Ubuntu it fails to build because of the following error:

/usr/include/glib-2.0/glib/gtypes.h: In function ‘_GLIB_CHECKED_ADD_U64’:
/usr/include/glib-2.0/glib/gmacros.h:217:53: error: size of array ‘_GStaticAssertCompileTimeAssertion_0’ is negative
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
                                                 ^
/usr/include/glib-2.0/glib/gmacros.h:214:47: note: in definition of macro ‘G_PASTE_ARGS’
#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
                                           ^
/usr/include/glib-2.0/glib/gmacros.h:217:44: note: in expansion of macro ‘G_PASTE’
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1] G_GNUC_UNUSED
                                        ^
/usr/include/glib-2.0/glib/gtypes.h:422:3: note: in expansion of macro ‘G_STATIC_ASSERT’
G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
^

注意:我有 gcc-multilib 和 g++-multilib.我还尝试将 /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h 中的定义从 8 更改为 4,但没有成功.我也尝试安装 libglib2.0-dev:i686 但 cmake 中的 pkg config 找不到 glib.我还为 C、CXX 和 LD 使用了适当的 -m32 标志

Note: I have gcc-multilib and g++-multilib. I also tried changing the defines inside /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h from 8 to 4 with no success. I also tried installing libglib2.0-dev:i686 but pkg config in cmake can not find glib. I am also using the appropriate -m32 flags for C, CXX and LD

对这个问题的任何帮助将不胜感激.

Any help with this issue would be greatly appreciated.

不知道为什么 glib 不尝试使用 int64_t 而不是复制它.对我来说似乎很傻.也许他们故意这样做是为了增加破坏的机会,如果你这样做,并尝试使用 64 位 glib 安装编译 32 位代码.

No idea why glib wouldn't try to use int64_t instead of duplicating that. Seems silly to me. Maybe they do this on purpose to increase the chance of breaking if you do what you did, and try to compile 32-bit code using a 64-bit glib install.

要编译 32 位应用程序,您需要 32 位库对象文件 (.so).他们将附带一个 glibconfig.h,它具有 -m32 的适当类型定义.

To compile 32-bit apps, you need 32-bit library object files (.so). They will come with a glibconfig.h that has appropriate typedefs for -m32.

安装 libglib2.0-dev:i686 应该是正确的方法.我假设您最终解决了这个问题,因此您正在构建的应用会找到 -I 包含路径和 -L 库路径.

Installing libglib2.0-dev:i686 should be the right approach. I assume you eventually got that sorted out, so the app you're building finds the -I include paths and -L library paths for it.