To clarify the clarification: I know how to create libraries in Xcode using either obj-c or swift. I know how to use these in projects. I know how to compile these projects so everything works. What I do not know is how to take open source C source code (hehe) and build/make/compile it into a library.
Just to clarify everything below: I am looking for a way to use c libraries in a Swift application, this means using Xcode. The c libraries do no have to be build with/in Xcode, I am fine with using other tools.
I normally write all the code I use myself and unfortunately I only write Swift in Xcode. So I am a little behind on using frameworks/libraries. Now I really want to explore Tesseract OCR and I am having trouble building the libraries needed. To me it is better to really understand how this works and be able to do this myself and not just look on Github and find pre-compiled sources.
The projects below both handle this differently. The iOS version uses precompiled Libraries. (.a file) The OSX version uses projects that contain the library files (not yet compiled).
libjpeg example of a library that can't be just dragged and dropped.
Using brew will only install it as a command line tool, not generate a lib.
install Tesseract with homebrew
The problem I have is that I know too little about these c libraries, and how to build them to even google this effectively.
My question:
- How do you compile/build the c code into an .a file?
- How do you create an xcode project that builds a framework based on the c code? (optional)
- What is the right vocabulary for all this?
I am not looking for a Tesseract specific answer. I want to learn how to do this myself.
This article doesn't mention how to actually add the c program and let xcode make it. The part about workspaces is interesting though.
Article on building c project in Xcode
This one is actually really relevant. However I can't find the executable in Tesseract for example. All options are greyed out when doing step 5.
This looks pretty : simple c++ procect Why can't tesseract look like that? :)
If you want to build Tesseract, follow the instructions for a UNIX system:
You don't have to, in fact you shouldn't use xcode (which is simply a GUI/frontend) but stick with what each library tells you to use. In some cases it might be possible to build with xcode. Projects that intend you to use xcode for their building, tend to include a xcode project file.
Apple's compiler is llvm/clang, so it may have some slight differences from Linux's GNU gcc/g++.
EDIT
You need to first install leptonica and automake:
Then run the building instructions. As you will notice during make install the library is in
And the headers are in:
From there on, its a matter of using it in your project. I tested this on OSX Yosemite 10.10.5 with brew and command line tools.
This is a big question. For the part, I had a recent encounter with Xcode.
Yourproj
(the root node of the tree on the LHS)Yourtarget
on the TARGETS sectionMach-O Type
to `Static LibraryAs per 'C' language requirement, AFAIK this can be changed on the fly:
C Language Dialect
to your choice, sayGNU99
Compile Sources As
: 'C'Packaging
and editProduct Name
toYourtarget
Executable Prefix
tolib
Executable Extension
to.a
Now the output should become a file like
libYourtarget.a
YMMV, based on what language you choose. I have not used Swift yet. Just add the
libYourtarget.a
as an Other framework ofYournewproj
. The proper way of doing this isYourproj
(the root node of the tree on the LHS)Build Phases
on the upper barLink Binary with Libraries
and click on the plus sign and thenAdd Other
buttonlibYourtarget.a
file and click open.This should work. If not, try to get rid of compiling errors as it is YMMV as already mentioned.
Hope this helps.