cocoa - HICococaView 未使用 GCC 4.2 进行编译

标签 cocoa xcode gcc macos-carbon

我们有一个大型的基于 Carbon (PowerPlant) 的应用程序,我们最终希望将其移植到 Cocoa 上。我们将逐步执行此操作,第一步是尝试在 Carbon 窗口中获取 Cocoa View 。

问题似乎是,当我使用 HICOcoaView.h 中的任何函数时,除非我将编译器从 GCC 4.2 切换到 GCC 4.0,否则应用程序将无法编译。

使用 GCC 4.0 以外的任何编译器时,我在 XCode 中收到错误,指出函数不可用,例如“HICocoaViewCreate 不可用”。

我不明白为什么这不起作用,我们是否必须切换到较旧的编译器,或者是否可以更改一些设置来使其编译?

非常感谢任何有关将 Carbon 移植到 Cocoa 的帮助或有用文档的指示。我已经阅读了旧的 Carbon Cocoa Integration 指南,但它没有提到这一点。

编辑:根据要求,这里是 gcc 命令行构建的输出:-

/Developer/usr/bin/gcc-4.2 -x objective-c++ -arch i386 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wmissing-prototypes -Wreturn-type -Wunused-variable -Wunused-value -D__IMPRO_DEBUG_BUILD__ -isysroot /Developer/SDKs/MacOSX10.5.sdk -mfix-and-continue -mmacosx-version-min=10.5 -gdwarf-2 "-I/Users/matt/Code/MattsFeatureBranch/Modules/User Notes/Mac/../../../(Intermediates)/Debug/User Notes.build/Debug/Module Bundle.build/User Notes.hmap" -Wparentheses -Wno-conversion -Wno-sign-compare -Wno-multichar -Wno-deprecated-declarations "-F/Users/matt/Code/MattsFeatureBranch/Modules/User Notes/Mac/../../../Build Products/Mac/Debug/Plugins" "-F../../../Build Products/Mac/Debug" "-F../../../Third Party/Mac/NVidia" "-I/Users/matt/Code/MattsFeatureBranch/Modules/User Notes/Mac/../../../Build Products/Mac/Debug/Plugins/include" -I../X-Platform -I../../../Common/Mac -I../../../Common/X-Platform -I../../../DLLs/ArcadiaCore/Mac -I../../../DLLs/ArcadiaCore/X-Platform "-I../../../Third Party/Mac/Powerplant" -I/Developer/SDKs/MacOSX10.5.sdk/Developer/Headers/FlatCarbon "-I../../../Third Party/X-Platform/boost_1_38_0" -I../../../DLLs/ArcadiaImaging/Mac -I../../../DLLs/ArcadiaImaging/X-Platform -I../../../DLLs/ArcadiaDatabase/Mac -I../../../DLLs/ArcadiaDatabase/X-Platform -I../../../DLLs/ArcadiaUI/Mac -I../../../DLLs/ArcadiaUI/X-Platform "-I../../../Third Party/Mac/Powerplant Extras" -I../../../DLLs/ArcadiaDevices/Mac -I../../../DLLs/ArcadiaDevices/X-Platform -I../../../DLLs/Arcadia3D/Mac -I../../../DLLs/Arcadia3D/X-Platform "-I/Users/matt/Code/MattsFeatureBranch/Modules/User Notes/Mac/../../../(Intermediates)/Debug/User Notes.build/Debug/Module Bundle.build/DerivedSources/i386" "-I/Users/matt/Code/MattsFeatureBranch/Modules/User Notes/Mac/../../../(Intermediates)/Debug/User Notes.build/Debug/Module Bundle.build/DerivedSources" -fpermissive -fasm-blocks -include "/Users/matt/Code/MattsFeatureBranch/Modules/User Notes/Mac/../../../(Intermediates)/Debug/SharedPrecompiledHeaders/XPrefix-acshmfbgvfwrdqbyayvgnckkypgr/XPrefix.h" -c "/Users/matt/Code/MattsFeatureBranch/Modules/User Notes/Mac/MUserNotesView.cpp" -o "/Users/matt/Code/MattsFeatureBranch/Modules/User Notes/Mac/../../../(Intermediates)/Debug/User Notes.build/Debug/Module Bundle.build/Objects-normal/i386/MUserNotesView.o"

最佳答案

来自 10.5 和 10.6 SDK 中的 HICOcoaView.h:

#if !__LP64__
extern OSStatus
HICocoaViewCreate(
  NSView *     inNSView,        /* can be NULL */
  OptionBits   inOptions,
  HIViewRef *  outHIView)                                                       AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER;
…
#endif  /* !__LP64__ */

这意味着 HICocoaViewCreate() 在 64 位 (LP64) 目标上不可用,即,如果您需要使用此函数,则必须以 i386 为目标(或 PowerPC)。

即使在支持 64 位的机器上运行,GCC 4.0 默认也以 i386 为目标。另一方面,GCC 4.2 在 64 位机器上默认以 x86_64 为目标:

$ gcc-4.0 a.c; lipo -info a.out
Non-fat file: a.out is architecture: i386

$ gcc-4.2 a.c; lipo -info a.out
Non-fat file: a.out is architecture: x86_64

如果您想同时使用 HICocoaViewCreate() 和 GCC 4.2,请通过传递 -arch i386 告诉它创建(并使用)32 位对象/二进制文件。例如,

$ gcc-4.2 a.c -arch i386; lipo -info a.out
Non-fat file: a.out is architecture: i386
<小时/>

尽管 Carbon 的一部分可用于 64 位目标,但您会在 64-bit Guide for Carbon Developers 中注意到HIToolbox 的大部分功能根本不可用。

至于从 Carbon 迁移到 Cocoa,很大程度上是一个全新的 Objective-C API。我不知道有任何简单的迁移指南,并且 Peter Hosey’s answer to a similar question on Stack Overflow值得一读。

关于cocoa - HICococaView 未使用 GCC 4.2 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4757277/

相关文章:

objective-c - 使用 NSPredicate 遍历多个 Core Data 对象

xcode - 如何使用本地网络上的主机名连接TCP套接字

gcc - 浮点异常在新的 gfortran 版本中发出信号

ruby - 无法编译 ruby​​ 扩展 : CPU you selected does not support x86-64 instruction set

iphone - 滚动以在 UIView 中加载内容

cocoa - MacRuby/Cocoa 中文本 (NSFont) 渲染效果不佳。有什么建议吗?

macos - 如何实现文件日志记录以使日志不会无限制地增长?

ios - UITextField 上的强密码覆盖

iphone - 如何在 iPhone 中显示从 URL 下载的图像?

c++ - GCC 的 undefined reference /多重定义错误