Binding.gyp file for Objective-C++ project built using XCode

Hi!

Last time we started with the project and I promised that next will be an addon. I don’t have it finished yet, but stepped into an unknown teritory of configuring everything to compile and link find with an Objective-C(++) code and native macOS libraries: CoreBluetooth and CoreFoundation.

There are not many informations at all on the internet about how to make it work so I had to do a lot of guessing and trying.

First I made a rookie mistake (I am a newbie with Node addons so no surprise here) and added include_dirs at the wrong level of the file. Which made it unusable for both Xcode and node-gyp.

And I spent a few hours just setting it manually in Xcode settings (some of node-gyp commands remove the project file, node-gyp rebuild  for example, or just node-gyp clean ) before I found the problem.

I was really pissed off at the moment when I have found out that most of settings that I put there were just not parsed at all because there were not added as a child element of target.

Anyway.

We need to build on OS X using native libraries. I wanted to use Objective-C too just to try how it works. So first we may add .m and .mm files (.m is Objective-C, .mm is Objective-C++ – there is not much difference between them, second just allows C++ code inside) so my “sources” now looks like this:

Of course it won’t work now. We need to change at least two more things. First (this is not mandatory, but I really recommend that) we add conditional settings based on operating system. This way we will not break compile on another platforms in the future:

Then we populate the “mac”:

Notice how libraries are imported (“link_settings”). Somehow for one library it is:

It does not work for more than one though, tried using comma etc. The way I put it works.

Next thing is CLANG_CXX_LIBRARY which means I can use C++11 and -ObjC++ which tells the compiler that some of the code will be in Obj-C.

Now also project created with this command works and can be built using Xcode:

This works fine so I will now try to finish the library and add some logging possibility. Stay tuned 😉

Leave a Reply

Your email address will not be published. Required fields are marked *