Linking with frameworks (Cocoa, CoreAudio, etc) on OSX

383 views
Skip to first unread message

Chet Gnegy

unread,
Aug 7, 2016, 5:03:55 PM8/7/16
to bazel-discuss
I am trying to set up BUILD rules for a third party library, Juce. Juce has lots of dependencies; on MacOSX, those dependencies include Cocoa, CoreAudio, and several other frameworks. 

I'm getting errors like this:
In file included from ThirdParty/Juce/lib/modules/juce_audio_devices/../juce_events/juce_events.h:29:
In file included from ThirdParty/Juce/lib/modules/juce_audio_devices/../juce_events/../juce_core/juce_core.h:137:
In file included from ThirdParty/Juce/lib/modules/juce_audio_devices/../juce_events/../juce_core/native/juce_BasicNativeHeaders.h:44:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h:12:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSArray.h:5:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:10:1: error: expected unqualified-id
@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:11:1: error: expected unqualified-id
@class Protocol;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:17:1: error: expected unqualified-id
@protocol NSCopying
^

The errors are because I'm not linking to Cocoa and Foundation (though it seems to be finding them?). How do I specify that I am using these frameworks in my build rule?

I've tried:
cc_library (
   
...
    copts
= [
     
"-framework Cocoa",
     
"-framework Foundation",
   
]
)

I've tried linkopts (instead of copts) with and without linkstatic.

The problem seems to be that it is trying to parse those headers and getting to Objective C code that it doesn't understand, perhaps linking to a built version of them is the right thing to do?

Looks like somebody wanted to know the same thing is me a while back, but the thread never really got off the ground.
https://groups.google.com/forum/#!topic/bazel-discuss/pMZJI3qR2_A

Any advice is greatly appreciated.

Thanks,
Chet

Peter Schmitt

unread,
Aug 8, 2016, 10:45:35 AM8/8/16
to Chet Gnegy, bazel-discuss
Have you tried the objc rules? They have an sdk_frameworks attribute that may help you here. Unfortunately you'll likely run into https://github.com/bazelbuild/bazel/issues/125 which we don't expect to be fixed before the end of the year. 

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/53cb20fb-2cef-477b-a952-4b737f97afc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chet Gnegy

unread,
Aug 8, 2016, 10:24:01 PM8/8/16
to bazel-discuss, chet...@gmail.com
I have, the problem is that I need to use the frameworks in c++ and you can't get the frameworks transitively by depending on an objc_library. Thanks for the link. End of the year is better than never I guess. 

I tried one of the suggested fixes, adding -ObjC to copts, but I get "error: invalid argument '-std=c++0x' not allowed with 'C/ObjC'. 
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages