views:

125

answers:

3

It is theoretically possible to use a boost library (e.g. boost threads) inside a cocoa project?

A: 

Yes. You can compile boost as a static library and link against it, or you can add the source code to your project and compile it with it.

eman
+2  A: 

Yes, there is nothing stopping you from doing that:

  • you can mix Objective-C and C++ - the result is called Objective-C++
  • you can of course also link to C and C++ libraries
Georg Fritzsche
Yeah, I know Objective-C++ ... but I'm just asking because I get 3057 errors, all looking like `error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token` :)
Polybos
@Niels: Are you sure you are using a `.cpp` or `.mm` file? Alternatively you can set the language in the file settings, but this could be misleading for others.
Georg Fritzsche
@gf Yeah, I renamed the file from `.m` to `.mm` and Get Info now says from filetype: `sourcecode.cpp.objcpp` but though I got these errors ...
Polybos
@Niels: Can you give a small sample that reproduces the problem? You can also try doing the same with a plain C++ file - it doesn't sound like it, but maybe an Objective-C keyword is the culprit.
Georg Fritzsche
it just happens when trying to include boost/thread.hpp (e.g. boost/noncopyable.hpp work fine). When trying from XCode i get `'__try' was not declared in this scope`, when trying from command line I'm getting `declaration does not declare anything`-errors, which have there origin in boost/exception/diagnostic_information.hpp ...
Polybos
@Niels: I don't get these just from including `boost/thread.hpp` with 1.42. What version are you using? Do you have any symbols/includes before the boost-include?
Georg Fritzsche
@gf: Yeah, I have `#import <Cocoa/Cocoa.h>`, but probably my boost build is broken ... I'll rebuild :)
Polybos
A: 

Yeah, just make sure you use Objective-C++ and include to the boost directories you need. (Note: to change to objective-C++ change the file extension to .mm instead of .m, and keep the .h files the same)

thyrgle