我正在尝试使用由 Qt 框架中的 qmake 工具生成的通用 Makefile 编译静态库。当我在没有 Objective-C 代码的情况下编译它时,一切正常:
//#import <Foundation/NSString.h>
int get_int()
{
return 1;
}
#if 0
NSString* get_string()
{
return [NSString stringWithString:@"MyString!"];
}
#endif
如果我启用 Objective-C 代码,我会收到以下错误:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -c -pipe -fmessage-length=0 -fexceptions -miphoneos-version-min=5.1 -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -fobjc-abi-version=2 -fobjc-legacy-dispatch -g -arch x86_64 -Xarch_x86_64 -Wall -W -DDARWIN_NO_CARBON -DQT_NO_AUDIO_BACKEND -I/usr/local/Qt4.8/mkspecs/qpa/macx-iphonesimulator-g++ -I. -I/usr/include -I/home/luca/Android/android-ndk-r7c/platforms/android-5/arch-arm/usr/include -I. main.mm -o main.o
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:149,
from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:5,
from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:8,
from main.mm:4:
/usr/include/objc/objc.h:119: error: expected initializer before ‘__AVAILABILITY_INTERNAL__IPHONE_5_0’
/usr/include/objc/objc.h:121: error: expected initializer before ‘__AVAILABILITY_INTERNAL__IPHONE_5_0’
/usr/include/objc/objc.h:123: error: expected initializer before ‘__AVAILABILITY_INTERNAL__IPHONE_5_0’
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:149,
from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:5,
from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:8,
from main.mm:4:
/usr/include/objc/objc.h:119: error: expected initializer before ‘__AVAILABILITY_INTERNAL__IPHONE_5_0’
/usr/include/objc/objc.h:121: error: expected initializer before ‘__AVAILABILITY_INTERNAL__IPHONE_5_0’
/usr/include/objc/objc.h:123: error: expected initializer before ‘__AVAILABILITY_INTERNAL__IPHONE_5_0’
lipo: can't open input file: /var/folders/vg/w8jfpsk12679f8w964bnjzs00000gn/T//ccasR3kI.out (No such file or directory)
make: *** [main.o] Error 1
这是我使用的 Makefile:
#############################################################################
# Makefile for building: libAndroidTest.a
# Generated by qmake (2.01a) (Qt 4.8.1) on: Mon Apr 30 19:26:19 2012
# Project: AndroidTest.pro
# Template: lib
# Command: /usr/bin/qmake -spec /usr/local/Qt4.8/mkspecs/qpa/macx-iphonesimulator-g++ -o Makefile AndroidTest.pro
#############################################################################
####### Compiler, tools and options
CC = /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc
CXX = /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++
DEFINES = -DDARWIN_NO_CARBON -DQT_NO_AUDIO_BACKEND
CFLAGS = -pipe -fmessage-length=0 -fexceptions -miphoneos-version-min=5.1 -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -fPIC -Wall -W $(DEFINES)
CXXFLAGS = -pipe -fvisibility=hidden -fvisibility-inlines-hidden -pipe -fmessage-length=0 -fexceptions -miphoneos-version-min=5.1 -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -fPIC -Wall -W $(DEFINES)
INCPATH = -I/usr/local/Qt4.8/mkspecs/qpa/macx-iphonesimulator-g++ -I. -I/usr/include -I/home/luca/Android/android-ndk-r7c/platforms/android-5/arch-arm/usr/include -I.
AR = /usr/bin/ar cq
RANLIB = /usr/bin/ranlib -s
QMAKE = /usr/bin/qmake
TAR = tar -cf
COMPRESS = gzip -9f
COPY = cp -f
SED = sed
COPY_FILE = cp -f
COPY_DIR = cp -f -R
STRIP =
INSTALL_FILE = $(COPY_FILE)
INSTALL_DIR = $(COPY_DIR)
INSTALL_PROGRAM = $(COPY_FILE)
DEL_FILE = rm -f
SYMLINK = ln -f -s
DEL_DIR = rmdir
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
export IPHONEOS_DEPLOYMENT_TARGET = 5.1
####### Output directory
OBJECTS_DIR = ./
####### Files
SOURCES =
OBJECTS = main.o
DIST = /usr/local/Qt4.8/mkspecs/common/unix.conf \
/usr/local/Qt4.8/mkspecs/common/mac.conf \
/usr/local/Qt4.8/mkspecs/common/gcc-base.conf \
/usr/local/Qt4.8/mkspecs/common/gcc-base-macx.conf \
/usr/local/Qt4.8/mkspecs/common/g++-base.conf \
/usr/local/Qt4.8/mkspecs/common/g++-macx.conf \
/usr/local/Qt4.8/mkspecs/qpa/common/g++-base-macx-iphone.conf \
/usr/local/Qt4.8/mkspecs/qconfig.pri \
/usr/local/Qt4.8/mkspecs/modules/qt_webkit_version.pri \
/usr/local/Qt4.8/mkspecs/features/qt_functions.prf \
/usr/local/Qt4.8/mkspecs/features/qt_config.prf \
/usr/local/Qt4.8/mkspecs/features/exclusive_builds.prf \
/usr/local/Qt4.8/mkspecs/features/default_pre.prf \
/usr/local/Qt4.8/mkspecs/features/mac/default_pre.prf \
/usr/local/Qt4.8/mkspecs/features/mac/dwarf2.prf \
/usr/local/Qt4.8/mkspecs/features/debug.prf \
/usr/local/Qt4.8/mkspecs/features/default_post.prf \
/usr/local/Qt4.8/mkspecs/features/mac/default_post.prf \
/usr/local/Qt4.8/mkspecs/features/mac/x86_64.prf \
/usr/local/Qt4.8/mkspecs/features/mac/objective_c.prf \
/usr/local/Qt4.8/mkspecs/features/static.prf \
/usr/local/Qt4.8/mkspecs/features/staticlib.prf \
/usr/local/Qt4.8/mkspecs/features/warn_on.prf \
/usr/local/Qt4.8/mkspecs/features/qt.prf \
/usr/local/Qt4.8/mkspecs/features/unix/thread.prf \
/usr/local/Qt4.8/mkspecs/features/moc.prf \
/usr/local/Qt4.8/mkspecs/features/mac/rez.prf \
/usr/local/Qt4.8/mkspecs/features/mac/sdk.prf \
/usr/local/Qt4.8/mkspecs/features/resources.prf \
/usr/local/Qt4.8/mkspecs/features/uic.prf \
/usr/local/Qt4.8/mkspecs/features/yacc.prf \
/usr/local/Qt4.8/mkspecs/features/lex.prf \
/usr/local/Qt4.8/mkspecs/features/include_source_dir.prf \
AndroidTest.pro
QMAKE_TARGET = AndroidTest
DESTDIR =
TARGET = libAndroidTest.a
####### Custom Compiler Variables
QMAKE_COMP_QMAKE_OBJECTIVE_CFLAGS = -pipe \
-fmessage-length=0 \
-fexceptions \
-miphoneos-version-min=5.1 \
-arch \
i386 \
-isysroot \
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk \
-fobjc-abi-version=2 \
-fobjc-legacy-dispatch \
-g \
-arch \
x86_64 \
-Xarch_x86_64 \
-Wall \
-W
first: all
####### Implicit rules
.SUFFIXES: .o .c .cpp .cc .cxx .C
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.cc.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.C.o:
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<"
.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<"
####### Build rules
all: Makefile $(TARGET)
staticlib: $(TARGET)
$(TARGET): $(OBJECTS) $(OBJCOMP)
-$(DEL_FILE) $(TARGET)
$(AR) $(TARGET) $(OBJECTS)
$(RANLIB) $(TARGET)
Makefile: AndroidTest.pro /usr/local/Qt4.8/mkspecs/qpa/macx-iphonesimulator-g++/qmake.conf /usr/local/Qt4.8/mkspecs/common/unix.conf \
/usr/local/Qt4.8/mkspecs/common/mac.conf \
/usr/local/Qt4.8/mkspecs/common/gcc-base.conf \
/usr/local/Qt4.8/mkspecs/common/gcc-base-macx.conf \
/usr/local/Qt4.8/mkspecs/common/g++-base.conf \
/usr/local/Qt4.8/mkspecs/common/g++-macx.conf \
/usr/local/Qt4.8/mkspecs/qpa/common/g++-base-macx-iphone.conf \
/usr/local/Qt4.8/mkspecs/qconfig.pri \
/usr/local/Qt4.8/mkspecs/modules/qt_webkit_version.pri \
/usr/local/Qt4.8/mkspecs/features/qt_functions.prf \
/usr/local/Qt4.8/mkspecs/features/qt_config.prf \
/usr/local/Qt4.8/mkspecs/features/exclusive_builds.prf \
/usr/local/Qt4.8/mkspecs/features/default_pre.prf \
/usr/local/Qt4.8/mkspecs/features/mac/default_pre.prf \
/usr/local/Qt4.8/mkspecs/features/mac/dwarf2.prf \
/usr/local/Qt4.8/mkspecs/features/debug.prf \
/usr/local/Qt4.8/mkspecs/features/default_post.prf \
/usr/local/Qt4.8/mkspecs/features/mac/default_post.prf \
/usr/local/Qt4.8/mkspecs/features/mac/x86_64.prf \
/usr/local/Qt4.8/mkspecs/features/mac/objective_c.prf \
/usr/local/Qt4.8/mkspecs/features/static.prf \
/usr/local/Qt4.8/mkspecs/features/staticlib.prf \
/usr/local/Qt4.8/mkspecs/features/warn_on.prf \
/usr/local/Qt4.8/mkspecs/features/qt.prf \
/usr/local/Qt4.8/mkspecs/features/unix/thread.prf \
/usr/local/Qt4.8/mkspecs/features/moc.prf \
/usr/local/Qt4.8/mkspecs/features/mac/rez.prf \
/usr/local/Qt4.8/mkspecs/features/mac/sdk.prf \
/usr/local/Qt4.8/mkspecs/features/resources.prf \
/usr/local/Qt4.8/mkspecs/features/uic.prf \
/usr/local/Qt4.8/mkspecs/features/yacc.prf \
/usr/local/Qt4.8/mkspecs/features/lex.prf \
/usr/local/Qt4.8/mkspecs/features/include_source_dir.prf
$(QMAKE) -spec /usr/local/Qt4.8/mkspecs/qpa/macx-iphonesimulator-g++ -o Makefile AndroidTest.pro
/usr/local/Qt4.8/mkspecs/common/unix.conf:
/usr/local/Qt4.8/mkspecs/common/mac.conf:
/usr/local/Qt4.8/mkspecs/common/gcc-base.conf:
/usr/local/Qt4.8/mkspecs/common/gcc-base-macx.conf:
/usr/local/Qt4.8/mkspecs/common/g++-base.conf:
/usr/local/Qt4.8/mkspecs/common/g++-macx.conf:
/usr/local/Qt4.8/mkspecs/qpa/common/g++-base-macx-iphone.conf:
/usr/local/Qt4.8/mkspecs/qconfig.pri:
/usr/local/Qt4.8/mkspecs/modules/qt_webkit_version.pri:
/usr/local/Qt4.8/mkspecs/features/qt_functions.prf:
/usr/local/Qt4.8/mkspecs/features/qt_config.prf:
/usr/local/Qt4.8/mkspecs/features/exclusive_builds.prf:
/usr/local/Qt4.8/mkspecs/features/default_pre.prf:
/usr/local/Qt4.8/mkspecs/features/mac/default_pre.prf:
/usr/local/Qt4.8/mkspecs/features/mac/dwarf2.prf:
/usr/local/Qt4.8/mkspecs/features/debug.prf:
/usr/local/Qt4.8/mkspecs/features/default_post.prf:
/usr/local/Qt4.8/mkspecs/features/mac/default_post.prf:
/usr/local/Qt4.8/mkspecs/features/mac/x86_64.prf:
/usr/local/Qt4.8/mkspecs/features/mac/objective_c.prf:
/usr/local/Qt4.8/mkspecs/features/static.prf:
/usr/local/Qt4.8/mkspecs/features/staticlib.prf:
/usr/local/Qt4.8/mkspecs/features/warn_on.prf:
/usr/local/Qt4.8/mkspecs/features/qt.prf:
/usr/local/Qt4.8/mkspecs/features/unix/thread.prf:
/usr/local/Qt4.8/mkspecs/features/moc.prf:
/usr/local/Qt4.8/mkspecs/features/mac/rez.prf:
/usr/local/Qt4.8/mkspecs/features/mac/sdk.prf:
/usr/local/Qt4.8/mkspecs/features/resources.prf:
/usr/local/Qt4.8/mkspecs/features/uic.prf:
/usr/local/Qt4.8/mkspecs/features/yacc.prf:
/usr/local/Qt4.8/mkspecs/features/lex.prf:
/usr/local/Qt4.8/mkspecs/features/include_source_dir.prf:
qmake: FORCE
@$(QMAKE) -spec /usr/local/Qt4.8/mkspecs/qpa/macx-iphonesimulator-g++ -o Makefile AndroidTest.pro
dist:
@$(CHK_DIR_EXISTS) .tmp/AndroidTest1.0.0 || $(MKDIR) .tmp/AndroidTest1.0.0
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/AndroidTest1.0.0/ && $(COPY_FILE) --parents main.mm .tmp/AndroidTest1.0.0/ && $(COPY_FILE) --parents main.mm .tmp/AndroidTest1.0.0/ && (cd `dirname .tmp/AndroidTest1.0.0` && $(TAR) AndroidTest1.0.0.tar AndroidTest1.0.0 && $(COMPRESS) AndroidTest1.0.0.tar) && $(MOVE) `dirname .tmp/AndroidTest1.0.0`/AndroidTest1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/AndroidTest1.0.0
clean:compiler_clean
-$(DEL_FILE) $(OBJECTS)
-$(DEL_FILE) *~ core *.core
####### Sub-libraries
distclean: clean
-$(DEL_FILE) $(TARGET)
-$(DEL_FILE) Makefile
check: first
mocclean: compiler_moc_header_clean compiler_moc_source_clean
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
compiler_objective_c_make_all: main.o
compiler_objective_c_clean:
-$(DEL_FILE) main.o
main.o: main.mm
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -c $(QMAKE_COMP_QMAKE_OBJECTIVE_CFLAGS) $(DEFINES) $(INCPATH) main.mm -o main.o
compiler_moc_header_make_all:
compiler_moc_header_clean:
compiler_rcc_make_all:
compiler_rcc_clean:
compiler_image_collection_make_all: qmake_image_collection.cpp
compiler_image_collection_clean:
-$(DEL_FILE) qmake_image_collection.cpp
compiler_moc_source_make_all:
compiler_moc_source_clean:
compiler_rez_source_make_all:
compiler_rez_source_clean:
compiler_uic_make_all:
compiler_uic_clean:
compiler_yacc_decl_make_all:
compiler_yacc_decl_clean:
compiler_yacc_impl_make_all:
compiler_yacc_impl_clean:
compiler_lex_make_all:
compiler_lex_clean:
compiler_clean: compiler_objective_c_clean
####### Compile
####### Install
install: FORCE
uninstall: FORCE
FORCE:
似乎缺少一些 CFLAG 或 DEFINE。知道是什么导致了这个错误吗?