2012-11-25 48 views
0

我正在使用this generic makefileMakefile錯誤:缺少分隔符,使用SDL和OpenGL編譯

與此自定義的選項:而不是

# The pre-processor options used by the cpp (man cpp for more). 
CPPFLAGS = -Wall -I/Library/Frameworks/SDL.framework/Headers 

# The options used in linking as well as in any direct use of ld. 
LDFLAGS = -framework SDL -framework Cocoa -framework OpenGL 

# The executable file name. 
# If not specified, current directory name or `a.out' will be used. 
PROGRAM = app 

# The source file types (headers excluded). 
# .c indicates C source files, and others C++ ones. 
SRCEXTS = .c .C .cc .cpp .CPP .c++ .cxx .cp .m 

clean: 
    $(RM) $(OBJS) $(PROGRAM) $(PROGRAM) 

# The pre-processor options used by the cpp (man cpp for more). 
CPPFLAGS = -Wall 

# The options used in linking as well as in any direct use of ld. 
LDFLAGS = 

# The executable file name. 
# If not specified, current directory name or `a.out' will be used. 
PROGRAM = 

# The source file types (headers excluded). 
# .c indicates C source files, and others C++ ones. 
SRCEXTS = .c .C .cc .cpp .CPP .c++ .cxx .cp 

clean: 
    $(RM) $(OBJS) $(PROGRAM) $(PROGRAM).exe 

Here你可以找到我運行生成文件的完整版本。

我使用Mac OS X 10.6.8和gcc 4.2.1,並嘗試使用SDL和OpenGL編譯main.cppSDLMain.mSDLMain.h

彈出的錯誤是:

main.d:1: * missing separator. Stop.

和文件main.d(由生成的makefile)是這樣的:

-n ./ 
main.o: main.cpp 

什麼問題?

+0

你在這裏表現出整個文件?因爲我沒有看到一個'include'行,但它正在抱怨單獨文件('main.d')的內容。 * //讀取錯誤信息:這就是你所做的。* – dmckee

+0

@dmckee [This](http://pastebin.com/fqXxDesJ)是該文件的完整粘貼。 (注意我的問題的第一行)。 – Shoe

+1

*「(另請注意,我的問題的第一行)」*我不讀代碼的網站:你的問題應該站在它自己的。特別是,如果要點擊幾次甚至可以看到它,我尤其不會閱讀代碼。你對現有的依賴文件('.d's)有問題。清除它們,看看它是否再次出現。 – dmckee

回答

0

我換成echo -nprintf,它解決了這個問題:

# Rules for creating dependency files (.d). 
#------------------------------------------ 

%.d:%.c 
    @printf $(dir $<) > [email protected] 
    @$(DEPEND.d) $< >> [email protected] 

%.d:%.C 
    @printf $(dir $<) > [email protected] 
    @$(DEPEND.d) $< >> [email protected] 

%.d:%.cc 
    @printf $(dir $<) > [email protected] 
    @$(DEPEND.d) $< >> [email protected] 

%.d:%.cpp 
    @printf $(dir $<) > [email protected] 
    @$(DEPEND.d) $< >> [email protected] 

%.d:%.CPP 
    @printf $(dir $<) > [email protected] 
    @$(DEPEND.d) $< >> [email protected] 

%.d:%.c++ 
    @printf $(dir $<) > [email protected] 
    @$(DEPEND.d) $< >> [email protected] 

%.d:%.cp 
    @printf $(dir $<) > [email protected] 
    @$(DEPEND.d) $< >> [email protected] 

%.d:%.cxx 
    @printf $(dir $<) > [email protected] 
    @$(DEPEND.d) $< >> [email protected] 

%.d:%.m 
    @printf $(dir $<) > [email protected] 
    @$(DEPEND.d) $< >> [email protected] 
+0

這些行實際上*做*有道理!沒有它們的依賴不會正確處理子目錄中的文件。問題是使用'echo'(可能是你的設置中的'make'使用的shell中的一個):它不理解'-n'選項,它應該在'echo'結尾壓制換行符'' s產量。 –

+0

@DietmarKühl,'printf'的工作原理是什麼? – Shoe

+0

是的,我認爲是。顯然,你不會使用'-n'選項,而是忽略格式中的任何換行符。然而,我不認爲'printf'是一個標準的POSIX shell命令,這可能是'echo'被使用的原因(雖然我不確定'-n'選項是否標準;我不認爲它是)。 –

1

您顯示的Makefile [exerpt]不顯示main.d的創建方式,但它似乎包含在實際的Makefile中。它可能意味着包含main.cpp的依賴關係,但包含-n ./' is clearly not valid make`語法。嘗試現在刪除文件,如果它被重新生成,你需要找到它是如何生成的,並解決這個問題。看看它是如何再次產生刪除該文件,並使用

make -p 2>&1 | tee mkerr 

一旦完成,mkerr包含make命令的輸出,包括它使用的規則。有一個規則是如何構建.d文件。隨着一點點運氣,刪除文件排序問題...

基於發佈到pastebin該問題的代碼是如何%.d文件被創建的規則:

%.d: %.cpp 
    @echo -n $(dir $<) > [email protected] 
    @$(DEPEND.d) $< << [email protected] 

的問題是,發現的echo不理解-n選項,該選項旨在避免任何換行符。規則的第一行應該爲文件添加一個目錄前綴。 esieast修復是找到更好的echo,它理解-n選項。雖然,您可能需要使用不同的外殼,因爲echo往往是內置的外殼!在這種情況下,您可能最好使用echo上的完整路徑指向不會出現錯誤的版本。

+0

我嘗試刪除'.d'文件並再次運行'make',它仍然會再次創建它。完整的文件請看[這裏](http://pastebin.com/fqXxDesJ)。 – Shoe

+0

@Jeffrey:你是否用'-p'選項運行以查看完整的規則集? –

+0

我剛剛試過運行'make -p'並打印makefile。它是用'-n。/'做什麼的? '-n'標誌的含義是什麼? (I [試圖](http://www.google.it/#hl=it&gs_nf=3&qe=LW4gZmxhZyBtYWtlZmlsZQ&qesig=uTjr2lI3792UCBsMoSjm4w&pkc=AFgZ2tmFXf6nSo26tlvpJYJnXI9bs3B1jRth0p83G1N91Cq_0m0Wb7Aib28tARcz3WPTC0w01iJutlEyqHChVAaCnRy786QRtQ&pq=gcc%20flags&cp=16&gs_id=5g&xhr=t&q=-n+flag+makefile&pf=p&tbo=d&sclient= psy-ab&oq = -n + flag + makefile&gs_l =&pbx = 1&bav = on.2,or.r_gc.r_pw.r_cp.r_qf。&fp = 70759a6a8974c64e&bpcl = 38897761&biw = 1279&bih = 680)和[試用](http:// tigcc。 ticalc.org/doc/comopts.html)用Google搜索它) – Shoe