Hi I am developing an IOS app and I have cpp file in it that need to read a binary file. Sending the path from .mm file to cpp file via a function call is not an option unfortunately. The only way I see is the cpp file somehow should call a function in .mm file which would then return the exact path to the binary file. How may I do that?
Asked
Active
Viewed 625 times
1 Answers
2
Sounds like calling a ObjectiveC method (returning the file path from the application bundle) from C / C++ is what you want to achieve. This SO question has the answer How to call an Objective-C Method from a C Method?
To obtain the actual path of the binary file add it to your Xcode project and make sure to add it to "Build Phases" > "Copy Bundle Resources" phase inside the Xcode project setting.
Call
[[NSBundle mainBundle] resourcePath]
to get the path to the directory that should contain your binary file.
Don't forget to look up the helper methods like
[NSString stringByDeletingLastPathComponent];
when working with file paths.
-
Thanks for the reply, However the link provided requires me to initialize a variable called param of type id, before being able to do any objective c call. My cpp class is parsing a 3D object file and reading texture file names and than reading them into memory. Also this class is created and called by other cpp files (deep enough), what would you recommend? having a global cpp class called settings and keep a variable called param with type ID – happycoder Apr 21 '16 at 20:13