作者dryman (dryman)
看板EE_DSnP
标题Re: [问题] (非功课><)想问MAC上编译程式
时间Sun Nov 25 10:22:36 2012
身为老人来回一下XD
GNU/Linux 和 Mac OSX 虽然都是UNIX的作业环境
但是它们的kernel是完全不一样的系统
Linux是单核心,为潜在的硬体,提供了大量完善的硬体抽象操作。
Mac是微核心,结构由一个非常简单的硬体抽象层和一组比较关键的原语或系统呼叫组成
(後来改成混合核心,但还是比较偏向微核心)
核心详见
http://zh.wikipedia.org/zh-tw/内核
以不同核心为起点发展出来的bianry,也会不一样
GNU/Linux, BSD是用ELF
http://en.wikipedia.org/wiki/Executable_and_Linkable_Format
ELF was designed with the assumption that
there would be only one ABI per system architecture.
^^^ 与 kernel 沟通的介面
PS BSD 原本是用 UNIX 最初的a.out binary format
原本ELF是用模拟的方式运行的,但後来Linux太盛行了所以也改用 ELF
http://www.freebsd.org/doc/handbook/binary-formats.html
Mac OSX是用Mach-O
http://en.wikipedia.org/wiki/Mach-O
Mach-O 的一个特色是,可以包含不同格式的binary code进去一个档案
在过去,苹果有PowerPC-32, PowerPC-64, x86, x86-64等不同的机器
使用Mach-O可以制作fat binary file来让一个软体可在不同机器上运行
这归功於微核心强大的ABI介面 :D
Mach-O 还有双层命名空间的设计
可以避免dynamic library的变数及function打架
The two-level namespace feature of OS X v10.1 and later adds the
module name as part of the symbol name of the symbols defined
within it. This approach ensures a module’s symbol names don’t
conflict with the names used in other modules. To perform special
tasks or to provide an enhanced user experience, your application
may need to launch other applications or create processes to run
command-line tools. To maintain a high degree of interoperability
and provide a consistent user experience, your applications should
use specific system functions and frameworks to execute processes
and launch applications.
-- OSX Mach-O programming topics
结论是,如果你要使用Linux的ELF static library
那你就不能编译
而且我记得当年修课时,termios的相关程式码要稍微改一些才能在mac上面跑
还是使用linux吧,不要跟开发环境过不去XD
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.136.182.210
1F:→ XDucka:专业推 11/25 13:27
2F:推 ypf791:推 11/25 13:52
3F:推 kaiwen789:专业推!! 感谢学长的回答!!! 11/25 18:36