[英]Makefile not linking the .o files
提供了以下Makefile來編譯我的項目。 它似乎是用過時的風格編寫的,盡管我正在閱讀官方的GNU Make手冊,但無法對其進行修復。 該項目本身似乎正確編譯了所有.o文件,因為它在我的工作目錄中創建了所有這些文件:main.o model.o param.o
# //////////////// NOMBRE DEL PROYECTO ///////////////////
#
P=project
#
EXE=$(P)
OBJS=main.o model.o param.o head.h
ADDLIBS=-D.
ADDINCFLAGS=-I.
SRCDIR=/root/projects/project
##########
CXX=g++
CXXFLAGS=-O3 -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -I$(COININCDIR)
CXXLINKFLAGS=-Wl,--rpath -Wl,/installed/CoinAll/lib
CC=gcc
CFLAGS=-03 -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wimplicit -Wparentheses -Wsequence-point -Wreturn-type -Wcast-qual -Wall
COININCDIR=/installed/CoinAll/include/coin
COINLIBDIR=/installed/CoinAll/lib
LIBS=-L$(COINLIBDIR) -lCbc -lCgl -lOsiClp -lOsi -lClp -lCoinUtils -lm \
`cat $(COINLIBDIR)/cgl_addlibs.txt` \
`cat $(COINLIBDIR)/clp_addlibs.txt` \
`cat $(COINLIBDIR)/coinutils_addlibs.txt`
# LIBS=-L$(COINLIBDIR) -lClp -lCoinUtils \
# -lm `cat $(COINLIBDIR)/coinutils_addlibs.txt`
INCL=-I`$(COININCDIR)`$(ADDINCFLAGS)
all: $(EXE)
.SUFFIXES: .cpp .c .o .obj
$(EXE): $(OBJS)
bla=;
for file in $(OBJS); do bla="$$bla ` $$file`"; done; \
$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla $(ADDLIBS) $(LIBS)
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<
.cpp.obj:
$(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then '$<'; else '$(SRCDIR)/$<'; fi`
.c.o:
$(CC) $(CFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<
.c.obj:
$(CC) $(CFLAGS) $(INCL) -c -o $@ `if test -f '$<'; then '$<'; else '$(SRCDIR)/$<'; fi`
這是我收到的錯誤消息,盡管正如我所說,.o文件是在目錄中創建的,但是似乎找不到它們將它們鏈接到我的可執行文件中。
/bin/sh: 1: main.o: not found
/bin/sh: 1: model.o: not found
/bin/sh: 1: param.o: not found
/bin/sh: 1: head.h: not found
collect2: error: ld returned 1 exit status
make: *** [project] Error 1
注意:這是我得到的完整輸出:
g++ -O3 -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -I/installed/CoinAll/include/coin -I`/installed/CoinAll/include/coin`-I. -c -o main.o `test -f 'main.cpp' || echo '/root/projects/project'`main.cpp
/bin/sh: 1: /installed/CoinAll/include/coin: Permission denied
main-farmer.cpp: In function ‘int main()’:
main-farmer.cpp:19:17: warning: variable ‘tiempo0’ set but not used [-Wunused-but-set-variable]
g++ -O3 -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -I/installed/CoinAll/include/coin -I`/installed/CoinAll/include/coin`-I. -c -o model.o `test -f 'model.cpp' || echo '/root/projects/project/'`model.cpp
/bin/sh: 1: /installed/CoinAll/include/coin: Permission denied
g++ -O3 -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -I/installed/CoinAll/include/coin -I`/installed/CoinAll/include/coin`-I. -c -o param.o `test -f 'param.cpp' || echo '/root//projects/project/'`param.cpp
/bin/sh: 1: /installed/CoinAll/include/coin: Permission denied
bla=;
for file in main.o model.o param.o head.h; do bla="$bla ` $file`"; done; \
g++ -Wl,--rpath -Wl,/installed/CoinAll/lib -O3 -fomit-frame-pointer -pipe -DNDEBUG -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -I/installed/CoinAll/include/coin -o farmer $bla -D. -L/installed/CoinAll/lib -lCbc -lCgl -lOsiClp -lOsi -lClp -lCoinUtils -lm `cat /installed/CoinAll/lib/cgl_addlibs.txt` `cat /installed/CoinAll/lib/clp_addlibs.txt` `cat /installed/CoinAll/lib/coinutils_addlibs.txt`
/bin/sh: 1: main.o: not found
/bin/sh: 1: model.o: not found
/bin/sh: 1: param.o: not found
/bin/sh: 1: head.h: not found
collect2: error: ld returned 1 exit status
make: *** [project] Error 1
在for循環中,以下位不正確。
` $$file`
這是不正確的,因為.o
文件不是要為其輸出運行的可執行文件。
這個makefile非常糟糕,您是正確的。
與上述問題類似。
除非$(COININCDIR)
是要運行的命令,否則此行是不正確的。
INCL=-I\`$(COININCDIR)\`$(ADDINCFLAGS)
此錯誤是/bin/sh: 1: /installed/CoinAll/include/coin: Permission denied
錯誤。
另外,除非打算將$(ADDINCFLAGS)
附加到$(COININCDIR)
的值(幾乎肯定不是)上,否則兩個變量之間需要有一個空格。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.