Using C ++ code in iOS, create a static library or mix with Objective-C?

I have C ++ code (exposing the C-only interface through the header) that I will use for the iOS project.

I can either create a static library, or a link to it from my application project, or add the source files directly to the application project - which option is the best?

All answers are appreciated!

+4
source share
4 answers

Add sources if you expect them to change frequently. Otherwise, the library will be more suitable and make your project cleaner (however, you will only have to put the header files in your project)

+1
source

I used OpenCV in one of my application projects, which is mostly written in C ++. I found that adding the source files to the application project worked better for me because I made some minor changes to the code where necessary. Mainly used for use.

+1
source

I always prefer to add a source, if any, simply because it makes debugging easier. If you make a call to the library procedure and get an unexpected result (or a crash or something else), it is much easier to enter the library code with a debugger and find out what is happening. If you just have a static library, this is a black box and you cannot see what is happening inside. It also makes it easier for you to change the library code if you encounter an error or a missing function (just be careful if the library will be shared by other projects so that you keep the library code up to date in your own repository).

Xcode is good at letting you organize your project, so take advantage of these features. Keep the library code and headers separate from the main application and bundle it as needed.

+1
source

I suppose that by code you do not mean a well-formed library, so I expect that in the future this code may get some kind of modification pressure. The best way is to wrap it. here is one very good example, but you can do it differently: http://robnapier.net/blog/wrapping-cppfinal-edition-759

0
source

Source: https://habr.com/ru/post/1497009/


All Articles