How to use in ObjectiveC project C++ files - iphone

I have a reqular objective C project. I import 10 C++ files into my project. All this files take "are communicating" with each other. If I have a look at File1.h, this file can manage all the operations in other class.
So, the question is How to include reference to File1.h and to call functions from it.
For example: [File1Class getAudioData];
If I include it by #include "File1.h", I will get a error "Class is unknown element"
P.S. I want to import aurioTouch2 sample code to my project and to call functions from theire C++ code.

You Can simply open both the projects in Xcode and drag and drop the files you need from the aurioTouch2 application. Make sure the files are actually copied by selecting the check mark that you get after you drop the files in your xcode project. After this, you will be able to use those files/classes. Consider using ".mm" as the extension of the implementation file in which you want to use the c++ files/classes. You may also use ".mm" as extension for your appdelegate implementation file in case you get c++ related errors.

Related

Wrap a C++ library in Swift code, compile as a Cocoa Touch framework

I have a C++ library that is full of warts and weird features, and I want to make it much easier to use (and reuse) in a Swift project. So I intend to wrap this C++ library in some Swift code, then make it available as a Cocoa Touch framework.
I've added both my (fat) .a file and the required .h files to my project, then added the .a to the "Link Binary with Libraries" section of Build Phases, and added the main .h file to the Project section of the Headers build phase. But the build fails with:
Library not found for -lMyLib
I'm obviously missing something here - I'm guessing maybe I need to adjust the Framework Search Path and/or Header Search Path? Or am I missing something more fundamental? My desired end result is a .framework another developer can pull into their Swift project without having to do any other build setting tweaks.
You're probably looking for "Library Search Paths" (LIBRARY_SEARCH_PATHS). You may need to add to "Header Search Paths (HEADER_SEARCH_PATHS) as well, depending on your setup. In this case, you shouldn't have to add anything to the Framework search paths, since you are not dealing with a Framework.
(As an aside, you are likely going to find that you have to wrap your C++ library in Objective-C++ code to expose the functionality to Swift.)

Library Project Reference in Xcode

I know something like this is already asked many times on SO, but I've tried everything (been at this for three hours now) and I still didn't find a solution. I'm quite new to xCode and I'm starting to work on a project that was originally created by somebody else.
So, I have a library project in my xcode (XS2Library) and now I would like to reference to that library in my other project (WaarBenJij). Building the Library succeeds and I reference to it by adding the LibXS2Library.a to the Project target's "Link Binary With Libraries".
Xcode doesn't give me any errors, so it looks like the library project is referenced appropriately. However, when I try to build my project I get the error that a class that resides in my library project cannot be found ("'XS2URLLoader.h' file not found").
Can anybody steer me in the right direction, maybe?
There's a sensible difference between the .a file, which is needed for linkage and contains the library source, and the .h file, which is needed to compile (and preprocess) and which contains the functions and classes declarations.
Here you included the .a file, which is required for a later step, but to use the library you also need to import the required .h files into your project.
The easier way is to simply put them in your project.
Or you can add the whole library as a subproject and as a dependency.

How to integrate aurioTouch app functionality in other app?

I am trying to integrate aurioTouch app functionality in my app but I am having problems because few portion of that app is written in C++ and for this I changed my .m file into .mm but still having issues. I have added the image. Please see/ How this error can be resolved?
Read this:
https://stackoverflow.com/a/4714727/88461
If you have a .cpp file with C++ code that needs to use Objective-C as
well, either rename that .cpp file to .mm or pass -x objective-c++ to
the compiler.
I also faced the same issue and was unable to sort it out for a very long time. The real problem starts when you import the auriotouch's .cpp classes in to your project. Generally while doing that we face a lot of compilation errors and sometimes linker errors. So,
First:
Change the extension of all of your class files in your project from .m to .mm. This will make your class files to support both C++ and objective C codes. [If not, u'll face multiple compilation issues]
Second:
Check whether you have imported the class files(.m, .mm or.cpp) in Project->Targets-> build phases-> Compile sources. [If not, u'll face linker errors]
Third:
Try to check whether u have properly declared the global variables in your class files. [If not, it might show duplicate symbol error]

Use C++ static library in Objective-C Xcode project

I made a cocoa touch static library in iOS in which I have C++ classes (.h and .cpp files).
I built the project successfully, but when I include this library (having .a extension) and any .h file, I get a compilation Error.
How can I add this library in my objective-C project and use the C++ classes?
Your problem is likely that the .h header contains C++ code. You should read up on "compilation units". In short, there's no way to tell what language a header file is written in for the compiler. Therefore, it always uses the language of the source file that includes the header. So if you include a C++ header from a .m file, it will not work.
But there is a solution: Apple invented a "new language" it calls Objective-C++ that lets you write both C++ and Objective-C statements in the same file. For every ObjC file that uses a C++ header, you have to change the file name suffix of the source file that uses it from .m (ObjC) to .mm (ObjC++), which means the source files will be able to compile both ObjC and C++ headers.
Of course, you may not want to change all your files to be ObjC++. For one, C++ (and by extension Objective-C++) is a language with much more complex syntax than C and Objective-C, so your compile times will be longer, and also, C++ behaves differently in some aspects than C (and by extension, ObjC++ behaves a bit differently than ObjC).
What people usually do is constrain the C++ parts to their implementation files, and keep C++ out of the header. They write an Objective-C class that "wraps around" the C++ class, and provides methods that call the corresponding C++ methods on the C++ object. Then any ObjC file in your project can include that class, without having to turn on the ObjC++ compiler itself, which internally ("secretly") uses ObjC++ to call the C++ code.
For some useful tricks on how to hide C++ code inside an ObjC class, see Can I separate C++ main function and classes from Objective-C and/or C routines at compile and link?
Most probably you just should rename your .m files which are objective-c specific to .mm files that can accept C++ code (objective-c++).
Second is to check if everything it depends on is properly included before your library header.
Also check the architecture you have built your library for. If you run on an emulator - it should be x86, if for deploying to device - arm.
If you built the .a on the same system, there shouldn't be a problem #includeing its headers and linking against it.

How to use fopen from a C library while Using iPhone SDK

I apologize in advance if this has been addressed, but I have not found a specific answer as of yet.
First, I am trying to use a C library in an iPhone/Cocoa touch app. It compiles fine as a plain C project and as a plain Foundation project (using X-code). My problems is this: The library uses a dictionary file which is called directly using fopen(). My question is how can that file be accessed on an iPhone from a C library which does not or cannot use Objective-C/SDK routines. I'm assuming that there is a way...somehow.
Thanks!
I think fopen is ok. But XCode put all resource files into the root directory. So maybe you should rewrite the library to open the file from the root.
Other solution is to create "folder reference" with "Add to project" menu. This way I think the whole folder will be copied to the app bundle.