views:

962

answers:

1

We are using precompiled headers with GCC for our project and build them like this:

gcc $(CFLAGS) precompiledcommonlib.h

Now I'm building the project on OSX 10.6 and trying to use the nifty feature of building for all architectures at the same time like this:

gcc $(CFLAGS) -c -arch i386 -arch x86_64 commonlib.c

However, it seems this does not work for the precompiled headers:

gcc $(CFLAGS) -arch i386 -arch x86_64 precompiledcommonlib.h
Undefined symbols for architecture i386:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
Undefined symbols for architecture x86_64:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
lipo: can't open input file: /var/folders/z1/z1A0sPkqGDyPrZWo9ysVK++++TI/-Tmp-//cc3W2gwd.out (No such file or directory)

Edit: As Mark pointed out as per XCode the precompiled header has to be built separately for each architecture, so my question is rather if there is any way to have gcc use the right precompiled header when building universal objects.

I do realise that I could build each architecture completely separate like XCode does it but I would much rather take advantage of the possibility to build them at the same time and not have to mess around with different build configurations.

A: 

Your problem is not the architectures. Both are failing

The issue is that you are trying to build a executable without a main function.

As the file name is commonlib.c I suspect you want to build a library if so start the project with a library template in XCode.

Mark
Thanks for taking your time.Try 'gcc foo.h'. What does it output? Do you still think I'm trying to build an executable?A hasty, not to mention plain wrong answer and a patronising attitude is not a particularly charming combination.
rasmusb
I did mix up the command lines sorry. However The error messages and command line are trying to build an executable. - which is why ld is the command line by giving the error I would still set this up in Xcode to get all the flags correct. If you had you would se that Apple precompiles each header separately for each architecture and the command line includes -x objective-c-header -arch x86_64 Apple docs <http://developer.apple.com/Mac/library/documentation/DeveloperTools/gcc-4.0.1/gcc/Precompiled-Headers.html> also suggest the -x parameter. amd details on separate architectures.
Mark