我可以使用 Macports 编译通用代码吗?海湾合作委员会?

发布于 2024-12-21 08:04:56 字数 567 浏览 1 评论 0原文

由于 Apple 不支持 GCC 4.6 或 GCC 4.7,我只是切换到 MacPorts 的 GCC 4.6/4.7 版本。但是,我在“通用”架构中构建代码时遇到了问题。

传统上,我会执行 g++ -arch i386 -arch x86_64 ... 来编译至少适用于 i386/x86_64 架构的二进制文件。我做了一些搜索,并意识到 -arch 选项仅受苹果编译器支持。所以当然它不适用于Macports。我能做的最好的事情就是使用 -m32/-m64 选项来指定我想要的架构。但是,这只会生成 i386 或 x86_64 格式的二进制文件。我真正想要的是在两种架构(通用)中获得一个二进制文件,就像原始 GCC 编译器所做的那样。

这是不受支持还是已知问题?我整晚都在谷歌上寻找答案,但没有得到任何有用的东西。所以我开始怀疑我是否是唯一一个遇到这个问题的人,并且我错过了一些使其发挥作用的真正重要的东西?如果有人能给我一些建议,我真的很感激。

顺便提一句。我已经安装了 gcc46 +universal 变体,但除了为每个体系结构编译单独的二进制文件之外,它没有产生任何真正通用的东西。

兴。

Since Apple do not support GCC 4.6 or GCC 4.7, I just switched to MacPorts' build of GCC 4.6/4.7. However, I had a problem to build my code in "Universal" architecture.

Traditionally, I'd do g++ -arch i386 -arch x86_64 ... to compile my binary for at least i386/x86_64 architecture. I did some search, and realised that -arch option is only supported by apple's compilers. So of course it didn't work with the Macports'. The best I could do is use -m32/-m64 options to specify an architecture I want. However, this will only produce a binary eitherr in i386 or x86_64 format. What I really want is get a binary file in both architecture (Universal) just as been done with the original GCC compilers.

Is this not supported or a known problem? I have tried the whole night looking for answers on Google, but I haven't get anything useful. So I just start doubt if I am the only one had this problem and I have missed something really important to get it work? Really appreciate if anyone can give me some suggestions.

BTW. I have installed gcc46 +universal variants, but it didn't produce anything really universal except compiling separate binaries for each architecture.

Xing.

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

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

发布评论

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

评论(2

时光瘦了 2024-12-28 08:04:56

哦,我刚刚遇到了这个问题,并花了相当多的时间来解决它。事实证明,GCC 4.2.1 的苹果版本实际上只是一个包装器,它遵循一些标志(特别是 -arch 标志),然后使用 lipo 将对象文件重新组合成一个胖对象。我稍微修改了这个驱动程序,以便它可以包装 macports GCC,同时仍然遵循 -arch 标志并生成多 arch 对象文件(无论如何,对于 32 位和 64 位 intel)。

我刚刚发布了一篇关于如何执行此操作的相当广泛的文章:

http://thecoderslife.blogspot.com/2015/07/building-with-gcc-46-and-xcode-4.html

Oh, I just had this problem and spent a pretty extensive amount of time on it. It turns out that the apple version of GCC 4.2.1 is really just a wrapper that honors a few flags (notably the -arch flag) and then uses lipo to stick the object files back together into a fat object. I modified this driver a bit so that it would wrap macports GCC while still honoring the -arch flag and produce multi arch object files (for 32 bit and 64 bit intel anyway).

I just posted a fairly extensive write up on how to do this:

http://thecoderslife.blogspot.com/2015/07/building-with-gcc-46-and-xcode-4.html

单挑你×的.吻 2024-12-28 08:04:56

您可以使用 lipo

You can combine binaries with different architectures in to a single universal using lipo.

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