Welcome to Soft32 Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Cross-compiling i386 or fat binaries from the command line?

 
   Soft32 Home -> Mac -> Programmer Help RSS
Next:  Sockets in Cocoa  
Author Message
William McBrine

External


Since: Jun 18, 2005
Posts: 3



(Msg. 1) Posted: Sat Jun 18, 2005 6:00 pm
Post subject: Cross-compiling i386 or fat binaries from the command line?
Archived from groups: comp>sys>mac>programmer>help (more info?)

They say all you need to do to build fat binaries in Xcode is check a
box. However, I have some Unix programs that I build with "make" on the
command line, and I'm having a lot more trouble. The programs build OK
for native PPC. And the object code files build just fine with "-arch
i386" (or even "-arch ppc -arch i386"); but I can't for the life of me
get them to link. I have Xcode 2.1 and the Universal SDK installed. I've
tried using -syslibroot with ld, defining the SDK environment variables,
directly specifying the right libSystem, etc. The furthest I've gotten
was to resolve all symbols except for dyld_stub_binding_helper. I even
tried a "hello world" program, with the same results.

Has anyone got this to work?

Alternatively... since these are Unix apps, could I just build them
under OpenDarwin, and expect them to work under Mac OS X for Intel?

--
William McBrine <wmcbrine RemoveThis @gmail.com>
Back to top
Login to vote
Tom Harrington

External


Since: Aug 19, 2003
Posts: 1921



(Msg. 2) Posted: Sun Jun 19, 2005 5:05 pm
Post subject: Re: Cross-compiling i386 or fat binaries from the command line? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <11b99t22pk6lo36 DeleteThis @corp.supernews.com>,
William McBrine <wmcbrine DeleteThis @covad.net> wrote:

> They say all you need to do to build fat binaries in Xcode is check a
> box. However, I have some Unix programs that I build with "make" on the
> command line, and I'm having a lot more trouble. The programs build OK
> for native PPC. And the object code files build just fine with "-arch
> i386" (or even "-arch ppc -arch i386"); but I can't for the life of me
> get them to link. I have Xcode 2.1 and the Universal SDK installed. I've
> tried using -syslibroot with ld, defining the SDK environment variables,
> directly specifying the right libSystem, etc. The furthest I've gotten
> was to resolve all symbols except for dyld_stub_binding_helper. I even
> tried a "hello world" program, with the same results.
>
> Has anyone got this to work?
>
> Alternatively... since these are Unix apps, could I just build them
> under OpenDarwin, and expect them to work under Mac OS X for Intel?

I haven't tried doing it from the command line. But from looking at
XCode 2.1's build log for a universal binary, the following looks to be
necessary:

1. Set this env var (I don't know if it's necessary, but XCode does it):
setenv MACOSX_DEPLOYMENT_TARGET 10.4

2. Use this gcc arg to specify universal:
-isysroot /Developer/SDKs/MacOSX10.4u.sdk

For what it's worth, the scheme XCode uses is to compile and link the
binary twice, once with -arch ppc and once with -arch i386. The
universal binary is then built from the two binaries using
/usr/bin/lipo. I don't know if specifying -arch twice would get the
desired result.

Depending on what you're doing, this might or might not be the right
approach. Universal binaries are only needed if you want to have one
precompiled binary that works on both architectures. If this was an
open-source project of some kind where the user could be expected to be
compiling their own copy, a better approach would probably be to have
the "configure" script recognize the architecture and proceed as
appropriate.

--
Tom "Tom" Harrington
Macaroni, Automated System Maintenance for Mac OS X.
Version 2.0: Delocalize, Repair Permissions, lots more.
See http://www.atomicbird.com/
Back to top
Login to vote
William McBrine

External


Since: Jun 18, 2005
Posts: 3



(Msg. 3) Posted: Wed Jun 22, 2005 2:52 pm
Post subject: Re: Cross-compiling i386 or fat binaries from the command line? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Sherm Pendley <sherm.DeleteThis@dot-app.org> wrote:

> export LDFLAGS="-Wl,-syslibroot,$SDK"

Thanks, that was the key. I'd tried variations of that, but now I've
actually got it working. The flags for the include directories aren't
even needed, at least with the code I've tried, though I guess they're
sound practice.

> GCC will complain if you try to use -c along with multiple -arches.

Nope, that also works fine for me.

Funny thing I've noticed, when I do it separately: the i386 code builds
faster than the ppc. Maybe not surprising, given gcc's history; but
funny since it's cross-compiling.

To answer my own question about Darwin: Apple sez "All software built
for Darwin should be able to run unmodified on Mac OS X."
( http://developer.apple.com/darwin/projects/darwin/faq.html )

So I grabbed Darwin 8.0.1, but I couldn't get it installed in VMware.
I've read that it doesn't work in VirtualPC, either, but I'll try it
anyway.
Back to top
Login to vote
Eric Albert

External


Since: Jan 09, 2004
Posts: 683



(Msg. 4) Posted: Thu Jul 07, 2005 5:31 am
Post subject: Re: Cross-compiling i386 or fat binaries from the command line? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article <11bjgc5m9bts459 DeleteThis @corp.supernews.com>,
William McBrine <wmcbrine DeleteThis @covad.net> wrote:

> Sherm Pendley <sherm DeleteThis @dot-app.org> wrote:

> > GCC will complain if you try to use -c along with multiple -arches.
>
> Nope, that also works fine for me.

I think Sherm was thinking of -S or -E, which as of gcc 4.0 don't
support multiple -arch arguments. That's because they're inherently
architecture-specific and can't emit universal output files.

> To answer my own question about Darwin: Apple sez "All software built
> for Darwin should be able to run unmodified on Mac OS X."
> ( http://developer.apple.com/darwin/projects/darwin/faq.html )
>
> So I grabbed Darwin 8.0.1, but I couldn't get it installed in VMware.
> I've read that it doesn't work in VirtualPC, either, but I'll try it
> anyway.

I wouldn't count on all software built for Darwin 8.0.1 on x86 running
on Mac OS X on Intel-based Macs. There were a number of changes between
Darwin 8.0.1 and the OS on the Intel-based Macs at WWDC. That said, any
Darwin release corresponding to a Mac OS X release for Intel-based Macs
should be covered by the statement you quoted above.

-Eric

--
Eric Albert ejalbert DeleteThis @cs.stanford.edu
http://outofcheese.org/
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How to run a command line tool? - Hi, A few of the Apple code examples build command line tools rather than proper apps. How do you 'run' these apps? I...

How to get the command line tool directory (written in C) - How to get the path of the command line tool programaticaly ? (after the command line tool was called from the Terminal...

GUI wrapper for command line application - Hi, I'm trying to write a GUI wrapper for a command line application and am following Apple's Moriarity example. Laun...

Command-line arguments in Mac App - I'm porting a Unix program to Mac OS X. I've made a bundle for the app, and I'd like to be able to have the executabl...

accessing command line arguments in AppKit? - I'm sure that this has got to be easy to do, I just can't find it. But I have a cocoa app (GUI/AppKit) that I'd like t...

starting a command line app from code - I want to start a command line program (deamon) from my Cocoa app. It seems there are a lot of ways to do this. I found...
       Soft32 Home -> Mac -> Programmer Help All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum

Categories:
 Windows
 Linux
  Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]