Missing symbols when compiling an external on Apple M1

Stephane Letz's icon

I have missing _common_symbols and common_symbols_init symbols when compiling an external on Apple M1. Any idea how to solve that?

11OLSEN's icon

Do you include commonsyms.c and added "common_symbols_init();" in your main method?

Stephane Letz's icon

Is that supposed to be done? The same code was linking without problems when compiled on Intel.
I mean: I was not calling common_symbols_init() in the main method.

Rob Ramirez's icon

I think with the new SDK to support M1 this became a requirement

11OLSEN's icon

No, it's not a typo. commonsyms.c is defining the common_symbols_init() that you need to call in your main() method. Only after that, all these symbols are predefined and you can chuck many gensym() from your code, which always does a lookup and therefore eats performance. To include in your code, you have multiple ways:

in your cMakeList:
add_library(
    ${PROJECT_NAME}
    MODULE
    ${PROJECT_SRC}
    ${MAX_SDK_INCLUDES}/common/commonsyms.c
)

or by including in your source file:
#include "common/commonsyms.c"

or manually adding commonsyms.c in your IDE to the targets.

You're lucky to get an error message. On Win, when you forget common_symbols_init(), external compiles fine and crashes at creation time in Max 😩