Xcode print symbol not found for my C function which used in Objective-C method body

拜拜、爱过 提交于 2019-12-23 03:29:11

问题


Xcode build prints this error .

Undefined symbols:
"EGViewportDimensionMake(unsigned int, unsigned int, unsigned int, unsigned int)", referenced from: -[Renderer render] in Renderer.o ld: symbol(s) not found collect2: ld returned 1 exit status

I cannot figure out what's the problem. I'm not good at classic C syntax. These are the function source code files:

EGViewportDimension.h

#import <Foundation/Foundation.h>

struct EGViewportDimension
{
    NSUInteger x;
    NSUInteger y;
    NSUInteger width;
    NSUInteger height;
};
typedef struct EGViewportDimension EGViewportDimension;

EGViewportDimension EGViewportDimensionMake(NSUInteger x, NSUInteger y, NSUInteger width, NSUInteger height);

EGViewportDimension.m

#import "EGViewportDimension.h"

EGViewportDimension EGViewportDimensionMake(NSUInteger x, NSUInteger y, NSUInteger width, NSUInteger height)
{
    EGViewportDimension dim;
    dim.x = x;
    dim.y = y;
    dim.width = width;
    dim.height = height;
    return dim;
}

I referenced and used this like:

Renderer.mm

#import "EGViewportDimension.h"

//.... many codes omitted.

EGViewportDimension vdim = EGViewportDimensionMake(0, 0, backingWidth, backingHeight);

回答1:


This is not a compiler but a linker issue. You referenced this method from [Renderer render], however the linker is unable to find it. Did you check you have included EGViewportDimension.h at the appropriate place (eg. Renderer.m)?




回答2:


I solved it by renaming Renderer.mm to Renderer.m. It was used some C++ classes so I made it as Objective-C++ code, but there was some problem. I removed all C++ calls and renamed it to Objective-C code.

But I still don't know what's the problem with Objective-C++ with classic C function definition.

----(edit)----

I asked this as another question, and I got an answer. See here: Does it prohibited calling classic C function from Objective-C++ class method body?



来源:https://stackoverflow.com/questions/2213589/xcode-print-symbol-not-found-for-my-c-function-which-used-in-objective-c-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!