How to “make” c++ code into a library for xcode

荒凉一梦 提交于 2019-12-04 04:27:34

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

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

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:

brew install automake
brew install leptonica

Then run the building instructions. As you will notice during make install the library is in

/usr/local/lib/libtesseract.a

And the headers are in:

/usr/local/include/tesseract

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.

  • How do you compile/build the c code into an .a file?
  1. Click on Xcode project name Yourproj (the root node of the tree on the LHS)
  2. Choose the target Yourtarget on the TARGETS section
  3. Click Build Phases on the upper bar
  4. scroll down to Linking section
  5. change Mach-O Type to `Static Library

As per 'C' language requirement, AFAIK this can be changed on the fly:

  1. From the last point above, scroll down to Apple LLVM - Language section
  2. change C Language Dialect to your choice, say GNU99
  3. If necessary choose Compile Sources As: 'C'
  4. Scroll up to Packaging and edit Product Name to Yourtarget
  5. Edit Executable Prefix to lib
  6. Edit Executable Extension to .a

Now the output should become a file like libYourtarget.a

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

YMMV, based on what language you choose. I have not used Swift yet. Just add the libYourtarget.a as an Other framework of Yournewproj. The proper way of doing this is

  1. Click on Xcode project name Yourproj (the root node of the tree on the LHS)
  2. Click on Build Phases on the upper bar
  3. Make sure a target is selected on the left
  4. Now expand Link Binary with Libraries and click on the plus sign and then Add Other button
  5. Browse to your libYourtarget.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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!