Objective C 和汽车制造

Objective C and automake

我有一个非常小的obj程序

Header 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

我的问题是 objective 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.

我是不是遗漏了什么明显的东西?

我尝试在 automake 设置中使用它。因此 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中,方法的名称包括所有参数标签和分号。 -initWithLine:column: 不存在,请使用 -initWithLine:withColumn: 代替或替换

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

来自

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