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.
Related
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).
Recently I ran into a CMake problem that can be found in this thread:
Cmake on OSX Yosemite 10.10.3 - GLEW: package 'gl' not found
Eventually it got solved, maybe partly due to my inexperience in XCode and CMake. (I mainly used visual studio to compile projects in the past.)
After the alteration in the linked thread I got warning about my GLEW libs in CMake
(Is this something I should be worried about or is it not important?):
MACOSX_RPATH is not specified for the following targets:
GLEW_MX_shared
GLEW_shared
I simply ignored it and tried to compile my project in XCode with the ALL_BUILD target selected. In the sparky target it said the include files in main could not be found so I added the .h files into the inc folder of my project.
When I compiled again the compiler started complaining again
(I don't know what this error means and how I can fix it.):
ld: library not found for -llib
Googled it for the entire day now and I can't find anything to solve this issue.
It's so frustrating working with XCode as an IDE but I really want to learn more about different platforms and their most popular IDE's so I can make multi platform applications from the start instead of porting it afterwards.
And if it matters I am using OSX Yosemite 10.10.3.
To make my issue easier to understand, I've put a zip of my project on my dropbox.
https://www.dropbox.com/s/xnrh90kuih9ia5a/SPARKY%202.zip?dl=0
Feel free to ask questions if I explained things to briefly and again, thanks to everyone who contributes here. I really learned allot after discovering these forums.
EDIT: Alright I booted up my windows machine, generated a visual studio environment and tried to build it on there. Seems that the same problem also happens here. I looked at the linker attributes/flags and saw a lib.lib file added to the linking process which doesn't look right at all.
When removing the file, the error disappeared and many others arrived! (Which are simply solved by linking the appropriate libs so I wont handle those here.)
I misunderstood the error on my mac and thought it was referring to a random library which I needed to hunt down but actually it's a inconsistency in one of my CMake files.
EDIT2: Now I only have to find out where the lib.lib comes from and how I can ditch the flags from the project so I can generate my environment and build right away!
So moral of the story. Sometimes the solution is right in front of you and still ends up more like looking for a needle in a haystack.
I removed the following from my root CMakeLists.txt file and the random lib.lib library was gone from my generated projects
SET( PROJ_LIBRARIES "lib" )
I thought this added a folder containing libraries but actually what it did was adding another flag for a specific library because this variable was being fed to:
TARGET_LINK_LIBRARIES( ${PROJ_NAME} ${PROJ_LIBRARIES} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} )
I'm working on an OS X application using a third-party framework. This framework is distributed both as shared objects and static objects. For my purposes, I want to use the static objects because I can't rely on the presence of the library on other systems.
However, when I build the application with Xcode, something decides it needs the shared objects, and when I run it, dyld tells me off before I even get to my program:
dyld: Library not loaded: /usr/local/lib/libshared.dylib
Referenced from: /Users/me/Library/Developer/Xcode/snip/Application.app/Contents/MacOS/Application
Reason: image not found
I ran otool -L on the executable, and sure enough, it tried to link against the shared objects (which aren't even installed on my system). However, when I ran it on the thirty-some .a files that I link against, none of them indicated any dependency on them.
Apple's ld -v is just a tad verbose: it displays the library search paths but doesn't produce any other kind of useful output.
How can I find what tried to link against the shared objects?
otool -L does list the libraries against which any object links.
This specific instance was caused by an Xcode bug (known as rdar://2725744 to the ones blessed with Apple bug database access, and not fixed as of Xcode 6.1.1) where if you try to link against a .a static library with Xcode but there's a .dylib (or .so) dynamic library with the same name in the same directory, the linker will pick the dynamic one.
When you instruct Xcode to link against a static library (say /some/path/to/my/libFooBar.a), it adds -L/some/path/to/my -lFooBar to the linker invocation. However, with it, ld first searches for a dynamic library called libFooBar.dylib, and it will fall back to the static library only if it can't find the dynamic one.
If you added the framework is listed in the "Build Phases" of "Link Binary with Libraries" and it has the setting of "Required" that could explain why the launch fails.
Try changing the setting to "Optional". Then if nothing uses the framework, it should launch fine. (If something tries to use the framework, but fails to check for it first, it might crash.)
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.
(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.