Makefile Issues: Error 127, 255, running programs within makefile - c++

I am a student in ECE working on a programming assignment; it has already been submitted and is being graded, but I still want to know why my makefile isn't working. When I run the file on our school server with the command 'make tests' it responds
'make: testq: command not found.
make * tests error 127
If I run 'make testq12345' it will actually run my program "myar" and produce the output file, but it will then give an error 255. I don't understand the issue, or why the makefile cannot find the targets. I've searched via stackoverflow and other sources about these errors but don't understand and can't find a workable solution. If it matters I'm running it on a Linux server.
I am running it in CS311/Homework4/test which contains the makefile, programs and text files.
Thanks for your time and assistance; its appreciated.
#
# $RCSfile$
# $Revision$
# $Author$
# $Date$
# $Log$
#
# Author: Cody R Crawford
# Email: crawfoco#onid.orst.edu
# Course: CS311-400
# Homework: 4
# Citations:
# http://mrbook.org/tutorials/make/
# For examples, guidance, and genera understanding
# Assumptions: I assume you want the .o files to show up unless
# you specifically command 'clean'
#########################################################
CC=gcc
DEBUG=-g
CFLAGS=$(DEBUG) -Wall
PROGS=sig_demo myar
OBJECTS=$(PROGS:.c=.o)
all: $(PROGS)
sig_demo.o: sig_demo.c
$(CC) $(CFLAGS) -c sig_demo.c
sig_demo.c: sig_demo.o
$(CC) $(CFLAGS) -c sig_demo.c
myar.o: myar.c
$(CC) $(CFLAGS) -c myar.c
myar.c: myar.o
$(CC) $(CFLAGS) -c myar.c
tests:
testq
testt
testv
testq:
testq24
testq135
testq12345
testq24:
rm -f ar24.ar
ar q ar24.ar 2-s.txt 4-s.txt
myar q myar24.ar 2-s.txt 4-s.txt
diff ar24.ar myar24.ar
testq135:
rm -f ar135.ar
ar q ar135.ar 1-s.txt 3-s.txt 5-s.txt
myar q myar135.ar 1-s.txt 3-s.txt 5-s.txt
diff ar135.ar myar135.ar
testq12345:
rm -f ar12345.ar
rm -f myar12345.ar
ar q ar12345.ar 1-s.txt 2-s.txt 3-s.txt 4-s.txt 5-s.txt
./myar -q myar12345.ar 1-s.txt 2-s.txt 3-s.txt 4-s.txt 5-s.txt
diff ar135.ar myar135.ar
testt:
testt24
testt135
testt12345
testt24:
rm -f ar24.ar
ar q ar24.ar 2-s.txt 4-s.txt
ar t ar24.ar > ar-ctoc.txt
myar -t ar24.ar > myar-ctoc.txt
diff ar-ctoc.txt myar-ctoc.txt
testt135:
rm -f ar135.ar
ar q ar135.ar 1-s.txt 3-s.txt 5-s.txt
ar t ar135.ar > ar-ctoc.txt
myar -t ar135.ar > myar-ctoc.txt
diff ar-ctoc.txt myar-ctoc.txt
testt12345:
rm -f ar12345.ar
ar q ar12345.ar 1-s.txt 2-s.txt 3-s.txt 4-s.txt 5-s.txt
ar t ar12345.ar > ar-ctoc.txt
myar -t ar12345.ar > myar-ctoc.txt
diff ar-ctoc.txt myar-ctoc.txt
testv:
testv24
testv135
testv12345
testv24:
rm -f ar24.ar
ar q ar24.ar 2-s.txt 4-s.txt
ar v ar24.ar > ar-ctoc.txt
myar -v ar24.ar > myar-ctoc.txt
diff ar-ctoc.txt myar-ctoc.txt
testv135:
rm -f ar135.ar
ar q ar135.ar 1-s.txt 3-s.txt 5-s.txt
ar v ar135.ar > ar-ctoc.txt
myar -v ar135.ar > myar-ctoc.txt
diff ar-ctoc.txt myar-ctoc.txt
testv12345:
rm -f ar12345.ar
ar q ar12345.ar 1-s.txt 2-s.txt 3-s.txt 4-s.txt 5-s.txt
ar v ar12345.ar > ar-ctoc.txt
myar -v ar12345.ar > myar-ctoc.txt
diff ar-ctoc.txt myar-ctoc.txt
clean:
rm -f $(PROGS) $(OBJECTS) *.o *~

Dependencies should be listed on the same line, otherwise it will try to execute them as commands;
For example;
tests:
testq
testt
testv
will just try to execute the shell commands testq, testt and testv which don't exist and give your error, while;
tests: testq testt testv
will just see to that the makefile targets testq, testt and testv are completed before the target tests is executed. In this case tests contains no commands, so the only thing that target does is see to that the depdendencies are executed.

I think you are looking for this:
A simple makefile consists of "rules" with the following shape:
target ... : dependencies ...
command
...
...
This is what you need to fix:
tests: testq testt testv
testq: testq24 testq135 testq12345
testv: testv24 testv135 testv12345

Related

GCC (MingW) + LD generate nearly empty executable. Why?

For a specific requirement, I need my binary to fall below 510bytes.
Doing the program in assembler, I get <100 bytes, while adding same code in C++, the resulting code is over 1K. Looking the resulting binary, mostly all ( + 90%) is full of 0x00 characters (Only a few characters at the beginning and end are really populated).
Currently building commands:
gcc -Wall -Os -s -Wl,--stack,32 -nostdinc -nostdinc++ -fno-ident -fno-builtin -I. -c -o cppFile.coff cppFile.cpp
nasm -f elf -o main.elf main.asm
ld -T link.ld -o out.elf main.elf cppFile.coff
objcopy -O binary out.elf out.bin
Size of files generated:
cppFile.coff = 684 bytes
main.elf = 640
out.elf = 2707
out.bin = 1112
When not linking to the cppFile.coff (with only one empty function)
out.elf = 1984
out.bin = 31 (tested and working)
Why GCC or LD add so many nul charactres?
How to remove this empty space?
ENTRY(start)
phys = 0x7c00;
HEAP_SIZE = 0;
SECTIONS
{
.text phys : AT(phys) {
code = .;
*(.text)
*(.rodata)
}
.data : AT(phys + (data - code))
{
data = .;
*(.data)
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
}
end = .;
}

OCaml : Unbound Module.function value

I'm new to OCaml and I am a little confused about Modules.
I tried to implement a really simple test but I can't compile it...
Here are the files (I'm on Linux by the way) :
main.ml
let main () =
if ((Array.length Sys.argv) > 2 && int_of_string Sys.argv.(1) > 1 && int_of_string Sys.argv.(2) > 1)
then
begin
Printf.printf "Args = %d && %d\n" (int_of_string Sys.argv.(1)) (int_of_string Sys.argv.(2));
Laby.initLaby (int_of_string Sys.argv.(1)) (int_of_string Sys.argv.(2))
end
else
Printf.printf "Usage : ./test x y n"
let _ = main ()
Laby.ml
let initLaby (x : int) (y : int) =
let testCell = Cell.initCell 0 1 in
begin
Printf.printf "Init Laby with X(%d) / Y(%d)\n" x y;
Cell.printCell testCell;
end
Cell.ml
module type CELL =
sig
type t
val initCell : int -> int -> t
val printCell : t -> unit
end
module Cell : CELL =
struct
type t = (int * int)
let initCell (x : int) (y : int) =
(x, y)
let printCell (x, y) =
Printf.printf "Cell -> X(%d) / Y(%d)\n" x y
end
Cell.mli
module type CELL =
sig
type t
val initCell : int -> int -> t
val printCell : t -> unit
end
module Cell : CELL
And here is the Makefile :
NAME = test
ML = Cell.ml \
Laby.ml \
main.ml
MLI = Cell.mli
CMI = $(MLI:.mli=.cmi)
CMO = $(ML:.ml=.cmo)
CMX = $(ML:.ml=.cmx)
OCAMLDPE = ocamldep
CAMLFLAGS = -w Aelz -warn-error A
OCAMLC = ocamlc $(CAMLFLAGS)
OCAMLOPT = ocamlopt $(CAMLFLAGS)
OCAMLDOC = ocamldoc -html -d $(ROOT)/doc
all: .depend $(CMI) $(NAME)
byte: .depend $(CMI) $(NAME).byte
$(NAME): $(CMX)
#$(OCAMLOPT) -o $# $(CMX)
#echo "[OK] $(NAME) linked"
$(NAME).byte: $(CMO)
#$(OCAMLC) -o $# $(CMO)
#echo "[OK] $(NAME).byte linked"
%.cmx: %.ml
#$(OCAMLOPT) -c $<
#echo "[OK] [$<] builded"
%.cmo: %.ml
#$(OCAMLC) -c $<
#echo "[OK] [$<] builded"
%.cmi: %.mli
#$(OCAMLC) -c $<
#echo "[OK] [$<] builded"
documentation: $(CMI)
#$(OCAMLDOC) $(MLI)
#echo "[OK] Documentation"
re: fclean all
clean:
#/bin/rm -f *.cm* *.o .depend *~
#echo "[OK] clean"
fclean: clean
#/bin/rm -f $(NAME) $(NAME).byte
#echo "[OK] fclean"
.depend:
#/bin/rm -f .depend
#$(OCAMLDPE) $(MLI) $(ML) > .depend
#echo "[OK] dependencies"
Here is the output of the Makefile :
[OK] dependencies
[OK] [Cell.mli] builded
[OK] [Cell.ml] builded
File "Laby.ml", line 3, characters 17-30:
Error: Unbound value Cell.initCell
Makefile:47: recipe for target 'Laby.cmx' failed
make: *** [Laby.cmx] Error 2
I think it's a compilation error, since it seems to not found the Cell module, but I can't make it works...
What am I doing wrong, and how can I fix it?
Each .ml file serves as its own module. You seem to have module Cell inside cell.ml which is double. You would have to address that function as Cell.Cell.initCell. Or open Cell in laby.ml. Also, I think .ml file names are conventionally lowercase? Aside: why does make output wrong english?

Undefined reference to function when linking [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
Trying to make a c++ program splitting a line and creating 2 std::vector to save elements from said line.
This is the function I call:
void readConf(const char *name, std::vector<t_objectLibrary> libs, std::vector<IObject *> &objs, std::vector<IObject *> &timer)
I placed in inside config.hpp which has it's prototype :
void readConf(const char *name, std::vector<t_objectLibrary> libs,std::vector<IObject *> &objs, std::vector<IObject *> timer);
and in the main I call it like this :
int main(int ac, char **av)
{
std::vector<IObject *> objs;
std::vector<IObject *> timer;
std::vector<t_objectLibrary> libs;
libs = lib_read("./src/objectLibrary");
readConf("config.txt", libs, objs, timer);
...
}
yet I get this error message when I compile with the Makefile. Everything is fine until the last message of compilation it says this :
Here is the Makefile I use (Asked in the comments) :
11 │ SRC = src/getvalue.cpp \
12 │ src/iobject.cpp \
13 │ src/attributes.cpp \
14 │ src/dynamic_lib.cpp \
15 │ src/config.cpp \
16 │ src/color.cpp \
17 │ src/main.cpp
18 │
19 │ OBJ = $(SRC:.cpp=.o)
20 │
21 │ NAME = conf
22 │
23 │ CXX = g++ -std=c++11 -Wall -Wextra -lsfml-graphics -lsfml-window -lsfml-system -fPIC
24 │
25 │ RM = rm -f
26 │
27 │ all: $(NAME) $(OBJ)
28 │
29 │ $(NAME): $(OBJ)
30 │ $(CXX) $(OBJ) -o $(NAME) -ldl
31 │
32 │ clean:
33 │ $(RM) $(OBJ)
34 │
35 │ fclean: clean
36 │ $(RM) $(NAME)
37 │
38 │ re: fclean all
39 │
40 │ .phony: all clean fclean re
The function signature in the hpp doesn't exactly match that in the declaration.
For further reading, consider another SO thread.
In your case, perhaps, a typo (check method signature in hpp).
hth

Pattern Matching in cron

I want to grep line which begin with # or #* or number or #number. In other word, I want to greping from the beginning of cron command until end of line. I don't need crontab header.
Here is crontab file :
# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#*/56 * * * * root bash /media/data/minutely.sh
#20 * * * * root bash /media/data/hourly.sh
#* * * * * root bash /media/data/looping.sh
* * * * * root bash /media/data/looping2.sh
20 * * * * root bash /media/data/hourly2.sh
And what I want is :
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#*/56 * * * * root bash /media/data/minutely.sh
#20 * * * * root bash /media/data/hourly.sh
#* * * * * root bash /media/data/looping.sh
* * * * * root bash /media/data/looping2.sh
20 * * * * root bash /media/data/hourly2.sh
.
.
.
.
#until end of line
I have try with :
cat /etc/crontab | grep '^[^#0-9]'
But it give me output :
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
How can grep only pattern that I have explain above?
Sorry for bad english.
Here's another sed variant that starts printing at the first line that begins with a digit:
sed -n '/^[0-9]/,$p' /etc/crontab
You can do it with sed:
sed -n '6,${/^[0-9#]/p}' /etc/crontab
-n option prevents to display lines automatically
6,$ is a range of lines (from line 6 to the last line)
/^[0-9#]/ tests if the line begin with # or a digit. If the test succeeds, p print the line.

Values of numbers being lost (changed) when called in subroutine

I have written two .f90 text files prog1.f90:
PROGRAM prog1
READ (5,*) A,B,C
PRINT*, "A = ",A
PRINT*, "B = ",B
PRINT*, "C = ",C
CALL test(A,B,C)
END PROGRAM prog1
and aux.f90
SUBROUTINE test(E,F,G)
real(kind=8) :: E,F,G
PRINT*,"E = ",E
PRINT*,"F = ",F
PRINT*,"G = ",G
END SUBROUTINE test
Which are compiled using the Makefile:
FC = gfortran
FCFLAGS = -g -fbounds-check
FCFLAGS = -O2
FCFLAGS += -I/usr/include
PROGRAMS = prog1
all: $(PROGRAMS)
prog1: aux.o
%: %.o
$(FC) $(FCFLAGS) -o $# $^ $(LDFLAGS)
%.o: %.f90
$(FC) $(FCFLAGS) -c $<
%.o: %.F90
$(FC) $(FCFLAGS) -c $<
.PHONY: clean veryclean
clean:
rm -f *.o *.mod *.MOD
veryclean: clean
rm -f *~ $(PROGRAMS)
I use this makefile to compile prog1 and then run prog1 with the input file input.inp:
0.0033943878 0.0018085515 0.0011798956
I expect the output of this code to be
A = 0.339439E-02
B = 0.180855E-02
C = 0.117990E-02
E = 0.339439E-02
F = 0.180855E-02
G = 0.117990E-02
However it is:
A = 0.339439E-02
B = 0.180855E-02
C = 0.117990E-02
E = 0.100765847236215E-21
F = 0.750936901926887E-24
G = 0.261410786221168-313
The number are much much smaller in the subroutine and seem to have no logical connection to the original A,B and C and are returned from the subroutine as such.
I take it my error is to do with the type I am storing these numbers as, i.e. they are not read in as real(kind=8) but are being converted into this type causing the error but I am not sure what the type should be in the subroutine or if this is even the cause. I may just be missing something obvious.
Any help would be appreciated and please tell me if I need to clarify anything I have written.
Thank you for your time.
James
You made the common error to forget the IMPLICIT NONE statement at the beginning of your program. (At least, it is heavily recommended to avoid this kind of error.)
As a result, all variables starting with I, J, K, L, M or N are of type INTEGER(4) and all other variables of type REAL(4). This means, that your variables A, B and C are of REAL(4). Passing them to the subroutine results in principle in an undetected type mismatch which results in misinterpreted values.
You should always place IMPLICIT NONE at the beginning of your programs and modules to be forced to specify explicit types for your variables!
I think I have fixed this error by correcting prog1.f90:
PROGRAM prog1
real(kind=8) :: A,B,C
READ (5,*) A,B,C
PRINT*, "A = ",A
PRINT*, "B = ",B
PRINT*, "C = ",C
CALL test(A,B,C)
END PROGRAM prog1