Mac OSX是否应具有“ malloc.h”文件?

时间:2019-06-05 14:56:14

标签: c macos include-path

客户的代码期望在“通常的可疑”位置之一中找到包含文件malloc.h。在我的Mac AFAICT上,没有malloc.h,至少没有在您希望找到的任何地方,例如/usr/include/usr/local/include/opt/local/include。由于malloc()通常是在stdlib.h中定义的,并且由于代码无论如何都包含stdlib.h,因此我只需注释掉malloc.h的少数几个包含项就可以构建代码。我正在与gcc建立。

但是有两个问题:我的gcc是否以某种方式弄乱了?该文件应该在那里吗?另外,代码炸弹几乎立即出现段错误,但我还无法找到。这可能是使用错误的malloc()的结果吗?

2 个答案:

答案 0 :(得分:4)

malloc.h已过时,不应使用。它也包含一些非标准功能。如果要使用malloc,请添加stdlib.h。甚至C89标准都没有提到malloc.h

如果是造成您问题的原因,我不知道,但这很有可能。

答案 1 :(得分:0)

下面的清单可以提供关于应该/应该在哪里找到文件的想法。不过,我无法在没有更多细节的情况下解释该段错误。我看不到它如何与malloc()有任何关系。

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/malloc.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/malloc/malloc.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/malloc/malloc.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/malloc/malloc.h
$