Static lib linking error: Symbols not found for architecture - ios

I need to link FFMPEG's libraries (libavformat, libavcodec, etc) to my project.
I have downloaded as an example iFrameExtractor project, and have successfully build it.
xcode-proj opens fine and the sample app works fine, so I just took libs from this project to my one.
But xcode fails to build it, saying me
Undefined symbols for architecture armv7:
"av_register_all()", referenced from:
I checked target settings, and I cannot see any difference between my project's settings and iFrameExtractor.
I just moved all ffmpeg folder to my project's folder.
Notes:
1) nm commands tells me that this symbol is inside the library.
2) library is fat-file, including i386, armv6, armv7 architectures.
Please, help me, what am I doing wrong?

I just went through this yesterday :-)
In xcode, you need to add the .a file to the list of linked libraries in the project. The easiest way to do that is by dragging the .a directly onto the project entry in the navigation area on the left:
Alternatively, you can select them from the dialogs in the summary area of the project editor:
Just make sure you select the actual .a files, not the whole folder. Then, simply import their headers (as you are likely already doing...), and you should be good to go :-)

Related

How to link to libz and libsqlite in xcode 7 beta?

I got linkage error like:
+[WeChatApiUtil DecodeBase64:] in libWeChatSDK.a(WeChatApiUtil.o)
"_deflate", referenced from:
+[MTAWXOHelper GZip:Out:] in libWeChatSDK.a(MTAWXOHelper.o)
"_deflateEnd", referenced from:
+[MTAWXOHelper GZip:Out:] in libWeChatSDK.a(MTAWXOHelper.o)
"_deflateInit2_", referenced from:
But I've already added those library to my target. But currently all those library have different extension .tbd.
Any idea? Thanks.
There is a known issue in XCode 7 while linking tbd files. Here is the link to the apple developer forum answer on how to link tbd files in XCode 7 - https://forums.developer.apple.com/message/8609#8609
[Snippet from the link is available below]
This is a known issue in the Xcode 7 beta.
To work around this issue for now, please:
Delete all references to .tbd files from either your linked libraries phase, or from the copied bundle resources phase (where they sometimes will be added).
Add the library you want to link manually to the "Other Linker Flags" build settings, by adding the argument: -l for each library you want to link (for example, add "-lsqlite3" (without quotes)).
For those who are curious, the .tbd files are new "text-based stub libraries", that provide a much more compact version of the stub libraries for use in the SDK, and help to significantly reduce its download size.
I have two project using zlib, one which finds it to link, one which doesn't. I set them both up by using the "+" in "Linked Frameworks and Libraries". I finally figured out how to fix the non-working one:
Remove all links to zlib that you added in previous attempts
Open Finder, head to /usr/lib, and drag the libz.dylib alias into your project's Frameworks folder
Compile. This worked on 2015/08/23 for me.

Error compiling Redis library into iOS Project ("_OBJC_CLASS_$_ObjCHiredis", referenced from:)

I am trying to integrate the simulator static library of Redis into my iOS project and have done the following things.
drag and drop the static library into my project folder
Add header search path in the build settings
Check whether the static library is added into the build phases in settings.
Set the header search path
Set the other linker flags setting to "-all_load"
I am not sure where i have gone wrong but am geting the following error while compiling it.
Any help in this regard is greatly appreciated.
I was also getting such errors and figured out that adding .m files in "Build Phase" -> "Compile Sources" for the target fixed my problem.
Actually this happens if we miss to tick the Target Name in "Add to targets" name while adding any new library to it. (For your case, after drag and drop you might have seen a dialog box with options to copy items if needed, Add to target etc.)
Finally build and run. Hope this solves your problem!
The static library which you are dragging is not build for i386 architecture(simulator), try running your app on device, or build for device. Basically your app with the corresponding library will work on all such architectures for which it is built(armv7, armv64).
If you want to use the library and build your app on the simulator you need the static library which is also built for i386. And this could be provided by the developer of the static library.
Basically a fat(static library) file is created using static libraries for i386 and armv7(any required architectures) and shipped with the SDK of the static library which works on simulator as well as device.
The fat file is created by executing a lipo command on individual architecture static libraries.

Adding static library to project >> Undefined symbols

I have created a static library which I added to another project in the same workspace in XCode. The library builds fine, both for Simulator and an actual device.
All errors refer to classes in the library, so it's not about another framework.
I get two undefined symbols errors that both refer to "_OBJC_CLASS_$_Campaign"
When I build for an actual device I get Undefined symbols for architecture armv7s
When I build for a simulator I get Undefined symbols for architecture i386
I tried creating a fat library: same issue.
I toggled "build for active architecture only" on and off: doesn't help.
I deleted and rebuilt the XCode workspace: no solution.
I'm very sure I added the correct .m files to the "compile sources" of the library, and I properly added the library to the other project through "Link binary with libraries". I also tried just dragging the .lib to the Frameworks folder.
I added the header file of the .lib to the project.
I would be glad with any suggestion!
The problem is likely caused by the fact that your static library import something from another library.
You need to figure out what symbols are missing exactly and add library that defines them. Build log output should be very helpful in this regard.
EDIT: Based on discussion in comments, problem is caused by the fat that there's no implementation for Campaign class. Without implementation, compiler doesn't generate class and this results in linking error. There are no compile-time errors because interface of the class is declared though.
You should add such implementation, either in a separate Campaign.m file, or in one of already existing files.

How to link to coco2d static library (1.1 beta 2) using workspaces in Xcode 4.3.1

I have done the following so far:
Created workspace
Added my project
Added the Cocos2d iOS project (by dragging dropping into project navigator). It is a sibling of my project (not child).
In my project, in build phase, linked to libcocos2d.a
In build settings of my project - Set Always search paths to YES
Created source tree variable pointing to folder containing cocos2d iOS xcodeproj file.
In user header paths of my project, added source tree variable from step 6. Set as recursive.
8.In project navigator, clicked on libcocos2d.a library (it appears red). Set location "Relative to build products" You set this in the right most window in Xcode 4.3.1.
Closed workspace, and opened pbxproj file in TextWrangler. Searched for path containing libcocos2d.a Remove path, so the entry only reads "libcocos2d.a" . This is because after compiling the library is in the same build directory of the app anyway.
Codesense and autocomplete work. But this will not compile. Around 70 linker errors pop up when I try to build, all saying something like:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_CCDirector", referenced from:
objc-class-ref in AppDelegate.o
objc-class-ref in ViewController.o
"_kEAGLColorFormatRGB565", referenced from:
-[RIAppDelegate applicationDidFinishLaunching:] in AppDelegate.o
"_OBJC_CLASS_$_CCTexture2D", referenced from:
objc-class-ref in AppDelegate.o
"_OBJC_CLASS_$_EAGLView", referenced from:
objc-class-ref in AppDelegate.o
If I try to build for the simulator, then instead of armv7, it says the symbols are missing for i386. The cocos2d project by itself compiles & builds fine. It is my project which has the above errors.
The cocos2d library is present in the build directory of my app after I try to build.
EDIT: Forgot to mention. I also edited the scheme for my project to not build in parallel. I also added the cocos2d target, and made it the top of the list (so it should build first).
EDIT: To clarify - after making the changes to the pbxproj file as detailed above, the libcocos2d.a file is no longer red. It looks normal. Also my app is also built, even though there are the link errors and the build fails. (It doesn't actually build, but the product is not "red". An app file is created in the same location as where the cocos2d library is produced.
I've been trying for a while to use Cocos2d as a static library, instead of a template. The reason being that it makes it easier to develop my project in a modular fashion. In addition, it makes it easier to switch between cocos2d versions and so on. After searching the cocos2d-x forums I found this link: http://cfc.kizzx2.com/index.php/cocos2d-x-with-xcode-4-from-scratch-without-template/
I found out the frameworks that I needed to add, and that solved all linking problems.
I still haven't submitted an application to the store, so if someone with more experience could look it over to check if there are any pitfalls / errors it would be great. English is a second language for me, so please don't mind. This was done using cocos2d1.1beta2 and Xcode 4.3.1
Create an Xcode workspace
Navigate to the folder containing the cocos2d xcodeproj file (iOS / Mac). This is where you unzipped cocos2d after downloading it.
Drag and drop the xcodeproj file into the navigator window of Xcode.(left most window).
Click on the tiny triangle near the cocos2d project file so all its contents disappear.
Add a new project to your workspace by right clicking in the navigator and "New Project". Make sure that the project is added as a sibling to the cocos2d project, and not as a child. I chose single window application (iOS)
In this new project, go to the build settings, and change "Always Search User Paths" to "Yes"
Add the location of your cocos2d folder to "User Header Search Paths". If you like you can instead add the cocos2d folder to your list of source trees in Xcode, and instead just fill in the name of the variable here. Eg: ${COCOS2D_SRC} . This is handy if later on you want to change the folder structure of build environment.
Click on the target and select the build phases tab. You want to link the following binaries with your library. Make sure they are there.
libcocos2d.a
libz.dylib
libxml2.dylib
OpenGLES.framework
QuartzCore.framework
UIKit.framework
Foundation.framework
CoreGraphics.framework
If libcocos2d.a is "red", then don't worry about it. It still compiles / links properly.
Under build settings, change "Build active architectures only" to YES.
Otherwise you may get an error ignoring file /Users/Pteriedaktyl/Library/Developer/Xcode/DerivedData/Build/Products/Debug-iphoneos/libcocos2d.a, file was built for archive which is not the architecture being linked (armv6)
In your info.plist file, make sure to remove the entry inside "required device capabilities" that says armv7. Otherwise, your code will only run on newer devices.
Now you're set! You should be able to access the cocos2d api from the sibling project. If you ever want to change your version of cocos2d, you just need to change the cocos2d project that is in the workspace, update the source tree path (if necessary), and link to the new libCocos2d.a
Testing:
Just to try it out, I modified the app delegate and view controller code to match the code from one of my old hello world projects.
Please try this out, and add to the thread if you have any problems.
In the Utilities pane for the libCocos2d.a, underneath the Identity and Type where you set the library to relative to Build Products, scroll to the bottom and make sure that the Target Membership is selected for your targets. If it's not, it won't include it in the actual build made by the target. At least, that was the only way I was able to reproduce this issue.

Linker Error - Project not cleaning entirely?

I'm going to apologize in advance here. The project I'm working is under a couple NDAs so I'm not going to be able to be as specific as I would normally want to.
I'm working on an iOS project that includes a pre-compiled library in the form of a .h and .a file. I started development with a particular version of this library and everything was working fine. They've since released a new version that I need for a particular new feature.
Between the old and new versions, several of the function names have changed. When I update my code to call the new methods, I'm getting an Apple Mach-O Linker Error at compile time: (Names have been changed to protect the innocent)
Undefined symbols for architecture armv7:
"methodName", referenced from:
myMethod() in MyClass.o
ld: symbol(s) not found for architecture armv7
collect2: ld returned 1 exit status
I know it looks like it just doesn't include armv7 code, but that's actually a red herring. If I set the architecture build setting for both the project and target to Standard (armv6 armv7), I get the same linker error, except it'll say armv6.
The problem is, I can put the new .h and .a files in a new project and call this same method and not get the linker error!
I have a feeling that there's something that isn't getting cleaned and it's trying to compile against the old .a file. I'm using Xcode 4.1 on Snow Leopard. I've tried removing the file from the project, deleting the .a file from the Link Binary With Libraries section under Build Phases for the target, cleaning, adding back the .a file and rebuilding and I still get the error.I'm starting to go crazy here.
OK - I found the culprit! Naturally, it was in Build Settings.
When I switched to the new version, I put the new library in a folder next to the old one, in case I had to switch back at some point. Apparently, when I removed the old version, it did not remove the path to the old version of the .a file from Library Search Paths in the build settings for the target. Deleted the old path, everything is working again.

Resources