Objective C and automake

问题描述 投票:0回答:1

我有一个非常小的obj程序

标题test.h


#import <Foundation/Foundation.h>

@interface Token : NSObject {
@private
  NSString * literal;
  size_t line;
  size_t column;
}
  @property (readonly) size_t line;
  @property (readonly) size_t column;
  @property (readonly) NSString * literal;
  + (id)newReturnTokenAtLine: (size_t) line column: (size_t) column;
  - (id)initWithLine: (size_t)aLine withColumn: (size_t)aColumn;
@end


@end

[test.m中的实现是

#import "test.h"


@implementation Token

@synthesize line;
@synthesize column;
@synthesize literal;


+ (id)newReturnTokenAtLine: (size_t) aLine column: (size_t) aColumn {
    Token * tok = [Token alloc];
    return (Token*)  [tok initWithLine: aLine column: aColumn];
}

- (id) initWithLine: (size_t) aLine withColumn: (size_t) aColumn {
    line = aLine;
    column = aColumn;
    return self;
}
@end

我的问题是,似乎目标C编译器认为未定义initWithLine

test.m:13:27: error: instance method '-initWithLine:column:' not found (return type defaults to 'id') [-Werror,-Wobjc-method-access]
    return (Token*)  [tok initWithLine: aLine column: aColumn];
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~
./test.h:5:12: note: receiver is instance of class declared here
@interface Token : NSObject {
           ^
1 error generated.

我缺少明显的东西吗?

我尝试在自动制作设置中使用它。因此,configure.ac

define(MINIOBJC_CONFIGURE_COPYRIGHT,[[
public domain
]])

AC_INIT([miniobjc], [0.0.1])
AC_CONFIG_SRCDIR([test.m])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([build-aux])

AM_INIT_AUTOMAKE([foreign serial-tests])

AC_PROG_CC
AC_PROG_OBJC
AC_PROG_LIBTOOL

AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([env],[chmod +x env])

AM_SILENT_RULES

AC_SUBST(OBJCFLAGS)
AC_SUBST(CFLAGS)

AC_OUTPUT

[Makefile.am

lib_LTLIBRARIES = libminiobjc.la

libminiobjc_la_SOURCES = test.h test.m
libminiobjc_la_OBJCFLAGS = $(AM_CFLAGS) -Werror=objc-method-access
objective-c autoconf automake libtool
1个回答
0
投票

在Objective-C中,方法的名称包括所有参数标签和分号。 -initWithLine:column:不存在,请改用-initWithLine:withColumn:或替换

- (id) initWithLine: (size_t) aLine withColumn: (size_t) aColumn

作者

- (id) initWithLine: (size_t) aLine column: (size_t) aColumn
© www.soinside.com 2019 - 2024. All rights reserved.