I've a task in which I need to use a .a c++ library (don't have any idea what is the code in that library) with a header file having some methods declared in it. Now what I need to do is to call these methods from my objective c class. for this I've done following things:
changed the extension of my view controller class from .m to .mm
set my 'other C++ flags' in build settings to objective-c++
all other steps which were suggested at stack overflow and any where else.still I'm not able to use that library. An example will give you all the better understanding on my problem:
suppose We've a library mylibrary.a,We also have a header file named myHeaderFile.h. Now we need to call a method named 'int Login(unsigned long *LoginInfo)' which is declared in myHeaderFile.h header file. What should be done? The screen shot is the crash report when I try to call C++ method
What can be mistake here,please suggest. A quick help will be appreciated...
Attach to the app with any debugger or turn on Error Reporting to see what exactly crashes.
UPD: Apple's LLDB tutorial. You need these steps:
Specifying the Program to Debug
Launching the Program with LLDB (r, then Enter)
Finally, when it crashes, type bt, then Enter.
Related
I would like to ask if there is a possibility to check a built-in function implementation in Xcode IDE. I mean - is there something like CTRL + [click on function name] in IntelliJ? I need to check arc4random() implementation.
In Xcode, you can hold command + click on function name to jump to file which function is defined (.h file).
If it's a built-in function, you can only see in .h file (Header file). You can't open built-in function in .m or .ccp file.
With arc4random() you can open stdlib.h but you can't check how it's implemented from XCode. Luckily you can check it here https://opensource.apple.com/source/Libc/Libc-997.90.3/gen/FreeBSD/arc4random.c.
opensource.apple.com is provided by Apple
EDIT:
To open stdlib.h from Xcode
Step 1: command + click to arc4random()
Step 2: Look at navigation bar
Step 3: Right click on stdlib.h
Step 4: Click on include folder and you will see what you want.
You can't access this specific implementation because it is Operating System's specific. But I think it's pretty likely that it's the same as BSD's implementation, since the Apple documentation describes it as "BSD Library Functions".
Edit: Being more specific, this function is part of the C standard library, and it's common practice to simply link it with the binary version distributed as part of the OS. So only the headers are normally available. Apple makes their libc source code available in the http://opensource.apple.com site though.
More broadly speaking though, you won't find the implementation of most Apple-related frameworks, except maybe Foundation, which is currently open source, and the Swift standard library.
you can't check implementation because it is defined in stdlib.h and you don't have its implementation file access.
I see there’s many libraries, open source, like Cocos2d, ShareKit, FormatterKit, etc. that seems up to date. (Check GitHub).
But still, implementation, snippets, samples and manual are intended to be written in Objective-C.
But, a method is a method… I think… If I get an instance of any framework/library of these and I call the method in a full Swift enviroment, would I be affected behind the scenes?
After June WWDC Swift gonna get serious, Apple is pushing hard, I’m just getting ready for the move and I don’t want my Apps to implement a soon-to-be deprecated library implementation in Objective-C.
I do not understand your question so much that I will regard your question as "Is it possible to use the Objective-C&Swiftin the same project?"
Yes, Apple claimed that developers can use Bridging-Header to implement double languages development, whatever your main developing language is ObjC or Swift. The specific details and theories about it you shall check from there.
Next I want to tell you some errors occurred in my project when I used Bridging-Header.
I always meet this kind of problem like import 'file not found'. I think you can try to check your file&folder hierarchy. Such as you have a root folder named Project, as is often the case, there is another Project in your previous Project, the root folder.
And Checking the Objective-C Bridging Header in the Build Setting. Sometime error can occurred for Project/Project/Bridging-Header.h. And the error can be corrected by changing the definition as Project/Bridging-Header.h.
If the location of Bridging-Header.h is not matching with the definition in the Build Setting, the error like import file not found will occur.
I just tell your my solution for Bridging issue I already met, I hope it can help you.
I am very new to the field of ios programming and working with linker is just a whole new world to me. I would try my best to be precise about my question.
Context: Static library linking in an ios project using xcode.
Problem:
Problem members:
3 static libraries.
libTestLibA.a
libTestLibB.a
libTestLibB_mine.a -- same functionality as libTestLibB.a -- same classes/methods everything.
Problem description
I am making an app using libTestLibA.a.
libTestLibA has some classes that depend on some classes from libTestLibB. Hence libTestLibA.a has libTestLibB.a compiled in itself.
Now, I have my own library named libTestLibB_mine. It has the exact same functionality as that of libTestLibB. Same methods / classes for same functionality. I want libTestLibA to use libTestLibB_mine instead of libTestLibB. I just have compiled static libraries (.a) for each of the problem members , ie, libTestLibA, libTestLibB and libTestLibB_mine.
Question:
When I compile my application, can I force a static compiled library (libTestLibA.a) to make use of another library (libTestLibB_mine.a) instead of what it already contains (libTestLibB.a)? If yes, how? If not, is there some work around?
Much thanks.
If A has already been statically complied against B, then I don't think you can replace B with B_mine. But as a workaround, I think what you might be looking for here is "Method Swizzling". What it does is, at runtime, replace the method of a class with another method (intercept the message and direct it somewhere else).
The following links should be useful to you.
CocoaDev Method Swizzling
JRSwizzle - open source library to make swizzling easier
Be sure to read about the dangers of method swizzling too.
I am creating an iphone test using c++,and I want to use nslog( the only way to show debug information?) whenever I want to include nslog function my cpp has to change to mm right? is it the only way to do it? because I don't want to change back to cpp when I move to other platform.
thanks for help
Since NSLog only exists on Objective-C platforms, why not create your own LogMessage() method taking standard C++ arguments in a single .mm file that calls NSLog and call that from C++ files named as usual. That way you'll not need to rename every single file that needs to log to .mm
On other platforms, just include another implementation of LogMessage() since there's no NSLog to call there anyway.
I had built PJSIP 2.7.1 and was integrating it for an iOS app written in Swift. Everything worked so I believed it was built the right way, all libs and headers were in the right place too, until one day I was trying to call lib functions from an external thread so I had to register this thread by using pj_thread_register() and declared a pj_thread_t type variable, the compiler started to complain about that the type pj_thread_t was undeclared.
I found the pj_thread_t was declared in pj/types.h and was defined in pj/os_core_linux_kernel.c. The types.h was already included in the header search path and I supposed it should work. I guess I must have missed something here.
I met the same problem in my Swift project. My solution is create a kind of wrapper file in ObjC. Swift and ObjC works with memory in different ways. This is why my wrapper works good. Now I can call pj_thread_t inside my wrapper file.
pjsip (C) --> MyWrapper file (ObjC) --> myProject' files (Swift)
MyProject-Bridging-Header.h file contain only one row:
#import "MyWrapper.h"