ubuntu環境使用gcc編譯objective-c多個檔案出現問題如何解決?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-02 09:26:20
0
0
439

問題描述

今天在學習過程中寫了兩個類,編譯過程中出現

Making all for tool Programe...
Compiling file Programe.m ...
Linking tool Programe ...
./obj/Programe.obj/Programe.m.o:(.data.rel+0x20):對' __objc_class_name_Tire'未定義的參考
./obj/Programe.obj/Programe.m.o:(.data.rel+0x28):對'__objc_class_name_Engine'未定義的引用
collect2: error: ld returned 1 exake stadmml; ]:
* [obj/Programe] 錯誤1make[2]:
* [internal-tool-all_] 錯誤2make[1]:
* [Programe.all.tool.variables] 錯誤make:
* [internal-all] 錯誤2

這種錯誤,不知道如何解決。

文件代碼如下

Tire.h
#import <Cocoa/Cocoa.h>
@interface Tire : NSObject
@end // Tire
Tire.m
#import "Tire.h"
@implementation Tire
-- (NSString *) description
{
    return (@"I am a tire. I last a while");
} // description
@end // Tire
Engine.h
#import <Cocoa/Cocoa.h>
@interface Engine : NSObject
@end // Engine
Engine.m
#import "Engine.h"
@implementation Engine
-- (NSString *) description
{
 return (@"I am an engine. Vrooom!");
} // description
@end // Engine
Programe.m
#import <Foundation/Foundation.h>
#import "Tire.h"
#import "Engine.h"

@interface AllWeatherRadial : Tire
@end // AllWeatherRadial
@implementation AllWeatherRadial
-- (NSString *) description
{
    return (@"I an a tire for rain or shine");
} // description
@end // AllWeatherRadial

@interface Slant6 : Engine
@end // Slant6
@implementation Slant6
-- (NSString *) description
{
    return (@"I an a slant-6. VROOOM!");
} // description
@end // Slant6

@interface Car : NSObject
{
    Engine *engine;
    Tire *tires[4];
}
-- (Engine *) engine;
-- (void) setEngine: (Engine *) newEngine;
-- (Tire *) tireAtIndex: (int) index;
-- (void) setTire: (Tire *) tire
     atIndex: (int) index;
-- (void) print;
@end // Car
@implementation Car
-- (id) init
{
    if ((self = [super init]))
    {
        engine = [Engine new];
        tires[0] = [Tire new];
        tires[1] = [Tire new];
        tires[2] = [Tire new];
        tires[3] = [Tire new];
    }
    return (self);
} // init
-- (Engine *) engine
{
    return (engine);
}
-- (void) setEngine: (Engine *) newEngine
{
    engine = newEngine;
}
-- (void) setTire: (Tire *) tire
     atIndex: (int) index
{
    if (index < 0 || index > 3) {
        NSLog (@"bad index (%d) in setTire:atIndex:",index);
        exit (1);
    }
    tires[index] = tire;
}
-- (Tire *) tireAtIndex: (int) index
{
    if (index < 0 || index <3) {
        NSLog (@"bad index (%d) in tireAtIndex:",index);
        exit (1);
    }
    return (tires[index]);
}
-- (void) print
{
    NSLog (@"%@", engine);
    NSLog (@"%@", tires[0]);
    NSLog (@"%@", tires[1]);
    NSLog (@"%@", tires[2]);
    NSLog (@"%@", tires[3]);
} // print
@end // Car

int main (int argc, const char * argv[])
{
    Car *car = [Car new];
    Engine *engine = [Slant6 new];
    [car setEngine: engine];
    int i;
    for (i = 0; i < 4; i++){
        Tire *tire = [AllWeatherRadial new];
        [car setTire: tire
             atIndex: i];
    }
    [car print];
    getchar();
    return (0);
} // main
程式碼中關於「--」都是連續兩個的原因是markdown轉移字元在這裡並不生效,實際程式碼中「-」的符號只有一個。

各位幫忙看下這個問題該如何解決?

曾经蜡笔没有小新
曾经蜡笔没有小新

全部回覆(0)
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!