i386架构未定义的符号,ld:i386架构中找不到符号。

4

我又遇到了阻碍,情况如下:

Undefined symbols for architecture i386:
  "CreateRenderer1()", referenced from:
      -[GLView initWithFrame:] in GLView.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我尝试了几乎所有自动搜索问题时显示的建议:

在“Build Phases”选项卡下的“Link Binary With Libraries”中添加这些库:

OpenGLES.framework
QuartzCore.framework

将所有相关文件添加到目标/编译源中。

将所有扩展名为.m的相关文件重命名为.mm。

我正在尝试在Xcode 4.3.2上的iPhone 5.1模拟器上编译此代码,有什么明显的问题吗?我觉得可能是设置方面的问题,但我尝试过的所有内容似乎都不起作用 =(

编辑:

GLView.h:

#import "IRenderingEngine.hpp"
#import <OpenGLES/EAGL.h>
#import <QuartzCore/QuartzCore.h>

@interface GLView : UIView {
    EAGLContext* m_context;
    IRenderingEngine* m_renderingEngine;
    float m_timestamp;
}

- (void) drawView: (CADisplayLink*) displayLink;
- (void) didRotate: (NSNotification*) notification;

@end

GLView.mm:

#import <OpenGLES/EAGLDrawable.h>   
#import "GLView.h"
#import "mach/mach_time.h"
#import <OpenGLES/ES2/gl.h> // <-- for GL_RENDERBUFFER only

@implementation GLView

+ (Class) layerClass
{
    return [CAEAGLLayer class];
}

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        CAEAGLLayer* eaglLayer = (CAEAGLLayer*) super.layer;
        eaglLayer.opaque = YES;
        m_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];

        if (!m_context || ![EAGLContext setCurrentContext:m_context]) {
            [self release];
            return nil;
        }

        m_renderingEngine = CreateRenderer1();

        [m_context
         renderbufferStorage:GL_RENDERBUFFER
         fromDrawable: eaglLayer];

        m_renderingEngine->Initialize(CGRectGetWidth(frame), CGRectGetHeight(frame));

        [self drawView: nil];
        m_timestamp = CACurrentMediaTime();

        CADisplayLink* displayLink;
        displayLink = [CADisplayLink displayLinkWithTarget:self
                                                  selector:@selector(drawView:)];

        [displayLink addToRunLoop:[NSRunLoop currentRunLoop]
                          forMode:NSDefaultRunLoopMode];

        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

        [[NSNotificationCenter defaultCenter]
         addObserver:self
         selector:@selector(didRotate:)
         name:UIDeviceOrientationDidChangeNotification
         object:nil];
    }
    return self;
}


- (void) didRotate: (NSNotification*) notification
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    m_renderingEngine->OnRotate((DeviceOrientation) orientation);
    [self drawView: nil];
}

- (void) drawView: (CADisplayLink*) displayLink
{
    if (displayLink != nil) {
        float elapsedSeconds = displayLink.timestamp - m_timestamp;
        m_timestamp = displayLink.timestamp;
        m_renderingEngine->UpdateAnimation(elapsedSeconds);
    }

    m_renderingEngine->Render();
    [m_context presentRenderbuffer:GL_RENDERBUFFER];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end

IRenderingEngine.hpp

enum DeviceOrientation {
    DeviceOrientationUnknown,
    DeviceOrientationPortrait,
    DeviceOrientationPortraitUpsideDown,
    DeviceOrientationLandscapeLeft,
    DeviceOrientationLandscapeRight,
    DeviceOrientationFaceUp,
    DeviceOrientationFaceDown,
};

// Creates an instance of the renderer and sets up various OpenGL state.
struct IRenderingEngine* CreateRenderer1();

// Interface to the OpenGL ES renderer; consumed by GLView.
struct IRenderingEngine {
    virtual void Initialize(int width, int height) = 0;    
    virtual void Render() const = 0;
    virtual void UpdateAnimation(float timeStep) = 0;
    virtual void OnRotate(DeviceOrientation newOrientation) = 0;
    virtual ~IRenderingEngine() {}
};

你的项目中是否已经添加了GLKit.framework? - danielbeard
你能展示一下初始化视图的代码吗? - danielbeard
对于第一个问题,不,我现在会在主要问题中编辑视图! - Hobbyist
你的IRenderingEngine可能未添加到目标中,或者无法找到其实现。这些方法是否在任何地方被实现? - danielbeard
扶额 好吧,我不知怎么把它们删了,浪费了一些时间来调试这个问题,我会重新做一遍,看看接下来会发生什么! - Hobbyist
好的,我会将这个作为回答添加。 - danielbeard
2个回答

2

编译器找不到您的IRenderingEngine实现。要么是实现丢失了,要么是文件没有正确添加到目标中。


0

尽管我已经修复了它,但我从来没有真正理解文件是如何“删除”的,今天我找到了答案:

如果您手动在Finder中重命名任何子文件夹,则XCode仍将指向旧路径,该路径现在无效。

为解决此问题,我右键单击无效的组文件夹,然后在右侧文件检查中单击一个晦涩微小的框,让我再次手动设置路径!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接