Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build ASSIMP Library for iOS (Device and Simulator) with boost-library?

I want to use the ASSIMP library http://assimp.sourceforge.net in an iOS project. Unfortunately, I'm not very experienced with makefiles and that stuff, so I need some help.

I've downloaded the sources and first I tried to build with make (in the code-subfolder) In the makefile I've added INCLUDEFLAGS = -I/Lib because my boost header-files are in /Lib/boost Executing make static succeeds with some warnings. A static library (.a) is generated.

Then I tried to add the .a-file to my xcode-project and specified the assimp-header folder as additional include directory (Other Search Paths). Linking failed with the message that the library has not the right architecture (i386 required for the simulator)

file libassimp.a outputs: "libassimp.a: current ar archive random library"

How can I build the library for the i386 architcture and for arm6 or arm7, whatever I need on an iOS device?

Is it ok to use the boost-headers only or is it better/necessary to build boost as a library? Currently I'm using boost headers only, which should be fine since boost is a header only library?!

There is also a cmake - makefile (CMakeLists.txt). cmake is the recommended way of building the library but I don't have any experience with cmake.

Or another thought: Is it possible to build a library via xcode? The final result should be a library for i386, arm6 and arm7 architecture.

What shall I do? And how?


Edit:

I've just discovered that there are the following preprocessor checks in the file aiDefines.h:

#if defined(_MSC_VER)
    // See http://msdn.microsoft.com/en-us/library/b0084kay.
#   if defined(_M_IX86)
#       define ASSIMP_BUILD_X86_32BIT_ARCHITECTURE
#   elif defined(_M_X64)
#       define ASSIMP_BUILD_X86_64BIT_ARCHITECTURE
#   elif defined(_M_IA64)
#       define ASSIMP_BUILD_IA_64BIT_ARCHITECTURE
#   else
#       error unknown architecture
#   endif
#elif defined(__GNUC__)
    // See http://gcc.gnu.org/onlinedocs/cpp/Predefined-Macros.html.
#   if defined(__x86_32__) || defined(__i386__)
#       define ASSIMP_BUILD_X86_32BIT_ARCHITECTURE
#   elif defined(__x86_64__)
#       define ASSIMP_BUILD_X86_64BIT_ARCHITECTURE
#   elif defined(__ppc__)
#       define ASSIMP_BUILD_PPC_32BIT_ARCHITECTURE
#   else
#       error unknown architecture
#   endif
#else
#   error unknown compiler
#endif

Does this mean, it is not possible to compile the ASSIMP library for ARM architecture?

like image 900
j00hi Avatar asked Jul 14 '11 10:07

j00hi


3 Answers

I personally don't do any iOS development, but I know that others have successfully compiled Assimp for their iDevices using Xcode. An Xcode 3 project should be included with the distribution, although I don't know if you can use it without further modification.

The architecture preprocessor defines are currently only used for logging output (in code/Importer.cpp), and support for ARM has been added to trunk in the meantime (r919, to be exact).

like image 124
dnadlinger Avatar answered Nov 11 '22 09:11

dnadlinger


I also had a few issues getting assimp to work on iOS devices.

Here's what I did in case anyone is also having similar issues - similar to Artur Sampaio's example above, but with a few differences:

  1. get the latest assimp from https://github.com/assimp/assimp, i.e., git clone git://github.com/assimp/assimp.git

  2. cd into the assimp directory and open up CMakeLists.txt. For some reason, the make file couldn't find my glut and gl libs, so I commented out the lines in CMakeLists.txt that referred to making the samples, i.e., the "IF ( BUILD_ASSIMP_SAMPLES)" block of code. There's probably a simple way to point to these, but since I didn't need the samples I just did commented those lines out.

  3. cd to port/iOS/ and then sudo ./build_ios.sh (it takes a few minutes to compile all 3 versions of the lib).

  4. now if you cd to assimp/lib/ios and lipo -info libassimp.a you will see that the library is a fat file with i386, arm6 and arm7 architectures (and will work on both the simulator and the arm6 or arm7 device).

  5. to get it to work in XCode 4.3.2, drag&drop the libassimp.a file into my project (from the finder). You don't have to actually copy it over to your project directory, it doesn't hurt if you do though.

  6. for some reason, a build will still fail unless you explicitly link to the libz dynamic library. Click the main project from the XCode file list, select TARGETS, then click on the Build Settings tab, scroll down to the Linking section, and then add "/usr/lib/libz.dylib" under "Other Linker Flags".

  7. the current version of assimp on github seems to have restructured the code somewhat, and while all of the examples I tested from the assimp website work, they all require different, or at least renamed, header files:

Here I've commented out the previous names of the headers and below are the new names:

//#include <assimp.hpp>      // C++ importer interface
//#include <aiScene.h>       // Output data structure
//#include <aiPostProcess.h> // Post processing flags
#include "Importer.hpp"
#include "scene.h"
#include "postprocess.h"

After this point I was able to use assimp on my iPad.

Also, you probably want to make sure that you have uninstalled other versions of assimp before doing this (eg from macports or brew).

like image 20
Angus Forbes Avatar answered Nov 11 '22 10:11

Angus Forbes


I found branch where one guy already changed project setting for your needs. https://github.com/blandinw/assimp/tree/ios-xcode46/doc

like image 21
Nikolay Shubenkov Avatar answered Nov 11 '22 09:11

Nikolay Shubenkov