繁体   English   中英

Makefile没有链接.o文件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM