我目前正在尝试构建一个我使用 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.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 符号?