简体   繁体   中英

Makefile not linking the .o files

I have been provided the following Makefile to compile my project. It seems to be written in pretty old-fashioned style, and although I am reading the official GNU Make manual I am not able to fix it. The project itself seems to correctly compile all the .o files, as it creates all of them in my working directory: 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`

This is the error message I am getting, although, as I said, the .o files are created in the directory, but it doesn't seem to find them to link them into my executable.

/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

Note: this is the complete output I get:

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

In the for loop the following bit is incorrect.

` $$file`

It is incorrect since the .o files are not executables to be run for their output.

This makefile is quite terrible, you were correct about that.

Similar to the above issue.

This line is incorrect unless $(COININCDIR) is a command to run.

INCL=-I\`$(COININCDIR)\`$(ADDINCFLAGS)

This mistake is the cause of the /bin/sh: 1: /installed/CoinAll/include/coin: Permission denied errors.

Additionally, unless $(ADDINCFLAGS) is intended to be attached to the value of $(COININCDIR) (which it almost certainly isn't) a space is needed between the two variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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