Adding Static Library to xcode not working - xcode

I added a static Library and its header file to my OSX project and added them to Link Binary With Libraries under Build Phases.
Xcode gives me the following warning
ignoring file /Users/sd1212/Desktop/OpenGLPlugin/libClientLib.a, file was built for archive which is not the architecture being linked (x86_64)
and wont let me call any of the library methods. I thought I had an architecture problem, so I looked online... Maybe the instructions weren't clear or something, but I think that I already have the x86_64 architecture added, and I changed "Build Active Architecture only" to "No."
Here is a screen shot of the project's architecture settings
Please help! Thanks in advance

Look at the project that builds the static library, as well as the project that links to it, and make sure they both build the right architecture. Consider not only the Valid Architectures line, which you highlighted in your screen shot, but also the Architectures setting. The ones that get built are the ones in both lines.

Related

Why does MoarVM complain about "built for archive which is not the architecture being linked" on Mac OS X?

I'm trying to build Moar from the latest on GitHub and the download on MoarVM.org. I keep getting an error about third-party libraries:
ld: warning: ld: warning: ld: warning: ignoring file 3rdparty/libatomic_ops/src/libatomic_ops.a, file was built for archive which is not the architecture being linked (x86_64): 3rdparty/libatomic_ops/src/libatomic_ops.aignoring file 3rdparty/tinymt/libtinymt.a, file was built for archive which is not the architecture being linked (x86_64): 3rdparty/tinymt/libtinymt.aignoring file 3rdparty/sha1/libsha1.a, file was built for archive which is not the architecture being linked (x86_64): 3rdparty/sha1/libsha1.a
This is similar to OSX : File was built for archive which is not the architecture being linked (i386) (and many other questions with insufficient answers). I know that something is building these for the wrong architecture already, so please skip providing that answer.
I've cleaned the directories, deleted everything and started over, told Configure.pl that I'm running on Darwin, and the various other things a user should know to do. I downloaded the tarball from MoarVM.org, which should be the 2105.12 tag in the repo. I run into the same issue with rakudobrew.
Let me know what you'd like to know about my system; it's a basic Mac OS X setup.
I've also filed this as MoarVM issue 334, but it looks like the issue queue doesn't get a lot of love.
From my comment in the MoarVM issue.
I think Sinan and I have figured this out (mostly Sinan though).
When I run configure, it recognizes darwin and selects clang as the compiler. AR is set to merely ar, but that first finds the gnu version in my path instead of the one that goes with clang. When we change the search path around to the first ar is Apple's, everything works.
However, trying Configure.pl --toolchain gnu still chose clang instead of gcc. I don't particularly care which one it uses (at least right now) as long as the other tools come from the right set. I know that I can individually set the paths with args to Configure.pl, but I wouldn't expect to have to do that. I bet most people don't even know what ar is or why they'd set one over the other.
I don't have any advice on this. My problem has a solution, but the Configure could be smarter about this. You can close this issue (maybe opening a fresh one for more smartness).

Linking static library from Xcode into Lazarus app fails on architecture mismatch

Much research here and in-depth exploration via Google links, to no avail.
I've made a simple, one function, static C library with OSX Xcode (5) which I'm trying to link into a Lazarus app, basically to port the Xcode function from Xcode to Lazarus.
Xcode builds the static library alright, and I have what seems to be the proper linkage code in the Lazarus app, as follows:
type
byteptr = ^byte;
const
libname = 'libLORaudio.a';
function LORaudioPlay (fd : longint; audio : byteptr): Integer;
cdecl; external libname;
r := LORaudioPlay(e, z);
All of that compiles just fine, but the build fails with the following messages:
Id: symbol(s) not found for architecture i386
Id: Warning: ignoring file libLORaudio.a, file was built for archive which is not the architecture being linked (i386): libLORaudio.a
(and it goes on to say the function is undefined, of course, since it ignored the library that supplies it.)
My problem could be solved in either of two ways, neither of which have I found sufficient information on, online nor within Xcode or Lazarus.
One solution would be to get Xcode to produce the static library with the architecture expected by Lazarus. I have tried the various options for setting the build architectures in Xcode mentioned in other answers here to similar questions, but it seems I haven't done them correctly because none of them worked for me.
The other solution would be to get Lazarus to accept the architecture produced by Xcode. The Laz.y documentation is not helpful in this regard.
Any suggestions I could try? Thanks so very much for your consideration.
So eventually, I scrounged around with Finder and found where (see below) I had built both the x86_64 and the i386 object files in separate attempts to solve the problem. This was done by changing the build settings for Architectures to 'i386'. Subsequent re-builds for 'x86_64' didn't remove the i386 object info from earlier.
Then I copied the i386 object file into the folder containing the Lazarus project (it was necessary to make the copy with the alt-option dragging method, as copy then paste didn't work).
There, I ran ar on it in Terminal, as: 'ar -r -s libname.a name.o' to build the static lib from the object.
Lazarus now handles the library as desired. (This of course, revealed some other buggy situations to be dealt with, but hey, progress happens.)
Xcode had put both versions of the object in a folder. Find these products from Xcode by right-clicking on the product mentioned in the project navigator and choose 'show in finder'. You can do this for whichever architecture you currently have; both lead to the same build folders. From there work your way back up thru the containing folders until you spot Build. Open that and work your way forward among the contained folders until you get to Objects-normal. In there you'll find folders for i386 and x86_64. Each of those folders contains the corresponding object file as name.o among other product related files.

Xcode 4 and Allegro 5.1 - Linker can't find Framework

I know there are several other questions here regarding the Linker and Xcode 4, but they don't really relate to my problem.
I've built Allegro 5.1 and it took me a while because of FreeType, but eventually it worked. Now I've written a little Space Invader game using Allegro. But somehow the linker can't find the framework.
What I've done so far:
The Frameworks are located at /Library/Frameworks/ and they have the same structure like all the other frameworks in that place
I've added the frameworks to the "Link Binary With Libraries" tab of my target
I've added them in a "Copy Files" tab on my target with Destination "Frameworks"
I've added the correct path settings in the Build Settings, so the header files can be found
I've done all the right steps, but still I get:
ld: framework not found Allegro-5.1
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I already had a working framework, but it was installed as shared libs and not in "framwork mode". But adding the framework components to the project was kinda hard because they were stored in /usr/local/lib, which can't be selected with the file dialog...
So... I have no idea what else there should be to do. When I had the shared libs it worked, but now with the same setting but different location it doesn't anymore. Tell me if you need more information, I'll provide it!
So, in case someone lands here, with the help of elias in the Allegro IRC I've found the "error":
In my targets Build Settings I had to specify the Framework Search Paths as /Library/Frameworks.
This doesn't really make sense to me, since this is the default directory for the Frameworks on Mac OS X, but whatever...

Linking OpenCV static libraries in Xcode

(I am new at pretty much everything that I will discuss here... apologies if the question is very basic) - I used Xcode to write some C++ code using OpenCV (dynamic libraries). The algorithm runs smoothly and I created an executable file that also works. However, it only works in my computer.
I understand that I need to use static libraries instead of dynamic libraries. I have done some research and found how to do this here: http://www.shiffman.net/2011/01/23/how-to-build-opencv-static-libraries-mac-os-x/ and here: http://www.randomsequence.com/articles/opencv-snow-leopard/.
I have followed the steps and, although I had to make a couple of changes, I was able to build ".a" files such as "libopencv_highgui.a".
My code, however, doesn't work anymore when I replace the libraries. I get 200+ errors. This is one of them:
Undefined symbols for architecture x86_64:
"_gzputs", referenced from:
__ZL7icvPutsP13CvFileStoragePKc in libopencv_core.a(persistence.o)
I have searched for this question here but this is the closest I could find: Linking OpenCV libraries in Xcode (not exactly the same question).
Thanks everyone!
You need .a files from $OPENCV_BUILD_PATH/3rdparty/lib/.
The _gzputs from your question belongs to libzlib.a
To link with OpenCV static libraries you also need to add all OpenCV's dependencies to you application. The most of these dependencies comes from the opencv_highui module and the list of dependencies is dependent from your build configuration so I can't tell you the full list. But you can find it yourself: open the CMakeCache.txt from your OpenCV build directory with any text editor and search for opencv_highgui_LIB_DEPENDS line. You need all items from that line except the word general.

Framework errors: ".objc_class_name_XXX", referenced from

I have taken over a Cocoa project that includes some frameworks, and I can get no help from the previous developer. When building one of the frameworks, I get 8 errors like this:
".objc_class_name_XXX", referenced from
I have tried googling the problem, but I cant get my head around it. Any ideas?
I also get some warnings saying "missing required architecture ppc in file" for a linked framework, could this hint at the problem?
Any help will be greatly appreciated. Thank you
Søren
The missing .objc_class_name_XXX means you’re sending class messages to XXX, but not linking to the binary where XXX’s main implementation is. Presumably this is the framework that doesn’t have a PPC part.
There are three possible ways to fix this:
Get a version of the framework with a PowerPC part.
Stop building for PowerPC (the ARCHS build setting).
Stop using those classes in the PowerPC build of the project (either look them up dynamically using NSClassFromString or #ifdef them out).

Resources