我已经提供了以下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
答案 0 :(得分:1)
在for循环中,以下位不正确。
` $$file`
这是不正确的,因为.o
文件不是为其输出运行的可执行文件。
这个makefile非常糟糕,你对此是正确的。
与上述问题相似。
除非$(COININCDIR)
是要运行的命令,否则此行不正确。
INCL=-I\`$(COININCDIR)\`$(ADDINCFLAGS)
此错误是导致/bin/sh: 1: /installed/CoinAll/include/coin: Permission denied
错误的原因。
此外,除非$(ADDINCFLAGS)
旨在附加到$(COININCDIR)
的值(几乎肯定不是这样),否则两个变量之间需要一个空格。