Search code examples
objective-cautoconfautomakelibtool

Objective C and automake


I have a very small obj program

Header test.h is


#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

And the implementation in test.m is

#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

My problem is that it seems the objective C compiler thinks that the initWithLine is not defined

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.

Am I missing something obvious?

I try to have this in an automake setup. Thus configure.ac is

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

and Makefile.am is

lib_LTLIBRARIES = libminiobjc.la

libminiobjc_la_SOURCES = test.h test.m
libminiobjc_la_OBJCFLAGS = $(AM_CFLAGS) -Werror=objc-method-access

Solution

  • In Objective-C the name of a method includes all argument labels and the semicolons. -initWithLine:column: doesn't exist, use -initWithLine:withColumn: instead or replace

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

    by

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