Linking Issues with C and Max SDK


    Jul 01 2020 | 4:42 am
    Update: I ended up just biting the bullet and compiling in xcode. After have to run this weird command ($ sudo xattr -rd com.apple.quarantine <path to externals dir where the built mxo goes after compilation>) and adding the externals directory to Option->File Preferences in Max, I was about to get it to work. Still need to figure out how to make a makefile to replace xcode in this process, but at least I can start coding.
    -------
    I want to start developing my patches with C because I don't enjoy programming in Javascript. I am having linker issues when I compile my C code. I am using the max-sdk v8.0.3.
    To test my initial work flow, I am using this example code from Writing External Objects for Max 4.0 and MSP 2.0 (I can't find a more up to date source for some reason):
    #include "ext.h"
    typedef struct _simple {   
      t_object s_obj;
      long s_value;
    } t_simple;   
    static t_class *s_simple_class;  
    void *simple_new() {
      t_simple *x = (t_simple *)object_alloc(s_simple_class);
      x->s_value = 0;
      return x;
    }  
    void simple_int(t_simple *x, long n) {
      x->s_value = n;
    }  
    void simple_bang(t_simple *x) {
      post("value is %ld", x->s_value); 
    }  
    void ext_main(void *r) {   
      t_class *c; 
      c = class_new("simple", (method)simple_new, (method)NULL, sizeof(t_simple), 0L, 0);
      class_addmethod(c, (method)simple_int, "int", A_LONG, 0);
      class_addmethod(c, (method)simple_bang, "bang", 0);
      class_register(CLASS_BOX, c);
      s_simple_class = c;
    }
    Here is my makefile:
    
    CC=gcc
    CCFLAGS= -g -Werror
    INCLUDE_DIRS=-Isrc -I../max-sdk-8.0.3/source/c74support/max-includes -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/
    MAIN_SRC=src/main.c
    main: $(MAIN_SRC)
    	$(CC) $(CCFLAGS) $(INCLUDE_DIRS) -o $@ $(MAIN_SRC)
    Here is my error:
    $ make
    gcc -g -Werror -Isrc -I../max-sdk-8.0.3/source/c74support/max-includes -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/Headers/ -o main src/main.c
    Undefined symbols for architecture x86_64:
      "_class_addmethod", referenced from:
          _ext_main in main-25be75.o
      "_class_new", referenced from:
          _ext_main in main-25be75.o
      "_class_register", referenced from:
          _ext_main in main-25be75.o
      "_gensym", referenced from:
          _ext_main in main-25be75.o
      "_main", referenced from:
         implicit entry/start for main executable
         (maybe you meant: _ext_main)
      "_object_alloc", referenced from:
          _simple_new in main-25be75.o
      "_object_post", referenced from:
          _simple_bang in main-25be75.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [main] Error 1
    Is there an issue with something I am excluding from my code? Have I left those references undefined when they shouldn't be? Is it an issue with something being 32-bit in the sdk? I am at a loss. Thanks in advance for the help.