I've decided to take a step back and just try to get a very simple proof of concept to work.
I've progressed a little further thanks to one of the Xamarin Lightning Lectures around this topic. I’ve been following this tutorial:
https://university.xamarin.com/lightninglectures/ios-bindings-in-cc
Here’s what I’ve done so far:
1) I have a simple C file “example.c” with 3 functions: addOne(int n), subtractOne(int n), get_time()
2) As shown in the tutorial, I used SWIG to create a C wrapper class - “example_wrap.c” (along with the C# wrapper classes).
3) I created the static library in Xcode and built a FAT binary with all architectures (lipo used to combine libs).
The tutorial talks about creating 2 projects - one with the C# wrapper classes and the other a single view iOS app. The iOS project has the libexample.a static library(as a BundledResource). Everything was going well until trying to build the iOS app. I can't get the iOS app to compile. I've removed any calls to the static library for now to isolate the issue....I'm just trying to get it to compile and link correctly. So all I have now is just a blank iOS app with the bundled static library. But I'm still having problems.
I have the following added to the mtouch arguments:
-cxx -gcc_flags "-L${ProjectDir} -lexample -force_load ${ProjectDir}/libexample.a"
When compiling, I get these errors:
Undefined symbols for architecture x86_64:
"subtractOne(int)", referenced from:
_CSharp_subtractOne in libexample.a(example_wrap.o)
"addOne(int)", referenced from:
_CSharp_addOne in libexample.a(example_wrap.o)
"get_time()", referenced from:
_CSharp_get_time in libexample.a(example_wrap.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I double checked the symbols in the libexample.a file by running “nm -arch x86_64 libexample.a” from the command line. It appears that all the symbols are listed for that architecture.
Here’s a link to the zip file with my libexample.a and C files:
https://drive.google.com/open?id=0B2WtJ38rvldKYmlZckU3QjNBeUE
I’m sure this is just a configuration error but I can’t seem to pinpoint where I’m going wrong.
Thanks.
I thought I'd answer my own question here - after getting some help from Xamarin support, it looks like I might have mixed up how I created the static library - I had to make sure the files were compiled as 'C' files, instead of C++. After I generated the static library correctly, the compiler was able to recognize the missing symbols.
Related
I've got three layers:
- core C++ engine
- iOS audio wrapper
- demo iOS consumer project
So I am:
1) compiling engine.a, which links against accelerate framework.
2) compiling wrapper.a, with a dependency on engine and linking against engine.a AND accelerate framework.
So far so good. I can build wrapper.a. But something looks wrong. My wrapper code is using CoreAudio calls. It is fetching real-time microphone data. It should be reporting errors, surely? It should be requiring me to link AudioToolbox or AudioUnit frameworks.
So I don't see why that library even compiles.
3) create a fresh iOS project that links against wrapper.a.
Now I'm getting a 30+ build errors:
```
Undefined symbols for architecture x86_64:
"vtable for std::exception", referenced from:
std::__1::bad_function_call::bad_function_call() in libfftDecoder.a(FFTDecoder.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"std::__1::__thread_struct::__thread_struct()", referenced from:
std::__1::thread::thread(void (DecoderThread::&&)(), DecoderThread&&) in libfftDecoder.a(FFTDecoder.o)
"std::__1::__throw_system_error(int, char const*)", referenced from:
std::__1::thread::thread(void (DecoderThread::&&)(), DecoderThread&&) in libfftDecoder.a(FFTDecoder.o)
:
```
Can anyone suggest what might be the problem? That first error kind of looks like 'failing to process a C++ construct'.
I should mention that Xcode is very disappointing in the context of this task. The items I link against in the 'build phases' tab are not consistently reflected in the project navigator's "frameworks" folder for the respective project. Also sometimes a .a appears red even when it built successfully.
First point (thanks #wiliz on #iphonedev Freenode) is that a static library has no concept of linking against something. So I should be removing all the links from my .a files and putting all of the dependencies in my consumer app.
The problem was that the library contains compiled C++ code. And the consumer app doesn't have any .mm files. So it isn't using ObjC++ anywhere. So it isn't linking against the C++ stdlib.
Simply renaming one of the .m files (say ViewController.m) to .mm fixes the problem.
I developed a very simple application, using openCV for iOS. It worked fine until I decided to use that code in another project. The new project shows this armv7 error and I can't see where the problem is (please, see the last image).
I created a static lib file with my working code, which has the following architecture info:
Then I compiled it into a *.a file and added the dyOpenCv.a and the DyOpenCV.h files to my main project, which has the following architecture configuration:
But when I try to use the method within the header file DyOpenCV.h I get the following errors:
Any ideas of what may be wrong?
There were two issues related to linking libraries:
Firstly, although my subproject had the opencv2.framework
correctly added and linked to it, I also had to add the framework
to my main project. This way I got rid of the cv::* linking
problems;
The second issue was related to my cross-compiling Objective-C++ configuration. Since I was using libc++ as my Standard Library, I had to add -lc++ to my Other Linker Flags. In case you are using libstdc++ as your Standard Library, you should add -lstdc++ instead.
After those changes, it all worked perfectly!
Good luck!
I think its because ur project is not linking to the C++ runtime .
Try adding libc++.dylib to ur linked Libraries.
I am trying to do extension development, but I am running into an error linking my code -- it's not finding NS_NewGenericModule2.
Undefined symbols for architecture x86_64:
"NS_NewGenericModule2(nsModuleInfo const*, nsIModule**)", referenced from:
_NSGetModule in meta.o
ld: symbol(s) not found for architecture x86_64
I'm using MacOsX lion... Does anyone have a XPCOM module or a Mozilla Extension with c++ and could share the source code?
You seem to be using some very outdated example code - NS_NewGenericModule2 has been removed from the Firefox codebase in Firefox 4, along with major XPCOM changes. I'm not sure how you managed to compile you code and why the issue only comes up when linking - normally (when using a current XULRunner SDK release) you should get an error already during compilation.
As to current example code, there is one in the Firefox code base. Have a look at nsSampleModule.cpp for a module definition example, nsSample.cpp contains the actual XPCOM object implementation.
I have a Cocoa app that compiles and links fine. I've since broken out some of the code into a static library and then have gone back and tried to link that libMyLib.a library to my original program.
I now get a linker error
Undefined symbols for architecture x86_64:
"std::terminate()", referenced from:
referencing one of the source modules that use to live in my main project, but now lives in the library.
I've tried to go back and match up each compiler and linker setting to see which one is different, but I just can't seem to nail it down. My hunch is that I'm linking with a C STD and need a C++ STD, but everything is using the C99 compiler with standard libs.
Any ideas?
Thanks!
linking in libc++.dylib fixed the issue
I've already spent countless hours puzzling over this, utilizing Google searches and other Stack Overflow questions to no avail.
I have an iPhone/iPad universal application, which seems to compile fine when the target is armv6. However, when the device is iPad, I get this warning:
warning: building for SDK 'Device - iPhone OS 3.2' requires an armv7 architecture.
Oddly enough, the app still runs great on iPad in spite of this warning. However, I do want to do things the "right way" what ever that means in this case. When I switch the target architecture to armv7, I get linking errors:
"___restore_vfp_d8_d15_regs", referenced from:
*redacted*
"___save_vfp_d8_d15_regs", referenced from:
*redacted*
ld: symbol(s) not found
collect2: ld returned 1 exit status
The "redacted" portions of the errors are references to the static library to which I'm trying to link.
Here's what I've tried from the many suggestions online. Each of these were suggested more than once without any explanation, which leads me to believe nobody quite understands this problem:
"Never use the drop down menu in the upper left of the XCode window to choose the target. Instead, set this to Base SDK and then the Base SDK to iPhone OS 3.0 in the target configuration. Set the target device to your preferred target (iPad, iPhone OS 3.2 in my situation.)"
This yields the error "Library not found for -lcrt1.3.1.o"
"Make sure that GCC isn't linking against the wrong version of the standard library. (You'll have to make sure the LIBRARY_SEARCH_PATH doesn't have the wrong path in it.)"
My LIBRARY_SEARCH_PATH is already empty, so this doesn't seem relevant.
"Try compiling with GCC 4.0 rather than GCC 4.2."
I get a syntax error inside a UIKit header file. The error is "Syntax error before 'AT_NAME' token." The line is "UIKIT_EXTERN #interface UILocalizedIndexedCollation : NSObject."
Another project compiles just fine with the same target settings, which is really making me question my sanity. Could I be dealing with a corrupt XCode project?
If anyone knows what's actually happening and has a reference or doesn't mind explaining it, I would be so very grateful.
Cheers!
VFP between ARMv7 and ARMv6 differs in various ways. In ARMv7 its usually preferable to use NEON. The problem is your static library depends on VFP in ARMv6 - you either need to compile the library at ARMv7 or keep the whole application at ARMv6.
Reverting back to GCC 4.0 is silly - ARMv7 support was basically nonexistent back then unless Apple backported it.
I had the same errors except it was for armv6. I fixed them by unchecking "Compile for Thumb" in the project settings for the static library and the main project.
try do like this http://groups.google.com/group/three20/browse_thread/thread/31ddbc047aa1b9ae/c4c5827ab0c7a76f
As far as AT_NAME error is concerned one of the possiblity is
Check if you miss the #end in a class.
To know more about AT_NAME error visit the following link
http://iosdevelopertips.com/xcode/error-syntax-error-before-at_name-token.html