iOS Math: undefined symbols fr architecture arm7 - ios

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.

Related

Undefined symbol _UnitySendMessage

Define a method in the .mm file
#if defined(__cplusplus)
extern "C"{
#endif
extern void UnitySendMessage(const char* obj, const char* method, const char* msg) __attribute__ ((weak));;
extern NSString* _CreateNSString (const char* string);
#if defined(__cplusplus)
}
#endif
#interface UnityAdapter ()
...
Called in #implementation UnityAdapter()
UnitySendMessage("PottingMobile", "bannerDidLoadAd", "");
I need help solving the following error:
ld: warning: Could not find auto-linked framework 'FBSDKCoreKit'
Undefined symbols for architecture armv7:
"_UnitySendMessage", referenced from:
-[UnityAdapter bannerDidLoadAd] in UnityAdapter.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
when i don't use UnitySendMessage method, everthing is ok.
I want to write a framework for bridging unit and iOS projects. When I use it in a unit packaged project, no problem. When I put the bridging file into my own framework, I will report an error. There is nothing in the framework project. Do I need to integrate unit's lib? If so, how to integrate? Can you give me a website? Thank you.
Unity is currently doing this with their library feature.
You can look at their solution.
If you need a solution now: Have a look at https://github.com/jiulongw/swift-unity. It's all automated and a good starting point, but missing the library feature.
This project shows how to make an actual library: https://github.com/forestlin1212/unity-ios-framework (But for an older Unity version and not automated)

Linker Command Failed with exit code 1 (Use -v to see invocation) iOS Error

In my application I'm using a static library named ABC.a in that library in a c file named Layout.c there is a function called init(). And I linked the library to the projects and added the .h file. The program is compiled without error but while linking the function its throwing the error. Why?
Info: I've added that static library in build phases also.
And the library is built for armv7, armv7s and arm64. bitcode enabled: No and Build active architectures : NO
Example error:
Undefined symbols for architecture arm64:
"AMID_INIT(int*, int*, int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
"amid_Val(float const*, int, int*, int, unsigned int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
Please help two days gone for this.
This is based on the fact that you mention that the .a file is generated from a c file. The linker error:
"AMID_INIT(int*, int*, int)", referenced from:
-[ViewController microphone:hasAudioReceived:withBufferSize:withNumberOfChannels:] in Test_lto.o
indicates that the AMID_INIT definition came from a C++/Objective-C++ file - this is because C files would not have information about the parameters of the routine.
From this I was able to surmise that the library header file did not have c++ guards.
Three approaches in this case - wrap all imports of the library header file in the C++ code with something like:
extern "C" {
#import "lib.h"
}
or create a lib.hpp file, containing:
#pragma once
extern "C" {
#import "lib.h"
}
and #import 'lib.hpp' instead, or fix the lib.h file by adding the standard name mangling preventative:
… near start of lib.h:
#ifdef __cplusplus
extern "C" {
#endif
… near end of lib.h:
#ifdef __cplusplus
}
#endif
This allows you to keep using the lib.h with both C and C++ compilers by declaring that all the routines offered by lib.h are exposed using C linkage, rather than C++ linkage.

Undefined symbols for architecture x86_64: "_nlist"

In adding 64 bits support to some iOS code I maintain, I found that the nlist function is not available for the x86_64 architecture (64 bits iOS simulator). Code invoking nlist() works fine for all other archs (armv7, armv7s, arm64 and i386) but will not build successfully for x86_64, where the linker fails to find the symbol in the linked libraries.
It can be reproduced on a template project created with Xcode, by simply adding:
#import <mach-o/nlist.h>
int testnlist()
{
struct nlist nl[2];
bzero(&nl, sizeof(struct nlist) * 2);
return nlist("test", nl);
}
Results in:
Undefined symbols for architecture x86_64:
"_nlist", referenced from:
_testnlist in ViewController.o
ld: symbol(s) not found for architecture x86_64
Tested on Xcode 6.1.1 with iOS SDK: 8.1, building for iPhone 6 simulator.
Looks to me like Apple might have forgotten to include some of the simulator's shared libraries built for x86_64, but I might also be overlooking something stupidly obvious...
you might want to try:
#ifndef N_NLIST_DECLARED
struct nlist
{
union
{
char *n_name;
struct nlist *n_next;
long n_strx;
} n_un;
unsigned char n_type;
char n_other;
short n_desc;
unsigned long n_value;
};
#endif
which I extracted from:
<https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/android-4.1.2_r2/lib/gcc/x86_64-linux/4.6.x-google/include-fixed/linux/a.out.h>
in that same header file, you will find lots of other things that
will be 'gotcha's when moving to 64bit code

Missing symbols from LayarSDK in the simulator

I'm including the Layar SDK framework into my app (version 8.0) and everything works fine on a device.
However, I can't run the app on a simulator anymore - I don't mind Layar not working (there's no camera after all!) but I do need it to compile for continual integration, automated tests etc (not to mention developing on the train top/from work!)
The linker gives me these errors :
ld: warning: ignoring file /Users/username/Documents/appname/libs/MPOAuth/libMPOAuthMobile.a, missing required architecture i386 in file /Users/username/Documents/appname/libs/MPOAuth/libMPOAuthMobile.a (2 slices)
ld: warning: ignoring file local/LayarSDK/LayarSDK.framework/LayarSDK, missing required architecture i386 in file local/LayarSDK/LayarSDK.framework/LayarSDK (2 slices)
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_LayarSDK", referenced from:
objc-class-ref in MYAppDelegate.o
ld: symbol(s) not found for architecture i386
Checking, the LayarSDK doesn't contain i386, it only contains armv7 and armv7s.
My solution is pretty clumsy - if anyone has a better idea, please let me know!
I compile this file (LayarSimulatorStub.m) into my app :
#if TARGET_IPHONE_SIMULATOR
#import <Foundation/Foundation.h>
#interface LayarSDK : NSObject
#end
#implementation LayarSDK
+ (id)layarSDKWithConsumerKey:(id)a andConsumerSecret:(id)b andDelegate:(id)c { return nil; }
- (id)init { return nil; }
- (id)initWithConsumerKey:(id)a andConsumerSecret:(id)b andDelegate:(id)c { return nil; }
#end
#endif
Now, there is an i386 symbol LayarSDK. It just returns nil from all it's constructors. The app now compiles with Layar disabled.
The conditional compilation means that it's not present for the device architectures so there are no linker errors.

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

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.:(

Resources