C Programming: makefile:2: *** missing separator. Stop - arrays

My code is a spellchecker program that checks words from an input file and that checks those words from the inputfile with a dictionary file.
I am trying to create a makefile and keep getting this error here makefile:2: *** missing separator. Stop. In Addition, I am writing my code in repl.it.
I don't know what is happening or why it is doing that?
This is my makefile contents:
a.out: main.o spell_lib.o spell.o
gcc *.o
main.o: main.c spell_lib.h spell_lib.c
gcc -c main.c
spell_lib.o: spell_lib.h spell_lib.c
gcc -c spell_lib.c

regarding: gcc *.o
this line must begin with a <tab> not a space

I was able to fix the issue, i just went and copied and pasted my code i had previously created in putty which has the correct indentations.

Related

Makefile in C: all vs target -std=c1x error

I am working on a C homework assignment and I came across a simple yet specific error when creating my Makefile.
My initial Makefile was simple:
all: numbers.o
gcc -Wall -pedantic -std=c1x numbers.c -o numbers
clean:
rm *.o
For whatever reason, despite the C program compiling correctly in the terminal, I repeatedly get the following error:
gcc: error: -std=c1x: No such file or directory
Makefile:2: recipe for target 'all' failed
The problem was actually because I had copied the gcc line from a pdf file. Thanks to the comment by raspy:
For sure it has nothing to do with target name. It looks like gcc did not treat the switch as a switch, but rather as a file name. Have you copied this command from somewhere? It happens that the - is not a simple dash but some dashy-looking Unicode character, most notably converted in word processors.

Makefile generating error

Every time I enter the command on UNIX
unix1% make clean
It returns an error message
mksh: Warning: newline is not last character in file makefile
Current working directory /home/s/m/mel
rm -f *.o core firstpass
unix1%
Here is my makefile:
firstpass: main.o hashFunct.o symbolTable.o opcodeTable.o
gcc main.o hashFunct.o symbolTable.o opcodeTable.o -o firstpass
main.o: main.c
gcc -c main.c
hashFunct.o: hashFunct.c
gcc -c hashFunct.c
symbolTable.o: symbolTable.c
gcc -c symbolTable.c
opcodeTable.o: opcodeTable.c
gcc -c opcodeTable.c
clean:
rm -f *.o core firstpass
I don't understand the problem, and I've tried to open it in emacs and see no mysterious characters. Also the word firstpass is the last character in the makefile. What does this error exactly mean?
mksh: Warning: newline is not last character in file makefile
The problem is exactly what it said, it wants a newline as the last character of the file. Currently the last character is probably the s of firstpass.
Open it in an editor, go to the end of the file, hit return.
Some editors will add a final newline to files for you.
A newline at the end of a file should not be a requirement. This sort of warning is common in older systems whose parsers might freak out if they are given input without a newline. Perl 1 is the only time I've seen this in the wild, and that's from 1987, but C compilers still issue this warning.

C Makefile compilation error - "linker input file unused because linking not done"

I'm having a problem with a C Makefile.
This is the code for the Makefile in bash:
CC=gcc
CFLAGS=-g -Wall
CCLINK=$(CC)
OBJS=flight.o runway.o airport.o main.o
RM=rm -f
# Creating the executable (airport)
airport: $(OBJS)
$(CCLINK) -o airport $(OBJS)
# Creating object files using default rules
main.o: main.c airport.h ex2.h flight.h runway.h
airport.o: airport.c airport.h ex2.h flight.h runway.h
runway.o: runway.c runway.h ex2.h flight.h
flight.o: flight.c flight.h ex2.h
# Cleaning old files before new make
clean:
$(RM) airport *.o *.bak *~ "#"* core
When I make the file, it says that:
make: `airport` is up to date.
After that - I can call "airport" in bash and it lets me enter some inputs the way I want it to be.
BUT- when I'm trying to check if "airport" is compiled by:
gcc -g -Wall -c airport
I get an error says that:
gcc: airport: linker input file unused because linking not done
Does someone know what could be the problem?
Thanks!
Gavriel.
The aim of Makefile is to avoid recompiling a file if its source is unchanged; when it happens, make says that the file is up to date.
This might be annoying if you want to check again the warnings. Then, simply call make to recompile everything, by typing
make clean ; make
Another goal of Makefile is to avoid typing the gcc commands by yourself, prone to errors. For instance, at the end of your question, you ask to make an object file from an executable (option -c), which is wrong. The good way to make an object file is to call make :
make airport.o
Finally, to produce the executable, you can either type
make airport
or, since airport: is the first target, type
make

How to create makefile for program using curses.h

I am struggling with making a makefile for the sample code below using curses.h.
#include <stdio.h>
#include <stdlib.h>
#include<curses.h>
int main(){
WINDOW *initscr(void);
initscr();
int endwin(void);
return 0;
}
I included library and header in Netbeans, but when I try to build with makefile:
CC=C:\TDM-GCC-64\bin\gcc
CFLAGS=-std=gnu99 -Werror -Wall -lm -lncurses
DEPS=curses.h
OUTPUT=main
all:
echo "Building all"
$(CC) $(CFLAGS) render.c -o $(OUTPUT)
it gives me :
echo "Building all"
Building all
C:\TDM-GCC-64\bin\gcc -std=gnu99 -Werror -Wall -lm -lncurses render.c -o main
render.c:3:19: fatal error: curses.h: No such file or directory
#include<curses.h>
^
compilation terminated.
make.exe": *** [all] Error 1
BUILD FAILED (exit value 2, total time: 150ms)
Just add -I. -L. to your CFLAGS macro, this adds the project library to the search paths of both the preprocessor and linket. This should work provided you have curses header and library files in your project folder. If the header or library files are in different folders just modify -I or -L flags accordingly.
Your last comment suggested that the preprocessing and compilation went fine but the linker could not locate the library file.
As a general note, it would be a good idea to put compiler flags to CFLAGS and linker flags to a different macro, say LDFLAGS.
Macro DEPS should also be used to enable incremental compilation. It is usually used as a dependency to the compilation rule but since you don't have it separately you could put it besides all such as this:
all : $(DEPS)
Here is what I did, it works, but it still returns 8 errors.
Solution to fix 1 of the 8 errors is listed further down.
I cd to the location of thadgavin.c
( for me it is "pset1/source")
For ubuntu (I used 16.04)
$ cc thadgavin.c -lm -lncurses
$ ./a.out
You can rename a.out to thadgavin (same as "make" would have done if it would have worked).
$ mv a.out thadgavin
There you go, hope this helps resolve the last of the errors.
Note:
There is an easy error fix in main(), you need to specify it as an int first. I believe it is on line 61?
Eg;
"int main()" shows only as "main()" due to "int" being up at the top with the abstracted layout syntax I do not believe it knows it has been called as an int. I may be wrong, hopefully someone else can shed light to this problem.
https://youtu.be/oOUgU0z4qeY
If you solve any of the rest of the errors, please post to my video or email Python253#gmail.com for others to benefit from your solution.
Thank you,
My name is Daniel Paul Evans
.... And this is CS50!

make: *** No rule to make target `gcc', needed by `all'. Stop

I am going through an eg pgm to create a make file.
http://mrbook.org/tutorials/make/
My folder eg_make_creation contains the following files,
desktop:~/eg_make_creation$ ls
factorial.c functions.h hello hello.c main.c Makefile
Makefile
all:gcc -c main.c hello.c factorial.c -o hello
error:
desktop:~/eg_make_creation$ make all
make: *** No rule to make target `gcc', needed by `all'. Stop.
Please help me understand to compile this program.
The syntax of makefiles is very strict:
target:dependencies
build_rules
# ^ this space here _needs_ to be a tab.
What you wrote makes all depend on gcc, -c, ... which are not valid targets.
What you need is something like:
all: hello
hello: factorial.c functions.h hello.c main.c
gcc -o hello factorial.c hello.c main.c
(If you want to compile and link in one step, don't use the -c switch).
Mat nailed it.
In my particular case, I'm using vi and have the expandtab enabled by default!!
To see if this issue applies to you, open vi and do:
:set list
If you don't see a ^I where a tab should be, then you most likely have the et enabled.
To disabled it just:
:set expandtab!
Maybe it helps somebody else as well.
Another reason is because you have the wrong name in the list of source files. (nameWrong.o instead of nameRight.o) That was my issue.
After all: everything is target, shows dependency anything written after that should present that directory,as in your code gcc(as a file is not present) like wise -c too
all:gcc -c main.c hello.c factorial.c -o hello correct one is
all:main.c hello.c factorial.c -o hello
please Read more about it GNU MAKE

Resources