How to define env:native in platformio.ini for a MacOS command line tool that uses the Cocoa framework

I figured it out. The flag '-framework Cocoa` is a flag for the linker. To get it passed to the linker one has to append LINKFLAGS to the SCons environment. For this I created an extra_script (saved in the same folder as platform.ini):

file: pre_extra_script.py

Import("env")
env.Append(LINKFLAGS=['-framework', 'Cocoa'])

and make sure it gets executed before the build starts by adding it to the platform.ini file.

file: platform.ini

[env:native]
platform = native
extra_scripts = pre:pre_extra_script.py

No additional build_flags are necessary.

2 Likes