How to "create" C ++ code in a library for xcode

To clarify the clarification: I know how to create libraries in Xcode using either obj-c or swift. I know how to use them in projects. I know how to compile these projects so that everything works. I don't know how to use open source (hehe) source code and build / make / compile it into a library.


Just to clarify everything below: I'm looking for a way to use c libraries in a Swift application, this means using Xcode. C libraries do not need to be built with / in Xcode, I am well versed in other tools.


I usually write all the code that I use myself, and, unfortunately, I only write Swift in Xcode. Therefore, I am a little behind the use of frameworks / libraries. Now I really want to learn Tesseract OCR, and I'm having trouble creating the necessary libraries. Itโ€™s better for me to understand how it works and be able to do it myself, rather than just look at Github and find pre-compiled sources.

The projects below are handled differently. The iOS version uses precompiled libraries. (.a file) The OSX version uses projects that contain library files (not yet compiled).

Compiled iOS Version

Compiled OSX Version

libjpeg is an example of a library that you cannot just drag and drop.

Using brew will only install it as a command line tool, not generate lib.

install Tesseract with homebrew

The problem is that I know too little about these c libraries and how to effectively create them even for Google.

My question is:

  • How do you compile / create c-code in a .a file?
  • How do you create an xcode project that creates a structure based on c code? (Not necessary)
  • What is the right dictionary for all this?

I am not looking for a specific Tesseract answer. I want to learn how to do it myself.

about static libraries

This article does not mention how to actually add the c program and let xcode do this. Interestingly, part of the work areas is interesting.

Article on creating a c project in Xcode

This is really true. However, for example, I cannot find the executable in Tesseract. In step 5, all parameters are grayed out.

It looks beautiful: simple C ++ procect Why can't tesseract look like this? :)

+7
c ++ frameworks xcode static-libraries
source share
2 answers

If you want to build Tesseract, follow the instructions for the UNIX system:

./autogen.sh ./configure make sudo make install sudo ldconfig 

You do not need to, in fact you should not use xcode (which is just a graphical interface / interface), but stick to what each library tells you. In some cases, it may be possible to build using xcode. Projects that are designed to use xcode to build them typically include an xcode project file.

The Apple compiler is llvm / clang, so it may have some minor differences from Linux GNU gcc / g ++.

EDIT

You need to install leptonica and automake first:

 brew install automake brew install leptonica 

Then run the building instructions. As you noticed during make install, the library is in

 /usr/local/lib/libtesseract.a 

And the headers are in:

 /usr/local/include/tesseract 

From there, it is a matter of using this in your project. I tested this on OSX Yosemite 10.10.5 using brew and command line tools.

+2
source share

This is a big question. For the part, I had a recent meeting with Xcode.

  • How do you compile / create c-code in a .a file?
  • Click on the Xcode Yourproj project name (root of the tree node on LHS)
  • Select Yourtarget in the TARGETS Section
  • Click Build Phases on the top bar.
  • scroll down to the link section
  • change Mach-O Type to `Static Library

In accordance with the requirements of the C language, AFAIK can be changed on the fly:

  • From the last paragraph above, scroll down to the Apple LLVM - Language section
  • change the C Language Dialect your choice say GNU99
  • If necessary, select Compile Sources As : 'C'
  • Scroll to Packaging and edit Product Name to Yourtarget
  • Change Executable Prefix to lib
  • Change Executable Extension to .a

Now the output should become a file like libYourtarget.a

  • How do you create an xcode project that creates a framework based on c code?

YMMV, based on which language you choose. I have not used Swift yet. Just add libYourtarget.a as another structure of Yournewproj . The correct way to do this is:

  • Click on the Xcode Yourproj project name (root of the tree node on LHS)
  • Click Build Phases on the top bar.
  • Make sure the target is selected on the left.
  • Now expand Link Binary with Libraries and click the plus sign and then Add Other
  • Locate the libYourtarget.a file and click Open.

That should work. If not, try to get rid of compilation of errors, as this is YMMV, as already mentioned.

Hope this helps.

+2
source share

All Articles