Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

systray_darwin.m: Compare Mac OS min version with value instead of macro #94

Merged

Conversation

teddywing
Copy link
Contributor

I was getting this error building on Mac OS X 10.12:

$ pwd
<$GOPATH>/src/github.com/getlantern/systray/example
$ go run .
# github.com/getlantern/systray
systray_darwin.m:132:22: error: use of undeclared identifier 'NSControlStateValueOn'
systray_darwin.m:134:22: error: use of undeclared identifier 'NSControlStateValueOff'

The NSControlStateValueOn and NSControlStateValueOff were not
defined because Mac OS versions prior to 10.14 don't define
__MAC_10_14.

From /usr/include/Availability.h:

It is also possible to use the _VERSION_MIN_REQUIRED in source code to make one
source base that can be compiled to target a range of OS versions. It is best
to not use the MAC
and _IPHONE* macros for comparisons, but rather their values.
That is because you might get compiled on an old OS that does not define a later
OS version macro, and in the C preprocessor undefined values evaluate to zero
in expresssions, which could cause the #if expression to evaluate in an unexpected
way.

#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
    // code only compiled when targeting Mac OS X and not iPhone
    // note use of 1050 instead of __MAC_10_5
    #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050
        // code in here might run on pre-Leopard OS
    #else
        // code here can assume Leopard or later
    #endif
#endif

See #75, #92.

I was getting this error building on Mac OS X 10.12:

    $ pwd
    <$GOPATH>/src/github.com/getlantern/systray/example
    $ go run .
    # github.com/getlantern/systray
    systray_darwin.m:132:22: error: use of undeclared identifier 'NSControlStateValueOn'
    systray_darwin.m:134:22: error: use of undeclared identifier 'NSControlStateValueOff'

The `NSControlStateValueOn` and `NSControlStateValueOff` were not
defined because Mac OS versions prior to 10.14 don't define
`__MAC_10_14`.

From `/usr/include/Availability.h`:

> It is also possible to use the *_VERSION_MIN_REQUIRED in source code to make one
> source base that can be compiled to target a range of OS versions.  It is best
> to not use the _MAC_* and __IPHONE_* macros for comparisons, but rather their values.
> That is because you might get compiled on an old OS that does not define a later
> OS version macro, and in the C preprocessor undefined values evaluate to zero
> in expresssions, which could cause the #if expression to evaluate in an unexpected
> way.
>
>     #ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
>         // code only compiled when targeting Mac OS X and not iPhone
>         // note use of 1050 instead of __MAC_10_5
>         #if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050
>             // code in here might run on pre-Leopard OS
>         #else
>             // code here can assume Leopard or later
>         #endif
>     #endif

See getlantern#75, getlantern#92.
@joesis joesis merged commit 6f0e5a3 into getlantern:master Jul 27, 2019
@teddywing
Copy link
Contributor Author

Thanks!

@antwal
Copy link

antwal commented Jul 27, 2019

not working very well, I'm checking if it's my mistake in the code since I get a link error

signal: segmentation fault

checking SDK API diff , AppKit Diff 10.12 to 10.13+

@getlantern getlantern deleted a comment from joesis Mar 1, 2021
ropog3ovomou pushed a commit to ropog3ovomou/systray that referenced this pull request Jul 13, 2022
…lue-instead-of-macro

systray_darwin.m: Compare Mac OS min version with value instead of macro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants