Duplicate symbols in iOS universal framework (i386) - iphone

I'm using iOS Universal framework
template.
I created framework and added them as sub project to another project.
And added framework binaries to the project.
in my framework there is some constants
const float kToolbarHeight = 45;
And when i'm trying to Build my Project and included Framework for
iphone simulator (i386), there are linker errors:
ld: 14 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
but when i build it for device - there is not any linker errors.
I'm tried to exclude subProject (my framework) from Project, and and keep only binaries, but there is not any effect.
I'm trying to change architectures in targets to the i386, and to the $(VALID_ARCHS), as
described in that issue, but there is not any effect.
How can I build framework for iOS simulator, what settings of target should I use?
Update: The problem was resolved when I defined
my constants as extern in header file.
// MyView.h
extern const float kToolbarHeight;
// MyView.m
const float kToolbarHeight = 45;
But why? What difference in simulator and arm builds?

The problem was resolved when I defined my constants as extern in header file.
// MyView.h
extern const float kToolbarHeight;
// MyView.m
const float kToolbarHeight = 45;
about extern

Related

Library not loaded: #rpath/somelib.dylib

I need to integrate a .dylib library and .h headers into iOS project to call its methods from Swift. It's illegal to add a .dylib file in iOS project, so I've tried to make a few workarounds:
Create a .xcframework with embedded .dylib and it's headers
Create a .framework with with embedded library binary, created using lipo command
Both workarounds compile successfully, but crashes when trying to run on a real device with message:
dyld[38413]: Library not loaded: #rpath/somelib.dylib
Referenced from: <6519D385-F3EB-3454-8CA0-02BF7E536629> /private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/TestApp
Reason: tried: '/usr/lib/system/introspection/somelib.dylib' (errno=2, not in dyld cache), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/private/preboot/Cryptexes/OS#rpath/somelib.dylib' (errno=2), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/usr/local/lib/somelib.dylib' (errno=2), '/usr/lib/somelib.dylib' (errno=2, not in dyld cache)
My guess is that some paths are setted up incorrectly, but I don't know how to fix that.
Here's content of my .h headers file:
#ifdef __cplusplus
extern "C" {
#endif
void ms_init(int width, int height);
void ms_draw();
#ifdef __cplusplus
}
#endif
I found a great answer to almost the same question, but the difference is that I use a .h headers.

Integrating un4seen BASS with Flutter using FFI and getting symbol error

I'm trying to integrate the BASS audio library from un4seen Developments with Flutter, Google's cross-platform app development environment. I've started a Flutter plugin that can be found here: https://github.com/JimTompkins/flutter_bass. It uses Flutter's FFI (foreign function interface) mechanism and a package called ffigen to convert the bass.h file to generated_bindings.dart.
Here is a snippet from generated_bindings.dart:
int BASS_Init(
int device,
int freq,
int flags,
ffi.Pointer<ffi.Void> win,
ffi.Pointer<ffi.Void> dsguid,
) {
return _BASS_Init(
device,
freq,
flags,
win,
dsguid,
);
}
late final _BASS_InitPtr = _lookup<
ffi.NativeFunction<
BOOL Function(ffi.Int32, DWORD, DWORD, ffi.Pointer<ffi.Void>,
ffi.Pointer<ffi.Void>)>>('_BASS_Init');
late final _BASS_Init = _BASS_InitPtr.asFunction<
int Function(
int, int, int, ffi.Pointer<ffi.Void>, ffi.Pointer<ffi.Void>)>();
It builds (Flutter 3.3, XCode 13) but throws a run-time error when I try to call the BASS_init function:
Failed to lookup symbol '_BASS_Init': dlsym(0x100f61e18, _BASS_Init): symbol not found
I can see the symbol in the libbass.a file using nm -gU libbass.a
Any comments/suggestions welcomed!
Update 2022-09-20:
I added the following frameworks to the Xcode build:
AVFoundation, AudioToolbox, SystemConfiguration, CFNetwork, Accelerate
In Xcode by going to Build Phase-->Link Binary with Libraries-->Add
This did not make any difference i.e. still getting symbol error
I checked that “Enable bitcode” is set to “No” in Xcode under Build Settings-->Build Options.
The search continues...
Updated 2022-09-29:
I got a hint from this Github issue post: use a force_load option to Xcode in the podspec file:
s.pod_target_xcconfig = {'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386', "OTHER_LDFLAGS" => '-force_load ($SRCROOT)/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a' } s.vendored_libraries = '($SRCROOT)/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a'
I tried this but now I'm getting a file not found error.
Could not build the precompiled application for the device.
Error (Xcode): File not found:
(/Users/jimtompkins/git/flutter_bass/example/ios/Pods)/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a
I checked and the file is there:
% ls -als /Users/jimtompkins/git/flutter_bass/example/ios/Pods/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a
1536 -rw-r--r--# 1 jimtompkins staff 785096 8 Sep 2021 /Users/jimtompkins/git/flutter_bass/example/ios/Pods/../../../ios/bass24-ios/bass.xcframework/ios-arm64_armv7_armv7s/libbass.a
Any hints greatly appreciated!
Update: 2022-09-30: fixed by removing ( ) around the $SRCROOT.
I also found that I needed to add the necessary frameworks to the OTHER_LDFLAGS command in the podspec file. See the Github repo.

Correct way to use a private library in objective c?

I downloaded a collection of private libraries from this link. When I click download I get all frameworks. So these are only header files not the .framework files that are available in Xcode. So I linked them by the usual method of going to build phases, in it I go to link binary with libraries click on + and choose the header files from a framework (preferences framework in my case). After these files are added to my project I try to make an object from one of the libraries and try to call their instance methods. When I try to execute this program I get this error. I get this whether I run it on the device or simulator.
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_DevicePINController", referenced from:
objc-class-ref in UAViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1
(use -v to see invocation)
DevicePinController is a part of a private framework preferences.h.I am trying to make an object of it UA
EDIT: I tried using other framework headers such as bluetooth and I get this error in all.
EDIT: I tried adding the entire framework to the project instead of adding individual header files.Now the error is
d: framework not found BluetoothManager
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You'll need to actually build the framework. You can't just link against a header file; that doesn't make sense.
Try adding all the .m files in the Preferences folder as Compile Sources, and remove the header file from Link Binary with Libraries.
Added: I realize now this answer is incorrect. The files OP is trying to use are not a library, but header files from Apple's private frameworks. Here's a related answer: https://stackoverflow.com/a/13388225/893113

Compiling ffmpeg for iPhone SDK (Symbol(s) not found - Linker)

I'm using ffplay in my Application. I implemented the Librarys which has been used in this Project: http://code.google.com/p/ffmpeg4iphone/downloads/detail?name=ffplay-xproj.zip&can=2&q=
But I've seen that this Sources are very old(Apr 2009). I wanted to Build new Librarys and then change it with these In my project.
What I've done:
Downloaded the ffmpeg Source code: (using command line: svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg)
Compiled the Project with special ./configure options and the gas-processor :
http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2009-October/076618.html
I only changed here the Paths of the actual locations for the iPhone SDK 4.1
Changed the header Path in xCode Active Target Project Settings to my ffmpeg folder
Included the .a files in my project in xCode
Added the Other Linker Flags -lm -lbz2 -lz
Tried to Build my Application, but I get some Linker errors where symbol(s) wasn't found.
Undefined symbols:
"avcodec_init()", referenced from:
And the other errors are nearly the same (_av_codec.....)
How can I build it correctly?
I've found the solution: I set the architecture to Optimized(arm7) and then all was working.
One more Question: I use ffmpeg for streaming an online stream. Which Values Should I set to get a good streaming quality also when I am in 3G. This what i've done:
set the audio-buffer to 1024
set the lowres value of mpeg to 3
Not sure if you are using C or C++ (g++) compiler, but try guarding your #includes for ffmpeg with extern "C": the c++ compiler (if it is used) is probably mangling the function names and hence the link errors.
Try to enclose your include with extern "C":
#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#ifdef __cplusplus
}
#endif

iPhone CATextLayer (QuartzCore framework) linking issue

I have the following code:
CATextLayer *test = [CATextLayer layer];
test.string = summary;
test.wrapped = YES;
//test.truncationMode = kCATruncationEnd;
//test.alignmentMode = kCAAlignmentJustified;
test.frame = s;
[test drawInContext:context];
I import the framework and link against it, however when it links I get the following error:
ld: warning: in
/Users/ryansully/Desktop/AppName/Project/1/AppName/QuartzCore.framework/QuartzCore,
missing required architecture i386 in
file Undefined symbols:
"_OBJC_CLASS_$_CATextLayer",
referenced from:
objc-class-ref-to-CATextLayer in StoriesCell.o ld: symbol(s) not found
collect2: ld returned 1 exit status
This is for an iOS project. I get this error in both XCode 3.2.3 and XCode 4 DP2.
I had the same issue. I resolved it by adding the framework somewhere in the project properties.
In the project properties (in the Project Navigator in the left of XCode interface, click on the project): Targets/[your project's name]/Build Phases/Link Binary With Librairies.
Then add QuartzCore.h (there is a "+" button at the bottom of the list).
Turns out XCode 4 is still buggy and can't add Frameworks appropriately. The issue was solved by opening the project in XCode 3, removing + readding the framework, then compiling.