在OS X上编译C程序以在Linux上运行 [英] Compiling C Program on OS X to Run on Linux

查看:114
本文介绍了在OS X上编译C程序以在Linux上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的C程序,仅使用标准库函数进行一些密码计算.

I have a pretty simple C program that does some cryptographic calculations using only standard library functions.

我将在Ubuntu(10.04,32位)上运行该程序,并使用带有-m32标志的cc在OS X 10.6上对其进行编译.当我尝试在Ubuntu上运行它时,出现错误消息无法执行二进制文件."

I will be running the program on Ubuntu (10.04, 32 bit) and compiled it on OS X 10.6 using cc with the -m32 flag. When I tried to run it on Ubuntu I got the error message "cannot execute binary file."

当我在Ubuntu上编译它时,它运行良好.

When I compile it on Ubuntu it runs fine.

有没有简单的方法可以将OS X上的代码编译为可以在Ubuntu上运行的二进制文件?如果不是,那么导致二进制文件不兼容的差异是什么?

Is there any easy way to compile code on OS X into a binary that will run on Ubuntu? If not, what are the differences that cause the binary to be incompatible?

推荐答案

恐怕您无法提供gcc的最小可移植性.

I'm afraid you can't given the minimum portability of gcc.

当然,您可以像这样构建交叉编译器 ,但我建议您使用用ubuntu虚拟机进行编译.

Of course you can build a cross compiler like this but I'll suggest you to use and compile with an ubuntu virtual machine.

这篇关于在OS X上编译C程序以在Linux上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆