How to fix linker error " Undefined symbols for architecture i386 from: "_current_task" "? - ios

In kern/task.h, i found the declare:
__BEGIN_DECLS
extern task_t current_task(void);
extern void task_reference(task_t task);
__END_DECLS
But when i call the function current_task() in an iOS application.
I got the linker error like:
Undefined symbols for architecture i386 from:
"_current_task", referenced from:.... in xxx.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
How to fix this problem?

A simple solution:
Use mach_task_self() to replace the function current_task. Still could returns a pointer to the task structure associated with the currently running kernel thread.
But i still want solve the problem above.:(

Related

.c File via Bridging Header Not Working After Xcode 8 Update

The app I've been working on uses an external library, pdlib, which has it's own externals (.c files) which I've been importing via the bridging header #import "Uzi.c" and calling in my main Swift file via Uzi.c's setup function Uzi_setup() in my ViewController class. I've had no problem with this until after updating to new public Xcode 8 a few days ago (I had no problem with Xcode 8 Beta 1 over the Summer).
Here are the 7 errors I get, listed under a single "Mach-O Linker Error" umbrella:
Undefined symbols for architecture x86_64:
"_Uzi_bang", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_class", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_float", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_new", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_pause", referenced from:
_Uzi_setup in ViewController.o
"_Uzi_resume", referenced from:
_Uzi_setup in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Those undefined symbols are 6 functions and a class declare from Uzi.c. Here's a link to the whole c file: https://github.com/electrickery/pd-miXedSon/blob/master/hammer/Uzi.c
I've tried every solution I've found online for dealing with similar problems, with no solution yet... I tried changing the "Architecture" and "Valid Architecture" settings to only armv7 and armv7s (no arm64) and changed "Build Active Architecture Only" to "No". These step seem to help others in similar situations, but they didn't work for me (and taking away arm64 causes additional errors to appear).
XCode 8 is pretty recent (the public version was released Sept. 13), so there are virtually no other questions about this upgrade causing a similar problem.
Any help would be greatly appreciated!
Solved by #danomatika on GitHub: https://github.com/libpd/libpd/issues/149
"You generally shouldn't include/import an implementation file aka .c, .cpp, .m, etc. This is what is causing the duplicate symbol issue.
This is what the "forward function declaration" in the header file is for: to tell the compiler that a function exists and what data it takes/returns. The compiler then assumes the actual implementation of the function exists in an implementation file. If it can't be found, then you get an "undefined symbol error." If you somehow end up declaring the function twice, aka include both a header with the forward declaration and the implemetaton of the function itself in the .c file, then you get a "duplicate symbol error."
This is all lower-level stuff that is only really an issue since Pd externals are designed around being dynamic libraries, so are not built or provided with headers which include the function declarations. This is why you have to do a little extra work and do it yourself.
Their are two easy fixes for this, both of which involve declaring the required function you want to call from the .c file in a header file.
Simply declare the function in the bridging header:
void uzi_setup();
Create a header, say Externals.h, and declare all of the externals stuff there:
// forward declare setup functions only found in .c implementations
void uzi_setup();
// convenience wrapper function
void externals_setup() {
uzi_setup();
}
Then import the file in your bridging header:
#import "Externals.h"
And in swift, you can now do:
externals_setup()

Array initialization is causing build to fail - arrayForceCastU

This line of code is preventing my project from building:
var allAttributes: [UICollectionViewLayoutAttributes] = []
I tried var allAttributes = [UICollectionViewLayoutAttributes]() and it too fails to build.
Here are the error details:
Apple Mach-O Linker Error:
Undefined symbols for architecture i386:
"__TFSs15_arrayForceCastU___FGSaQ__GSaQ0__", referenced from: __TFC42com_myname...30ClassWhereCodeIs33layoutAttributesForElementsInRectfS0_FVSC6CGRectGSqGSaPSs9AnyObject___ in ClassWhereCodeIs.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What is the proper way to initialize an array so that I may append objects to fill it?
That first line builds fine for me in a view controller class.
Have you tried deleting the Derived Data?
Window Menu > Organizer -> Projects -> choose Project. There's an button on the right to delete the Derived Data.

How do you debug missing symbols as reported by linker especially of compiler __builtin* functions?

I keep getting the following error from the linker:
Undefined symbols for architecture armv7:
"___clear_cache", referenced from:
However when I do the following,
#if __has_builtin(__clear_cache)
#error clear cache is defined
#endif
I get this confirmation:
/Users/myHome/Projects/proofOfConcept/coreEngine/icache.c:66:2: error: clear cache is defined
The code is written in standard C, and is using gnu make & clang.
Thanks.

iOS Math: undefined symbols fr architecture arm7

I'm getting the following error when trying to use C's math.h library:
#import <Foundation/Foundation.h>
#import <math.h>
#interface Filter : NSObject {
float cutoff;
float resonance;
float sampleRate;
float *f;
float freq;
float damp;
}
- (float)filter:(float)input;
#end
Can you tell me how I can solve this error? It seems that the min() function cannot be compiled to armv7 architectures.
Undefined symbols for architecture armv7:
"_min", referenced from:
-[Filter init] in Filter.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You are linking against a static library that is compiled for i386 or x86-64, in your specific case I think that you have referenced a library that contains min function but is not compiled for armv7 architecture, take a look at your referenced static library .
On iOS I had to use fmin() instead of min() as alex purposed. Further, i didn't even need to import math.h as Anoop said.

iOS-QR-Code-Generator linking issue

Need to generate QR code from iOS for different strings. Tried out the following library:
**jverkoey-ObjQREncoder-e1841fe**
being able to generate QR Code .. but this code cannot be read by any readers.
**iOS-QR-Code-Generator**
Following the documentation provided But facing linking problem when i am trying to add the 'kuapay-iOS-QR-Code-Generator' to generate QRCode. I followed the way that is written in the github project
"To build your own project from this template you must attace the libz.dylib library to your target in Xcode. You must also drag the QRDraw and libpng folder files into your project. Update the Header Search path to look in the libpng folder in your target build settings menu."
But it give me 6 error message. These are -
Undefined symbols for architecture i386:
"CQR_Encode::EncodeData(int, int, bool, int, char*, int)", referenced from:
-[RootViewController LoadQRImage] in RootViewController.o
"CQR_Encode::~CQR_Encode()", referenced from:
-[RootViewController LoadQRImage] in RootViewController.o
"_OBJC_CLASS_$_FileManager", referenced from:
objc-class-ref in RootViewController.o
"QRDrawPNG::draw(char*, int, int, unsigned char (*) [177], void*)", referenced from:
-[RootViewController LoadQRImage] in RootViewController.o
"CQR_Encode::CQR_Encode()", referenced from:
-[RootViewController LoadQRImage] in RootViewController.o
"vtable for QRDrawPNG", referenced from:
QRDrawPNG::QRDrawPNG() in RootViewController.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can anyone help me with this? OR suggest a better QRcode generator for iOS device?
Thanks a lot!
This issue is caused because you are using c++ code silently in your app , use .mm instead of .m in your RootViewController .
Check you have the file Barcode.mm, qr_draw_png.mm, QR_Encode.mm linked to your project target. Also you may be add "-fno-objc-arc" flag.

Resources