Fix compilation on MacOS X 10.8 ("Mountain Lion")
cover Fix compilation on MacOS X 10.8 ("Mountain Lion")
I had a go at compiling on my Macbook, which runs Apple's most recent cat. I had to fix a couple of issues, which I think are down to new stuff in the system headers:
* the os/object.h header will try to use Objective-C syntax unless explicitly squashed
* some of the headers we use in the cocoa ui frontend use the 'Blocks' Apple extension, so won't build except with clang or the (now rapidly aging) Apple gcc, so to do a build with a modern gcc we need to support specifying the Objective-C compiler separately.
Peter Maydell (2):
configure: Define OS_OBJECT_USE_OBJC=0 for MacOSX builds Support using a different compiler for Objective-C files
configure | 15 +++++++++++++++ rules.mak | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.11.4
PATCH 1/2 configure: Define OS_OBJECT_USE_OBJC=0 for MacOSX builds
MacOSX 10.8 ("Mountain Lion") defaults to trying to use automated reference counting on certain objects. This means that the system header files will use some Objective C syntax constructs even when compiling pure C, which confuses mainline gcc. Suppress this by setting OS_OBJECT_USE_OBJC=0. This avoids a compile error like this:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:5:0,
from /usr/include/os/object.h:74,
from /usr/include/dispatch/dispatch.h:48,
from /System/Library/Frameworks/IOKit.framework/Headers/IOKitLib.h:56,
from block/raw-posix.c:35:/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:409:1: error: stray ‘@’ in program [with a large number of further run-on errors]
--- configure | 3 +++ 1 file changed, 3 insertions(+)
configure +3 -0
@@ -452,6 +452,9 @@ Darwin) audio_possible_drivers="coreaudio sdl fmod" LDFLAGS="-framework CoreFoundation -framework IOKit $LDFLAGS" libs_softmmu="-F/System/Library/Frameworks -framework Cocoa -framework IOKit $libs_softmmu" + # Disable attempts to use ObjectiveC features in os/object.h since they + # won't work when we're compiling with gcc as a C compiler. + QEMU_CFLAGS="-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS" ;; SunOS) solaris="yes"
Signature · 1 line
1.7.11.4
PATCH 2/2 Support using a different compiler for Objective-C files
In reply to Peter MaydellMacOSX 10.8 ("Mountain Lion") requires us to compile our one Objective-C source file with clang even if the rest of QEMU requires a real gcc, because the system headers we use make use of Apple's "Blocks" extension to C/ObjC, and mainline gcc doesn't support that. Since we only need to use a true gcc for the parts of QEMU that use the fixed-register env variable, we can simply use clang to build the ObjC
file: it will link to the gcc-built objects with no problems.
Add the necessary support for an OBJCC variable in the makefile and configure machinery; we default to clang if we have it, otherwise whatever CC is (since gcc might be the Apple gcc which does support Blocks).
--- configure | 12 ++++++++++++ rules.mak | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-)
configure +12 -0
@@ -534,6 +534,13 @@ fi : ${python=${PYTHON-python}} : ${smbd=${SMBD-/usr/sbin/smbd}} +# Default objcc to clang if available, otherwise use CC +if has clang; then + objcc=clang +else + objcc="$cc" +fi + if test "$mingw32" = "yes" ; then EXESUF=".exe" QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS"
@@ -577,6 +584,8 @@ for opt do ;; --host-cc=*) host_cc="$optarg" ;; + --objcc=*) objcc="$optarg" + ;; --make=*) make="$optarg" ;; --install=*) install="$optarg"
@@ -1024,6 +1033,7 @@ echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]" echo " --cc=CC use C compiler CC [$cc]" echo " --host-cc=CC use C compiler CC [$host_cc] for code run at" echo " build time" +echo " --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]" echo " --extra-cflags=CFLAGS append extra C compiler flags QEMU_CFLAGS" echo " --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS" echo " --make=MAKE use specified make [$make]"
@@ -3054,6 +3064,7 @@ fi echo "Source path $source_path" echo "C compiler $cc" echo "Host C compiler $host_cc" +echo "Objective-C compiler $objcc" echo "CFLAGS $CFLAGS" echo "QEMU_CFLAGS $QEMU_CFLAGS" echo "LDFLAGS $LDFLAGS"
@@ -3521,6 +3532,7 @@ echo "PYTHON=$python" >> $config_host_mak echo "CC=$cc" >> $config_host_mak echo "CC_I386=$cc_i386" >> $config_host_mak echo "HOST_CC=$host_cc" >> $config_host_mak +echo "OBJCC=$objcc" >> $config_host_mak echo "AR=$ar" >> $config_host_mak echo "OBJCOPY=$objcopy" >> $config_host_mak echo "LD=$ld" >> $config_host_mak
rules.mak +1 -1
@@ -29,7 +29,7 @@ endif $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," AS $(TARGET_DIR)$@") %.o: %.m - $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@") + $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@") LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(sort $(1)) $(LIBS)," LINK $(TARGET_DIR)$@")
Signature · 1 line
1.7.11.4
Re: [Qemu-devel] [PATCH 2/2] Support using a different compiler for Objective-C files
Am 11.08.2012 23:34, schrieb Peter Maydell:
Quoted 25 lines
MacOSX 10.8 ("Mountain Lion") requires us to compile our one Objective-C source file with clang even if the rest of QEMU requires a real gcc, because the system headers we use make use of Apple's "Blocks" extension to C/ObjC, and mainline gcc doesn't support that. Since we only need to use a true gcc for the parts of QEMU that use the fixed-register env variable, we can simply use clang to build the ObjC
file: it will link to the gcc-built objects with no problems.Add the necessary support for an OBJCC variable in the makefile and configure machinery; we default to clang if we have it, otherwise whatever CC is (since gcc might be the Apple gcc which does support Blocks).
Signed-off-by Peter Maydell <[email protected]>--- configure | 12 ++++++++++++ rules.mak | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-)configure +0
-0
configure fi · line 539
Quoted 6 lines
configure +3
-0@@ -534,6 +534,13 @@ fi : ${python=${PYTHON-python}} : ${smbd=${SMBD-/usr/sbin/smbd}} +# Default objcc to clang if available, otherwise use CC +if has clang; then + objcc=clang
On IRC I had commented that I find defaulting to clang whenever clang is available too aggressive (it may be some /usr/local/bin version that doesn't even have the right host architecture support compiled in). I won't object to this patch but would appreciate a follow-up limiting this to v10.8+ where it's actually needed and keep using gcc elsewhere.
Andreas
Quoted 54 lines
configure +9
-0+else + objcc="$cc" +fi + if test "$mingw32" = "yes" ; then EXESUF=".exe" QEMU_CFLAGS="-DWIN32_LEAN_AND_MEAN -DWINVER=0x501 $QEMU_CFLAGS"@@ -577,6 +584,8 @@ for opt do ;; --host-cc=*) host_cc="$optarg" ;; + --objcc=*) objcc="$optarg" + ;; --make=*) make="$optarg" ;; --install=*) install="$optarg"@@ -1024,6 +1033,7 @@ echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]" echo " --cc=CC use C compiler CC [$cc]" echo " --host-cc=CC use C compiler CC [$host_cc] for code run at" echo " build time" +echo " --objcc=OBJCC use Objective-C compiler OBJCC [$objcc]" echo " --extra-cflags=CFLAGS append extra C compiler flags QEMU_CFLAGS" echo " --extra-ldflags=LDFLAGS append extra linker flags LDFLAGS" echo " --make=MAKE use specified make [$make]"@@ -3054,6 +3064,7 @@ fi echo "Source path $source_path" echo "C compiler $cc" echo "Host C compiler $host_cc" +echo "Objective-C compiler $objcc" echo "CFLAGS $CFLAGS" echo "QEMU_CFLAGS $QEMU_CFLAGS" echo "LDFLAGS $LDFLAGS"@@ -3521,6 +3532,7 @@ echo "PYTHON=$python" >> $config_host_mak echo "CC=$cc" >> $config_host_mak echo "CC_I386=$cc_i386" >> $config_host_mak echo "HOST_CC=$host_cc" >> $config_host_mak +echo "OBJCC=$objcc" >> $config_host_mak echo "AR=$ar" >> $config_host_mak echo "OBJCOPY=$objcopy" >> $config_host_mak echo "LD=$ld" >> $config_host_makrules.mak +1
-1@@ -29,7 +29,7 @@ endif $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," AS $(TARGET_DIR)$@") %.o: %.m - $(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@") + $(call quiet-command,$(OBJCC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," OBJC $(TARGET_DIR)$@") LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $(sort $(1)) $(LIBS)," LINK $(TARGET_DIR)$@")
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Re: [Qemu-devel] [PATCH 2/2] Support using a different compiler for Objective-C files
Quoted 10 lines · Andreas Färber
Am 11.08.2012 23:34, schrieb Peter Maydell:
configure fi · line 539
Quoted 3 lines
configure +3
-0+# Default objcc to clang if available, otherwise use CC +if has clang; then + objcc=clangOn IRC I had commented that I find defaulting to clang whenever clang is available too aggressive (it may be some
/usr/local/binversion that doesn't even have the right host architecture support compiled in). I won't object to this patch but would appreciate a follow-up limiting this to v10.8+ where it's actually needed and keep using gcc elsewhere.
Mmm. It might be better to explicitly test for a compiler with Blocks support (although even then you might end up with clang on pre-10.8; I don't really want to check for "does header Foo need blocks support" because that seems a bit fragile.)
-- PMM
Re: [Qemu-devel] [PATCH 2/2] Support using a different compiler for Objective-C files
Am 15.08.2012 16:55, schrieb Peter Maydell:
Quoted 12 lines · Andreas Färber
Quoted 10 lines
Am 11.08.2012 23:34, schrieb Peter Maydell:
configure fi · line 539
Quoted 3 lines
configure +3
-0+# Default objcc to clang if available, otherwise use CC +if has clang; then + objcc=clangOn IRC I had commented that I find defaulting to clang whenever clang is available too aggressive (it may be some
/usr/local/binversion that doesn't even have the right host architecture support compiled in). I won't object to this patch but would appreciate a follow-up limiting this to v10.8+ where it's actually needed and keep using gcc elsewhere.
Quoted 4 lines
Mmm. It might be better to explicitly test for a compiler with Blocks support (although even then you might end up with clang on pre-10.8; I don't really want to check for "does header Foo need blocks support" because that seems a bit fragile.)
A simple does-clang-compile-a-hello-word-for-host check, falling back to gcc, should catch the worst regressions as well.
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg