Make error: main.o: Command not found Makefile: recipe for target 'all' failed - makefile

# Makefile for Defmod
FFLAGS =
FPPFLAGS =
LDLIBS =
-include ${PETSC_DIR}/conf/variables
-include ${PETSC_DIR}/conf/rules
-include ${PETSC_DIR}/lib/petsc/conf/variables
-include ${PETSC_DIR}/lib/petsc/conf/rules
OBJS = main.o m_global.o m_local.o m_elems.o m_utils.o
m_utils.o : m_utils.F90
m_elems.o : m_elems.F90 m_utils.o
m_local.o : m_local.F90 m_elems.o
m_global.o: m_global.F90 m_local.o
main.o : main.F90 m_global.o
all: ${OBJS}
-${FLINKER} ${OBJS} -o ../defmod ${PETSC_LIB} ${LDLIBS}
when I enter make all, it pops out:
make[1]: Entering directory '/mnt/c/Users/gxyan/defmod-dev/src'
main.o m_global.o m_local.o m_elems.o m_utils.o -o ../defmod
make[1]: main.o: Command not found
Makefile:21: recipe for target 'all' failed
make[1]: [all] Error 127 (ignored)
make[1]: Leaving directory '/mnt/c/Users/gxyan/defmod-dev/src'
and all the environment variables of PETSC is set.
the configure of PETSC is done with the command:
./configure --with-cc=gcc --with-fc=gfortran --download-mpich --download-fblaslapack --download-cmake --download-metis --with-debugging=0
So, what's wrong?

make variable FLINKER is either not defined, or is defined but has the empty string value

You need to first set the PETSC_DIR variable. E.g., in BASH do:
export PETSC_DIR=/home/user/petsc
followed by
make all
Alternatively, you can do:
make all PETSC_DIR=/home/user/petsc

Related

make static pattern prerequisites problem

Recently, I am working on GNU Make.So I wrote such a file:
SOURCE_FILES := $(wildcard src/*.c)
OBJECT_FILES := $(SOURCE_FILES:src/%.c=dist/%.o)
all: ${OBJECT_FILES}
cc -o main $?
${OBJECT_FILES} : dist/%.o : src/*.c
cc -c $? -o $#
But I got the error below:
cc -c src/demo.c src/main.c -o dist/demo.o
cc -c src/demo.c src/main.c -o dist/main.o
cc -o main dist/demo.o dist/main.o
clang: error: no such file or directory: 'dist/demo.o'
clang: error: no such file or directory: 'dist/main.o'
clang: error: no input files
My question is, now that, the target is individual for target static pattern matching.
Why the $? refer to all the prerequisites?
How to get the prerequisites for individual target in static pattern matching?
I found the $< special automaic variable.
That works!

make: *** No rule to make target 'loader64.o', needed by 'wind64.exe'. Stop

Trying to compile WindowsD project with MSYS2-MINGW64 and get this error:
make: *** No rule to make target 'loader64.o', needed by 'wind64.exe'. Stop.
For the first time I am dealing with a makefile, I have tried many solutions to the problem that I found on the Internet, but without success..
How to resolve this problem?
Makefile problem part:
...
%.o : %.rc
windres $< $#
...
ifneq ($(LOADERS),)
loader32.rc: win7sp1x86/termdd.sys
echo -e '#include "defs.h"\nLOADER_ID RCDATA "$<"' | windres -o $#
loader64.rc: win7sp1x64/termdd.sys
echo -e '#include "defs.h"\nLOADER_ID RCDATA "$<"' | windres -o $#
endif
...

lack of the file (cholrl.a) during make

I install Lapack-3.6.1 on Ubutun.There is a problem during make, lack of the file (cholrl.a). The error message is this.
make[1]: Leaving directory '/usr/local/src/lapack-3.6.1/BLAS/SRC' ( cd
SRC/VARIANTS ; make) make[1]: Entering directory
'/usr/local/src/lapack-3.6.1/SRC/VARIANTS' gfortran -O2 -frecursive
-c cholesky/RL/cpotrf.f -o cholesky/RL/cpotrf.o gfortran -O2 -frecursive -c cholesky/RL/dpotrf.f -o cholesky/RL/dpotrf.o gfortran -O2 -frecursive -c cholesky/RL/spotrf.f -o cholesky/RL/spotrf.o gfortran -O2 -frecursive -c cholesky/RL/zpotrf.f -o
cholesky/RL/zpotrf.o ar cr LIB/cholrl.a cholesky/RL/cpotrf.o
cholesky/RL/dpotrf.o cholesky/RL/spotrf.o cholesky/RL/zpotrf.o ar:
LIB/cholrl.a: No such file or directory Makefile:38: recipe for target
'cholrl' failed make[1]: * [cholrl] Error 1 make[1]: Leaving
directory '/usr/local/src/lapack-3.6.1/SRC/VARIANTS' Makefile:39:
recipe for target 'variants' failed make: * [variants] Error 2
Do you have a solution?
Creating LIB directory myself worked for me. So, type mkdir LIB in SRC/VARIANTS.

Adding functionality to Makefile gives error :- "multiple definitoon here ..."

I have been given an already working Makefile which is actually working fine.
Makefile Contents can be found here in this post ...
Questions about Makefile - what is "$+" & where are .c files/dependencies called here ?
I am asking this question separately from my previous post mentioned above as it involves a different issue and adding it to that question would unnecessarily increase its length.
Now I have added one more functionality which is being used quite frequently at many places so I thought creating a separate file would be a nice idea so I created linklayer.c and added linklayer.o to $LIBOBJS.
I added this ...
LIBOBJS= linklayer.o csum.o compact.o protoname.o headers.o
parseargs.o cryptomod.o crc32.o
and this
linklayer.o: linklayer.c
$(CC) -o $# -c -I. $(CFLAGS) $+
I have declared function in sendip_module.h which is already declared and accessed in each of the module present in the project.
But now this multiple definition error is coming ... Have I done something wrong or misunderstood something?
Note: "ipv6_opts" is defined in ipv6.h
$ make all
for subdir in mec ; do \
cd $subdir ;\
make ;\
cd .. ;\
done
make[1]: Entering directory `/home/udit/Desktop/sendip-2.5-mec-2/mec'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/udit/Desktop/sendip-2.5-mec-2/mec'
gcc-4.4 -o ipv6.so -fPIC -fsigned-char -pipe -Wall -Wpointer-arith
-Wwrite-strings -Wstrict-prototypes -Wnested-externs -Winline -Werror
-g -Wcast-align -DSENDIP_LIBS=\"/usr/local/lib/sendip\" -shared ipv6.c
libsendipaux.a libsendipaux.a
libsendipaux.a(linklayer.o):(.data.rel.local+0x0)
: multiple definition of `ipv6_opts'
/tmp/ccxa4tMX.o:(.data.rel.local+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [ipv6.so] Error 1
and why this libsendipaux.a libsendipaux.a two times ? Is there something wrong with the Makefile itself.
Do I first need to manually compile it and then add it to libsendipaux.a ?
I am new to this Makefile stuff, so please help me understand how this is all working out here ?
Thanks.
Edit :
Remake debugging output -
remake -x
Reading makefiles...
Updating goal targets....
/home/udit/Desktop/sendip-2.5-mec-2/Makefile:33 File `all' does not exist.
/home/udit/Desktop/sendip-2.5-mec-2/Makefile:48 File `subdirs' does not exist.
/home/udit/Desktop/sendip-2.5-mec-2/Makefile:48 Must remake target `subdirs'.
for subdir in mec ; do \
cd $subdir ;\
make ;\
cd .. ;\
done
make[1]: Entering directory `/home/udit/Desktop/sendip-2.5-mec-2/mec'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/udit/Desktop/sendip-2.5-mec-2/mec'
/home/udit/Desktop/sendip-2.5-mec-2/Makefile:48 Successfully remade target file
`subdirs'.
File `ipv6.so' does not exist.
Must remake target `ipv6.so'.
gcc-4.4 -o ipv6.so -fPIC -fsigned-char -pipe -Wall -Wpointer-arith
-Wwrite-strings -Wstrict-prototypes -Wnested-externs -Winline -Werror
-g -Wcast-align -DSENDIP_LIBS=\"/usr/local/lib/sendip\" -shared ipv6.c
libsendipaux.a libsendipaux.a
libsendipaux.a(linklayer.o):(.data.rel.local+0x0)
: multiple definition of `ipv6_opts'
/tmp/ccb0oaXR.o:(.data.rel.local+0x0): first defined here
collect2: ld returned 1 exit status
remake: *** [ipv6.so] Error 1
#0 ipv6.so at ??
#1 all at /home/udit/Desktop/sendip-2.5-mec-2/Makefile:33
33rd line -> all: $(LIBS) subdirs sendip $(PROTOS) sendip.1 sendip.spec
I guess it could not help me out .... actual problem is with my understanding of scenario itself. Please help me bring out of the mess.
the problem you are facing, is that you are linking together several objects where at least two of them define de function ipv6_opts.
since there are two implementations of the function, your linker cannot decide which one to use and throws an error.
the problem most likely comes from the fact that you are linking libsendipaux.a twice into your final binary.
the reason why this happens is here:
%.so: %.c $(LIBS)
$(CC) -o $# $(CFLAGS) $(LIBCFLAGS) $+ $(LIBS)
in this target, $+ will expand to all the dependencies of your target (that is: %.c $(LIBS), which will in turn be resolved to ipv4.c libsendipaux.a
the actual call to the compiler can then be read as $(CC) -o $# $(CFLAGS) $(LIBCFLAGS) ipv4.c $(LIBS) $(LIBS), and $(LIBS) $(LIBS) will expand to libsendipaux.a libsendipaux.a, which will produce the erroneous double linkeage.
so the solution is to remove extraneous $(LIBS) from the .so target:
%.so: %.c $(LIBS)
$(CC) -o $# $(CFLAGS) $(LIBCFLAGS) $+
btw, the errors you get in remake about non-existing files, are because all and subdirs are indeed no files, but phony targets (targets that do no generate files called after the target-name).
to prevent those warnings, add something like the following to your makefile:
.PHONY: all subdirs

make: *** No rule to make target `all'. Stop

I keep getting this error:
make: *** No rule to make target `all'. Stop.
Even though my make file looks like this:
CC=gcc
CFLAGS=-c -Wall
all: build
build: inputText.o outputText.o main.o
gcc main.o inputText.o outputText.o -o main
main.o: main.c
$(CC) $(CFLAGS) main.c -o main.o
inputText.o: inputText.c
$(CC) $(CFLAGS) inputText.c -o inputText.o
outputText.o: outputText.c
$(CC) $(CFLAGS) outputText.c -o outputText.o
Yes there should be a tab space underneath the target and there is in my make file.
I can get it to work if I try one of the targets like main.o, inputText.o and outputText.o but can't with either build or all.
EDIT:
I just randomly tried running make and telling it the file using the following command:
make -f make
This works but why doesn't just typing make work?
Your makefile should ideally be named makefile, not make. Note that you can call your makefile anything you like, but as you found, you then need the -f option with make to specify the name of the makefile. Using the default name of makefile just makes life easier.

Resources