我目前正试图建立一个iPhone应用程序,我已经使用iPhone工具链开发。当我完成创建makefile时,当它试图加载我的。o文件时,它给了我这个错误:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
在查看它试图执行的shell代码时,我确定它删除了最后一个引号,因此我对我的makefile进行了快速修复。加载后,它给了我以下错误:
未定义的符号:
"_main", referenced from:
__start in crt1.10.5.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** ["Autotune] Error 1
如果我读对了,它找不到我的main函数,但它在main.mm中有明确的定义。我想保持我的项目闭源,但我愿意展示我的代码的某些,非重要的部分。我不明白为什么不编译;它在Xcode上运行良好。我对Makefile的更改是否以某种方式导致它不加载_main符号?我该如何解决这个问题?我被难住了。
这是我的Makefile:PROJECTNAME="MyAppName"
APPFOLDER=$(PROJECTNAME).app
INSTALLFOLDER=$(PROJECTNAME).app
CC=arm-apple-darwin9-gcc
LD=$(CC)
LDFLAGS = -arch arm -lobjc
LDFLAGS += -framework CoreFoundation
LDFLAGS += -framework Foundation
LDFLAGS += -framework UIKit
LDFLAGS += -framework QuartzCore
LDFLAGS += -framework CoreGraphics
LDFLAGS += -framework CoreAudio
LDFLAGS += -framework AudioToolbox
LDFLAGS += -framework AVFoundation
LDFLAGS += -L"/usr/lib"
LDFLAGS += -F"/System/Library/Frameworks"
LDFLAGS += -F"/System/Library/PrivateFrameworks"
LDFLAGS += -bind_at_load
LDFLAGS += -multiply_defined suppress
CFLAGS = -I"/var/include"
CFLAGS += -I"/usr/include"
CFLAGS += -I"/var/include/c++/4.0.0"
CFLAGS += -I"/var/include/c++/4.0.0/arm-apple-darwin9"
CFLAGS += -I"./Classes"
CFLAGS += -F"/System/Library/Frameworks"
CFLAGS += -F"/System/Library/PrivateFrameworks"
CFLAGS += -DDEBUG -Wall
CFLAGS += -DMAC_OS_X_VERSION_MAX_ALLOWED=1050
BUILDDIR=./build/2.0
SRCDIR=./Classes
RESDIR=./Resources
OBJS=$(patsubst %.m,%.o,$(wildcard $(SRCDIR)/*.m))
OBJS+=$(patsubst %.mm,%.o,$(wildcard $(SRCDIR)/*.mm))
OBJS+=$(patsubst %.c,%.o,$(wildcard $(SRCDIR)/*.c))
OBJS+=$(patsubst %.cpp,%.o,$(wildcard $(SRCDIR)/*.cpp))
RESOURCES=$(wildcard $(RESDIR)/*)
all: dist
CFLAGS += -include Prefix.h
$(PROJECTNAME): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^
%.o: %.m
$(CC) -c $(CFLAGS) $< -o $@
%.o: %.mm
$(CC) -c $(CFLAGS) $< -o $@
%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
%.o: %.cpp
$(CC) -c $(CFLAGS) $< -o $@
dist: $(PROJECTNAME)
/bin/rm -rf $(BUILDDIR)
/bin/mkdir -p $(BUILDDIR)/$(APPFOLDER)
/bin/cp $(RESDIR)/* $(BUILDDIR)/$(APPFOLDER)
/bin/cp Info.plist $(BUILDDIR)/$(APPFOLDER)/Info.plist
@echo "APPL????" > $(BUILDDIR)/$(APPFOLDER)/PkgInfo
/usr/bin/ldid -S $(PROJECTNAME)
/bin/cp $(PROJECTNAME) $(BUILDDIR)/$(APPFOLDER)
install: dist
/bin/cp -r $(BUILDDIR)/$(APPFOLDER) /Applications/$(INSTALLFOLDER)
@echo "Application $(INSTALLFOLDER) installed"
killall SpringBoard
uninstall:
/bin/rm -fr /Applications/$(INSTALLFOLDER)
killall SpringBoard
reinstall: dist
/bin/rm -fr /Applications/$(INSTALLFOLDER)
/bin/cp -r $(BUILDDIR)/$(APPFOLDER) /Applications/$(INSTALLFOLDER)
@echo "Application $(INSTALLFOLDER) installed"
clean:
@rm -f $(SRCDIR)/*.o
@rm -rf $(BUILDDIR)
@rm -f $(PROJECTNAME)
需要注意的是,Prefix.h曾经是一个预编译的头文件,但我只是将其更改为头文件,并告诉make将其包含在我所有的源文件中。
我对没有包括最后报价的问题所做的快速修复是:
改变:
$(PROJECTNAME): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^
:
$(PROJECTNAME): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^"
在那篇长文之后重申我的问题。我对Makefile的更改是否以某种方式导致它不加载_main符号?
我发现我的实际应用程序名称由PROJECTNAME给出,其中有一个空格。我删除了这个空间,并将LD从apple-arm-darwin -gcc更改为apple-arm-darwin -g++。