/**
@function GetInputSizeFromUsage
@abstract return frame width and height from usage
@param usage PPVEUsage to be inqure
@param width (out) the input width for usage
@param height (out) the input height for usage
*/
void GetInputSizeFromUsage(PPVEUsage usage, size_t *width, size_t *height);
#import <abc.h>
void GetInputSizeFromUsage(PPVEUsage usage, size_t *width, size_t *height)
{
switch(usage) {
case UsageLandscape848x480:
*width = 848;
*height = 480;
break;
default:
*width = 0;
*height = 0;
break;
}
}
// This file uses this above function in various other functions and is fine to compile
#import <abc.h>
size_t GetInputSizeFromUsage(PPVEUsage usage)
{
size_t width, height;
GetInputSizeFromUsage(usage, &width, &height);
return (width * height);
}
错误: 未定义符号:GetInputSizeFromUsage(PPVEUsage, unsigned long*, unsigned long*)
该错误是由于 file2.mm 无法看到该符号造成的。如果我在 file2.mm 中将其注释掉,它可以正常编译。
期望它能够看到符号
Objective-C++ 是 C++ 语言的超集,C++ 的所有规则都适用于此。 IE。声明函数时,您必须处理所谓的“名称修改”,它会以编译器无法在 Objective-C/C 编译单元中找到它的方式更改函数签名。对于这种情况,您应该通过使用 extern "C"
部分告诉链接器在将此标头包含在 C++ 编译单元中时应用 C 规则:
#ifdef __cplusplus
extern "C" {
#endif
void GetInputSizeFromUsage(PPVEUsage usage, size_t *width, size_t *height);
#ifdef __cplusplus
}
#endif