dll or lib or what

Member
Posts: 241
Joined: 2008.07
Post: #1
I'm using OpenAL to play OGG files. We've got the entire vorbis code base included in our project, which is obviously unnecessary to re-compile every time we build the project. It's also throwing a ton of warnings. If I was programming in Windows, I'd know how to handle this, I'd build a lib lib and link to it. I would put the source in the build search path and could #include <>, instead of " ".

How would I go about accomplishing this task in Xcode? Thanks!
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #2
A few things:
  • Unless the vorbis source itself changes between compilations, it should only need to be compiled once up-front. Subsequent compiles should be able to observe that the source files haven't changed, and simply relink the previously produced object files. Clean builds will of course recompile them, but if they're recompiling every time, something is very wrong with your build system.
  • In the normal case, you probably don't want to include third-party library source directly in your project. My usual approach is to build a static library from the provided autoconf project, then link to that during compilation (copying headers over as appropriate). (You don't want to install it, though; make sure your project is self-contained so that it can build on any computer without additional setup)
  • autoconf projects aren't set up to very easily build multi-architecture binaries. Here's how I do it:
Code:
CC="gcc -arch ppc -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk" ./configure
make
cp .libs/libfoo.a ~/libfoo.ppc.a
make clean
CC="gcc -arch i386 -mmacosx-version-min=10.4 -isysroot /Developer/SDKs/MacOSX10.4u.sdk" ./configure
make
cp .libs/libfoo.a ~/libfoo.i386.a
lipo -create -output ~/libfoo.a ~/libfoo.ppc.a ~/libfoo.i386.a
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #3
I'm not worried about multi-architecture setup. I was saying IF I was using Windows, I'd know how to do it but I'm relatively noob to Mac Programming. If there's no third party library source, how can I generate that? I hope I'm not misunderstanding.
Quote this message in a reply
Member
Posts: 86
Joined: 2008.04
Post: #4
Shared libraries on the mac can be dynamic [ .so ] or static [ .a ]. (This is unix)

.so = shared object
.a = archive

Windows basically copied the same approach years ago, but renamed the .so to .dll and .a to .lib.

So you can use whatever approach you want, and compile OpenAL as either dynamic or static library to include.
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #5
Static is what I need. I guess that's in the project properties?
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #6
I don't mean to bump but this is to help anyone else who is trying to accomplish the same thing.

You should be able to find plenty of resources out there as to how to create an static library, which is basically an archive of .o files with a table of contents for linking. Once you've got your .a file, you can't just drag it into Xcode and expect that to work. You still need to make the implementation files visible and include them.

I used "Advanced Mac OS X Programming" by Mark Dalrymple and Aaron Hillegass to assist me in creating the .a file. The book assists you very well with the creation of the archive using Terminal and some basic UNIX commands. It then says, "Using static libraries in Xcode is really easy. Just drag the [archive] file into your project. Xcode will automatically link it." Yeah, that's true, it does, but it's not that easy.

Either you have to put all the .h files you need into Xcode or do what I did which was add them all to a central location on your hard drive and then add them to the search paths. This is ideal because for something like vorbis, which has 24 .h files and will never change, you want that to be accessible to another program you may want it for in the future. To add a folder to the Xcode search path:

RichardS from Gamedev.net Wrote:Select 'Edit active target 'x' from the Project menu.
Choose the Build tab.
Choose "All Configurations" from the Configuration popup button.
Choose "Search Paths" from the Collection popup button.
Double click on the entry marked 'Header Search Paths'
Add the path to the top level include folder. You should not select 'recursive'.

These instructions assume you are using Xcode 2.2 or 2.2.1. It is different for older versions.

Original Quote

Don't forget to use <> instead of "" in your #import or #include.

Cheers!
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #7
Okay, life was happy and good until I tried to build it for the iPhone and then all my hopes and dreams shattered into a million pieces. Would anyone know why the archive will link on the iPhone Simulator but not on the iPhone device itself?
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #8
The device uses a different CPU architecture than the simulator, which I could see causing you a number of possible problems. What's the specific error you're getting?
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #9
Well, I know it's not a problem with the source code because we previously had all the vorbis source and headers included in the project. It's something like 50 files and some of the variables in those files aren't used, so we get about 40 warnings and it's just an ugly mess. It works though in the phone and the simulator.

As this thread illustrates, I tried to convert all the source to a static library or .a. Then I put all the header files in my user search paths for Xcode so that it would link. I added a line to the project so it knew where to search for those files and it worked fine in the Simulator.

It has something to do with not wanting to link for the phone. The specific errors are

_ov_info, _ov_open, _ov_pcm_total, _ov_read calls in our vorbis wrapper, which unmangled are ov_info, ov_open, ov_pcm_total, ov_read. I looked at these calls in the source and they are all extern which had me scratching my head. So, just to see if that was the problem, I commented out those specific calls. Then I got a huge list of other linker errors. I'm pretty sure it's not linking the .a or not bundling or something that is beyond my understanding. Sad
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #10
What architectures are you building your static library for? If you're trying to link, for example, an i386 static lib with an armv6 object file, it's not going to work. You'll need to build the static lib for all of the architectures you want to link it into.
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #11
Oh!!

That makes sense.

Okay, so I guess I just have to tell GCC to compile it for ARM6, which I have no clue how to do. Also, how would I set the project/target so that it links to the .a that's built for i386 when running the Simulator and to the .a that's built for ARM6 when running on the phone?
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #12
The -arch flag specifies which architecture to build for. See the gcc man page for details.

If you're compiling a separate libraries for each architecture, one way to do what you're trying to do would be to put the target architecture in the file name (ex. libvorbis.i386.a, libvorbis.armv6.a), and specify the file in OTHER_LDFLAGS as libvorbis.${CURRENT_ARCH}.a.
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #13
The only options for the -arch flag are i386, ppc, and ppc64. Looking now for a way to compile it for armv6 ( I tried armv6 as the flag parameter, no luck ). It's got to be possible.
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #14
Thanks again Took. I was able to get it to work but I don't think I could have done it without your help. I couldn't find a way to do it from the command line so I just created a BSD Static Library project, added the files, set the build mode to iPhone SDK 2.2/release - build, and voila!
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #15
Very nice! I could have been remembering the armv6 architecture flag wrong; if you're curious, you could look at Xcode's build log to see how it's actually invoking gcc. In any case, glad it's working for you!
Quote this message in a reply
Post Reply