Setting up Bullet Physics for iOS in XCode 4 - ios

So, I have downloaded the latest Bullet Physics package (2.78) and I have read the "Getting Started" documentation, which even includes an article on setting up a project in XCode from scratch (but not targeted at iOS nor XCode 4, which is what I'm using). Even so, I am still not able to set this up.
The following are the steps I'm currently taking:
I'm adding the Bullet Physics "src"
folder in the classes of the Xcode
I'm including the Bullet Physics
"src" folder path in the debug and
release "Header Search Paths" in
XCode
I add #include
"btBulletDynamicsCommon.h" to the
file where I want to use Bullet
Physics
I change the Objective-C file to
Objective-C++ by changing its file
extension from "m" to "mm". This is
the file where the
"btBulletDynamicsCommon.h" is
included
After I follow these steps, the compiler complaints about missing files (first few errors, there are 999+ errors shown when I try to build).
These are the first few headers missing in the btSoftBodySolverVertexBuffer_DX11.h:
#include <windows.h>
#include <crtdbg.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dcompiler.h>
Now, I'm pretty new with XCode and iOS, so the fact that these are missing doesn't really tell me much on how to solve this issue, and it makes me even wonder if they are at all needed for iOS development given the appended "DX11" on the file name that is having this issue.
So, what I would appreciate is either information on what's possibly wrong, or information on how to set up Bullet Physics to be used with iOS in XCode 4, from scratch.
Thanks.
Update: I have completely removed the DX11 and OpenCL and I'm now able to compile after step 4 above. I have not yet actually tested the Bullet Physics framework to see if it works without issues. But this now leads me to ask:
What are the specific source files/folders that are strictly necessary to run Bullet Physics in iOS?

There is a tutorial with step by step instruction for integrating Bullet Physics with iOS and Apple's GLKit framework http://www.informit.com/articles/article.aspx?p=1914612
The example code downloadable with the tutorial will get you started quickly and produces an interesting simulation.

How to insert Bullet Physics into iOS: iOS OpenGL BulletPhysics Sample Code
Download the sample code or follow on a new project form Xcode with iOS openGL template:
Download bullet physics... put it into a folder like the following:
*(notice that there is a folder for the project that contains the Xcode project file)
/MyProjectFolder/bullet-2.78/
/MyProjectFolder/MyProject/MyProject.xcproj
1.5. Run CMake in the physics directory to compile the frameworks (assuming you installed cmake already CMake) This step is optional with the sample code I uploaded since it already included the compiled frameworks in it....that made the file 100 megs but what is 100 megs these days anyway?
cmake . -G "Unix Makefiles" -DINSTALL_LIBS=ON -DBUILD_SHARED_LIBS=ON -DFRAMEWORK=ON -DCMAKE_OSX_ARCHITECTURES='i386;x86_64' -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/Library/Frameworks -DCMAKE_INSTALL_NAME_DIR=/Library/Frameworks -DBUILD_DEMOS:BOOL=OFF
make -j4
sudo make install
Goto your MyProject.xcproj and open in Xcode...
in XCode goto any file you wish to add the physics code to... you must understand that cpp files are c++ and .m .h files are generally cocoa. You must change the Class you wish to add the physics engine code to have a .mm extension signifying it should be compiled as Objective-C++ code...
In the particular class you want to add the physics which is now an Objective-C++ file or a cpp file, add the line
#include "btBulletDynamicsCommon.h"
and you should compile...the error is that the file is not found...
Next goto the MyProjectFolder/bullet-2.78/src and drag the src folder into your project.
Delete the folder named BulletMultiThread...it will eliminate the error of trying to compile some openCL (.cl) files
Last step, copy the following frameworks from the src folder of your bullet physics installation into your project:
/MyProjectFolder/bullet-2.78/LinearMath/LinearMath.framework
/MyProjectFolder/bullet-2.78/BulletCollision/BulletCollision.framework
/MyProjectFolder/bullet-2.78/LinearMath/LinearMath.framework
Build and Run... should compile smoothly to iOS and Mac now...

i found Orbitus007's answer a little miss leading. You can just add the bullet physics frameworks to the project instead of adding the whole src folder to your project. adding the src folder gave me errors and just adding the frameworks made my project compile
should look something like this http://imgur.com/CINtb
you can then just go
#import "BulletDynamics/btBulletDynamicsCommon.h"
you will still need to have your file with the .mm extension
also, i found that i got an error when trying to use cmake saying something about xcode-select. if you get it try run this command in the terminal, then try again
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
but other than that, his answer helped me get it working

OK, so as an update and to answer my own question:
I ended up deleting the folders DX11 and OpenCL and their content. This has so far allowed me to run a few Hello World tests.
I still welcome more assertive answers, given it seems strange to me that I can't find any documentation covering this for iOS usage.

Related

opencv cmake files, how to use them in iOS

These stuff stuck me another 3 days to figure out.
I'm implementing opencv and I need to use xfeatures2d module in objc xcode. I previously downloaded the opencv.framework and successfully imported it in my iOS project and it works. But there is no xfeatures2d in it. So then I finally figured out that it is an extra module and it is in a package call opencv_contrib.
To make use of it, it seems like people recommend to use cmake to build the source code of opencv-master with opencv-contrib-master
I did it, and it looks build correctly. And I got lots of funky things in my folder. However, it seems like nothing I can use to #import to my .xcodeproj project. (Sorry I can't embed my screenshot yet.)
So did I do something wrong? Or,is it the correct way to build the file I need??
Please help, Thanks!
Finally I found a solution. #thachnb 's solution is referred from here. This instruction guide you to generate an opencv2.framework in use of your iOS project from the opencv-master package. If you want to use the modules in opencv_contrib, you need to physically copy the module from opencv_contrib(in my case is xfeatures2d, or you can just copy everything over), to opencv-master/module, and then use
python opencv/platforms/ios/build_framework.py ios
command to compile it. After this compilation, you will have a opencv2.framework containing everything you need. This also helps.
Thanks #thachnb !
Q1. Did you run below command?
python opencv/platforms/ios/build_framework.py ios
if yes, move to question 2
Q2. Did you see opencv.framework in ios subfolder?
if yes, move to question 3
Q3. Did you add that opencv.framework folder to your xcode project? or drag and drop it to Framework folder of your xcode project?

Modules are disabled - but why?

I'm struggeling with Modules in a project. Where I use #import I get "Use of '#import' when modules are disabled". But why are they disabled?
In my build settings I have "Enable modules (C and Objective-C)" set to Yes for all targets.
Setting "Link Frameworks Automatically" to Yes or No does not impact this (compile-time) error
Although the project used to have Objective-C++ and some C++ code, it doesn't anymore. Are there any project-settings I can have missed that were set because of this?
I have no more .pch files in the project, and the build settings have no mention of them
I use CocoaPods (0.39.0) with "use_frameworks!" and the modules I wish #import are from there. But the same error happens if I replace the '#import ' or '#import ' with '#import Foundation;' and '#import UIKit', so I expect this is not related
The project is from pre-iOS7 so I might have missed a setting that used to be on by default
The project requires iOS 8 and builds against iOS 9.2.
I realize that loading third-party modules will probably slow down the apps loading time. I'm converting to CocoaPods with use_frameworks! so that I can measure by how much. If it's not too bad, I'd like to use as I'm planning to move multiple swift-only parts of the codebase into their own frameworks (as open source coocapods)
I believe that this is not be a duplicate of other questions on SO since I've gone through the ones I found (big thank-you to this one), followed the links, re-watched WWDC'13 session 404, and read the related posts on Apples forums, so I believe I've done my homework. :-)
In my project I have a bridging header to bridge from ObjC to Swift, and there is a generated header file to bridge from Swift to ObjC. It turns out that if the bridging header referenced headers where the implementation file referenced the bridge file from Swift to ObjC, module support is disabled. So be careful about what you put in your bridging file, and be careful about when you import the generated -Swift.h file.
Firstly go to the terminal and type xcode-select -p. It should say, /Applications/Xcode.app/Contents/Developer. If it doesn't, then type, sudo xcode-select -s /Applications/Xcode.app and hit enter and type in your password.
If that doesn't fix it, try deleting your project's derived data directory. Go to the Projects view and delete the derived data for your project. Then clean your build folder (command-shift-K). Run Analyze (command-shift-B) and resolve any issues in blue and yellow.
Now if #import is still not working, create a brand new XCode project. Verify that #import works in it. If it doesn't, then your XCode installation got screwed up probably, or your HDD is dying. Delete XCode and re-download it, see if that works. Restart into the recovery partition and see if you have some disk issues (unlikely, but hey).
If #import works in the new project, try taking all your from your current project and copying them into the new project. Make sure you have the latest version of cocoapods and then freshly install your pods into the new project.
If all of that doesn't fix it, you probably left an #end statement out somewhere or have a missing } ...

opencv2/opencv.hpp file not found in Xcode

I have built openCV to get opencv2.framework. I added this to my xcode iOS project by going to "build phases->Link Binary With Libraries", then tried to include "opencv2/opencv.hpp" in my project.
I get the error "opencv2/opencv.hpp" not found. But the file exists in the framework. I have tried to find a solution online but nothing has worked for me.
The file I'm trying to include it in is a .mm file. I have made "compile sources as" objective-c++. Any help would be great.
What worked for me was very simple:
*NOTE THE DIFFERENCE FOR IOS vs. OS X PROJECTS
FOR IOS:
Put the opencv download (for 3.0.0 it is just a drag and drop kind of thing) into the project specific Xcode folder. Then set the Frame Search Paths to $(PROJECT_DIR). The Frame Search Path is located under the Build Settings. No other paths need to be set.
Lastly, right click in the navigator pane and click "Add Files to..." in order to add in the opencv library from the project folder.
FOR OSX:
check out Tim's tutorial: https://www.youtube.com/watch?v=OVSPfUmNyOw
I solve the problem by adding to the FRAMEWORK_SEARCH_PATHS the absolute path were I had the framework I needed to use:
You should use your own path obviously. ;-)
Took me 4 hours to figure this out. This is how I got this to work :
Along with the opencv framework add the following frameworks in the build phases:
Accelerate, AssetsLibrary, AVFoundation
, CoreGraphics
, CoreImage
, CoreMedia
, CoreVideo
, QuartzCore
, UIKit
, Foundation.
Then, in the .pch file add these lines before UIKit and Foundation imports :
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
In my case the symbolic links to the header files were broken. This was caused by cloning the following great example project:
https://github.com/BloodAxe/OpenCV-Tutorial
In the cloned project, the header files were not reachable anymore. After reimporting the opencv2.framework from the official opencv ios download site (OpenCV for iOS), the headers were available again. XCode should look as follows:
The following is a screenshot of a Xcode project with broken headers.
With broken header files, the xcode project looks as follows:
Make sure in Build Settings for the Target, you have the Framework Search Path in the Search Paths section set to the correct path to where your framework is located in your directory. You can do this by clicking to the right of Framework Search Path in the white space, click the + sign and add $(PROJECT_DIR) then click + again and add $(inherited). Make sure the framework is located in your main directory for your project at hand. This worked for me, as I encountered the same problem.
Hope this helps!
I used openCV in my project and implementing it with cocoapods was impossible because version of library was too old, so i decided to implement it as static library. create folder in your project and add library there, in build settings find library and framework search path and add link to your openCV folder. It will work without any error. Also you should add openCV header file in prefixPatch.
More Detail Instruction 100% Works:
1) Download framework from official website: OpenCV
2) In Project Directory create folder named: External_SDK
3) Put Opencv framework inside this folder and drag&drop it in Xcode Project (Folder) with Target Membership of your App (Not App_test).
4) In Xcode Project search for yourPrefixHeaderFileName.pch and in the top of the file add this lines:
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
5) after that you should import or include it in .h file, why include? because it's CPP library. If you want to access library with import keywoard than you should do like this: #import <EXAMPLE>
6) In build settings search for library and framework search path and add link to your EXTERNAL_SDK folder. To read framework directly from your folder. Find and change ALWAYS_SEARCH_USER_PATHS = YES
and in HEADER_SEARCH_PATHS add $(inherited) and /usr/include/FRAMEWORK_PATH
Hope this answer will help someone.
And the best practice is to call
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
Only header files.
From my experience, it is not necessary to add so many other frameworks. Instead, only need opencv2 and add "#import " in prefixheader.pch
The thing is that MUST set correct Framework Search Paths as mentioned above unless opencv2 framework folder is in your project directory.
Notice: don't set wrong location in Framework Search Paths as there are two "YourProjectName". Set the 1st one (belongs to TARGETS), not the 2nd one(belongs to PROJECT). I made the mistake.
Here is my answer for this.
Environment: XCode 8.1
Download page: http://opencv.org/downloads.html. Choose any link for iOS.
Important step: while downloading opencv2.framework, you must use ".zip" format, not ".framework" format, afterwards, unzip it to opencv2.framework. It is weird, but it should work. Meanwhile, you have to rename it to opencv2.framework if the unzipped one is not.
just drag and drop the framework to your iOS project. No any settings are required. You could refer to this for testing : www.youtube.com/watch?v=ywUBHqxwM5Q.
I ran into some issues when I went to Target-->Build Phases-->Link Binary With Libraries. When I added opencv2.framework from there, my app would not launch.
Instead, I just dragged and dropped the framework under the directory "Frameworks" in XCode and that worked. I didn't change anything else.

How do I add this C library to my iOS Xcode 4 project?

I'm trying to add the openjpeg library to my XCode 4 project so that I can compress images taken by the iPhone's camera to jpeg2000.
I built the static library (libopenjpeg.a) using Cmake on OS/X. (I'm guessing this may have been the first error, that it needs to be built by XCode so it's built for iPhone architecture and not OS X).
I have the library added in the Link Binary with Libraries of my target.
The project builds successfully but I can't seem to import any of the headers from the library into any of my Objective-C classes. I've tried manually adding the folder that contains the libopenjpeg header files to the User Header Search Path but that did not seem to do anything.
Any suggestions?
for the simplest solution
Import the head files to you project's source.
You can still build it on the command-line with CMake, you'd just have to modify the CMakeLists.txt file so the right flags are passed when compiling.
However as Gavin indicates, it may be simpler just to drag the header and source files from the library into your Xcode project, and forego the building of a static library.

Problems trying to add the libz.1.2.3.dylib to my ipad project

First of all, i'm now on this site so really sorry if i'm commiting some error posting this question.I'm trying to use the zipArchive class to manage zip files in an ipad project.
What steps will reproduce the problem?
Create a project.
Add the ZipArchive folder with their files.
Add the libz.1.2.3.dylib
What is the expected output? What do you see instead?
I have all the code (about ziparchive) commented, so i only have the #import #import "ZipArchive/ZipArchive.h" in my viewcontroller, and i expect to build the project without errors.
I see the following error in the compiler:
ld: warning: ignoring file /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2/Symbols/usr/lib/libSystem.dylib, missing required architecture i386 in file
ld: in /Developer/Platforms/iPhoneOS.platform/DeviceSupport/4.2/Symbols/usr/lib/libobjc.A.dylib, missing required architecture i386 in file for architecture i386
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1
What version of the product are you using? On what operating system?
I'm using xcode 4 a project for the ipad with the 4.2 ipad simulator on a Mac os X version 10.6.7
Please provide any additional information below.
I think the problem is with the libz.1.2.3.dylib library, and I have some guest of where might be the problem:
The libz.1.2.3.dylib path error is on iPhoneSimulator.platform, it is valid for ipad too?? If is not, which lib could i use for the same purpose with the ipad??
I'm not sure i'm adding the libz.1.2.3.dylib lib correctly. What I have done is: right-click on Resources folder -> add files to "myproject" -> search for the libz.1.2.3.dylib and add the 4.2 version of it from the path u could see in the compiler errors. I also try to add to the frameworks folder with the same results.
I'm reading lots of posts about how to fix similar problems but no one could help me.
Any idea of what I have to do to fix my problem??
Really thanks!!
You need to do this:
Delete libz.1.2.3 from your local Frameworks folder. You don't need it.
Select your project at the top of the Project Navigator.
Select your application target.
Open "Link Binary With Libraries".
Click the "+"
Search for "libz".
Select "libz.dylib".
If you are using Xcode 4.5.2 the screenshots below may aide you in proceeding through steps 2 through 5. I'm not sure if other versions of Xcode are the same or not.
If you are using xcode 4 or upper version of it than it seems that libz.1.2.3.dylib is not included in iOS5 sdk. Here is simple method to fix this:
Open your project in XCode 4.2
Remove libz.1.2.3.dylib from framework
Add new framework libz.1.2.5
Run you app
It works fine.
libz.dylib is an alias to the latest version (currently libz.1.2.5) so you can also navigate to the file's location in Terminal and create a symlink called "libz.1.2.3.dylib".
cd /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/
sudo ln -s libz.1.2.5.dylib libz.1.2.3.dylib
You could also link to libz.dylib, which I would expect to always point to the actual latest version, which is why Tricon recommends changing the project to just include libz.dylib. I'm not sure I'd delete anything, although it's not a whole lot different from adding a new symlink...you're still mucking around deep inside the guts of Xcode....

Resources