Makefile:6: *** missing separator. Stop - makefile

HEADERS = schedule.h
default: papcmp
program.o: schedule.c $(HEADERS)
gcc -g -lnuma -lm -pthread schedule.c -lutil -lz -o schedule.o
program: schedule.o
gcc schedule.o -o papcmp
clean:
-rm -f schedule.o
-rm -f papcmp
-rm -f *.log dump.gz
This is the first time i'm trying to create a make file. and it looks like there is an error. Could you help me with it? The line that is in bold has the error according to the output.

Make is very picky about spaces vs. tabs. Command lines absolutely must be indented with a single tab, and not spaces. You may need to adjust your editor to generate tab characters.

Make TAB to make it work!
Example working code with TAB symbol as orange line
Original code with spaces highlighted in Notepad++:

Related

How to create makefile for Linux for the next command - gcc -shared -home/ time.c /libperi.a -o time.so

How to create a makefile for Linux for the next command?
gcc -shared -home/ time.c /libperi.a -o time.so
First, pick a name. This command appears to build time.so, so that's a good name.
The makefile is just a text file. Write it like this:
time.so:
gcc -shared -home/ time.c /libperi.a -o time.so
That whitespace before the gcc is a TAB, not spaces.
Once you have that working, you can read the manual and learn more about Make, which will allow you to write more powerful rules.

error in using tab in makefile how to fix it

when I try to do make for the makefile it shows me (makefile error missing separator. stop)
my make file is
PROGS = $(patsubst %.c,%,$(SRCS))
all: $(PROGS)
%: %.c
arm-linux-gnueabihf-gcc --static $< -o $#
clean:
rm -f $(PROGS)
I try to use the following command but I could not solve my problem
cat -e -t -v Makefile
SRCS^I=^I$(wildcard^I*.c)^I$
PROGS^I=^I$(patsubst^I%.c,%,$(SRCS))$
all:^I$(PROGS)^I$
%:^I%.c^I$
arm-linux-gnueabihf-gcc^I--static^I$<^I-o^I$#^I$
clean:^I$
rm^I-f^I$(PROGS)^I$ ```
Crazy. You have TAB characters in all the places you don't need them, and you don't have TAB characters in any of the (two) places you must have them. I don't know how you managed that.
In your makefile above the places you MUST have TAB chars are the recipe lines. In other words, your makefile should look like this from cat -e -t -v Makefile:
SRCS = $(wildcard *.c)$
PROGS = $(patsubst %.c,%,$(SRCS))$
all: $(PROGS)$
%: %.c$
^Iarm-linux-gnueabihf-gcc --static $< -o $#$
clean:$
^Irm -f $(PROGS)$
As for configuring your text editor, there are a ton of text editors out there, even on Ubuntu, and we have no idea which one you are using.
I recommend you use a programmer's editor, which has a special mode that understands makefile syntax.

Bash script to compile a program and run it works in the terminal but not as a bash script

I have a simple series of commands that need to be executed as root:
#/bin/bash
g++ -O3 -ffast-math -msse4 -c *.c *.cpp -lGL -lglfw -m64 -Wno-undef -fPIC
rm main.o
g++ -O3 -ffast-math -msse4 -shared -o GeklminRender.so *.o -m64 -Wno-undef -lGL -lglfw
#In your root window:
cp /home/gek/Programming/GeklminRender-master/THEVERSION/GeklminRender.so /usr/lib/GeklminRender.so
g++ -O3 -ffast-math -msse4 -lGL -lglfw -m64 -Wno-undef -Wall -L. -l:GeklminRender.so -o prog2.bin main.cpp
#./prog2.bin
When I run these commands individually by copy-pasting them into LXTerminal, it runs completely fine.
When I run the SH file it prints out this series of errors (Note: It's being executed in a root terminal by typing in ./Compiler_Call.sh)
’; did you mean ‘-fPIC’?
rm: cannot remove 'main.o'$'\r': No such file or directory
/usr/bin/ld: cannot find -lglfw
collect2: error: ld returned 1 exit status
cp: cannot stat '/home/gek/Programming/GeklminRender-master/THEVERSION/GeklminRender.so': No such file or directory
: No such file or directory
Now, maybe I'm just missing something (I'm a life-long windows user, where batch scripts run always 100% of the time whether or not you typed it into the terminal or ran it in a .bat file) but I don't understand why things I type into the terminal don't work from a .sh file. My shell is indeed bash!
The fact that 'main.o'$'\r' appears in your output is very telling. It suggests that there is an extra carriage return character in your script at the end of the line rm main.o. That character is invisible to you, but not to bash, so even though it looks to you as if you wrote a command to remove the file main.o, bash sees a command to remove the file main.o\r (where \r stands for the invisible carriage return character), and of course there is no file by that name.
If there are carriage returns at the end of your other lines, that would probably also explain the other error messages you're seeing. For example, ’; did you mean ‘-fPIC’? probably comes from GCC trying to display a message something like this
invalid option ‘-fPIC\r’; did you mean ‘-fPIC’?
but because GCC actually moves the display cursor back to the beginning of the line when the \r comes up, the second half of the message overwrites the first half. And /usr/bin/ld: cannot find -lglfw is probably actually /usr/bin/ld: cannot find -lglfw\r, where the carriage return at the end is invisible.
This would happen if you wrote this script file in a text editor that uses Windows-style line endings. To make it run in bash, you'll have to convert the line endings to Unix-style, which means removing all the carriage return characters. How you do this depends on what tools you have available.
I FOUND THE ANSWER!!!
I was using Microsoft DOS line endings

Makefile:2: *** missing separator. Stop [duplicate]

This question already has answers here:
Make error: missing separator
(14 answers)
Closed 8 years ago.
I have two .cpp files namely decryptor.cpp and prod-ent.cpp.
I have created a Makefile to for the compilation of both the files in Linux platform.
all: decryptor.cpp prod-ent.cpp
g++ prod-ent.cpp -o prod-ent -g
g++ decryptor.cpp -o decryptor -g -lcryptopp
clean:
rm prod-ent
rm decryptor
Whenever I'm trying to execute the Makefile its showing me the following error:
Makefile:2: * missing separator. Stop.
I am new to create makefiles and cannot figure out my fault. Please help me in correcting the code.
Thanks in advance !!
You need a real tab instead of space in front of g++ and rm commands. If still fails
then your editor is inserting spaces instead, even if you're hitting the tab key on your keyboard. You need to configure your editor to insert hard tabs (09 in ASCII) instead.
Like
all: decryptor.cpp prod-ent.cpp
*****g++ prod-ent.cpp -o prod-ent -g
*****g++ decryptor.cpp -o decryptor -g -lcryptopp
clean:
*****rm prod-ent
*****rm decryptor
Instead ***** replace TAB.
You can check your side by command
cat -e -t -v makefile
It's show line starting by ^I if TAB is given to that line and it end the line by $.
Also you can do by ;
all: decryptor.cpp prod-ent.cpp ; g++ prod-ent.cpp -o prod-ent -g ; g++ decryptor.cpp -o decryptor -g -lcryptopp
clean: ; rm prod-ent ; rm decryptor

Error in make command makefile:18: *** missing separator. Stop [duplicate]

This question already has answers here:
Make error: missing separator
(14 answers)
Closed 3 years ago.
For the following make file copied below, I am getting the missing separator error. Nothing seems to be wrong with the tabspace.
OBJS = driver.o snapshot.o
SHOBJS = malloc.o mymemory.o
CC = g++
DEBUG = -g
CFLAGS = -Wall -c $(DEBUG)
LFLAGS = -Wall $(DEBUG)
Snapshot: $(OBJS)
$(CC) $(LFLAGS) $(OBJS) -o Snapshot
driver.o: snapshot.h driver.cpp
$(CC) $(CFLAGS) driver.cpp
snapshot.o: mymemory.h snapshot.h snapshot.cpp
$(CC) $(CFLAGS) snapshot.cpp
libmymemory.so: $(SHOBJS)
gcc -shared -o libmymemory.so malloc.o mymemory.o
malloc.o: malloc.c
gcc -fPIC -g -c -Wall malloc.c
mymemory.o: mymemory.cpp
gcc -fPIC -g -c -Wall mymemory.cpp
clean:
\rm *.o *~ Snapshot
Line 18 is gcc -fPIC -g -c -Wall mymemory.cpp. Make is expecting a separator, typically :. It's not detecting this line as a command. You mistyped the intendation: you have spaces where you should have a tab.
Good editors highlight makefile lines that begin with spaces but look like they should begin with a tab instead.
I have seen this error message when a file used spaces instead of tab character(s) at the beginning of a line in the makefile.
This mostly happens if you copy paste the code from internet. Remove all the spaces from the indented lines by using the delete key. And then press the tab key, only once per line.
Save it and try running the file again. It should work now. This worked for me.
I don't know if it's accurate or an artifact of pasting the code online, but the indentation for the last two commands in the file looks like it's smaller than the commands above it. Double-check your spacing carefully.

Resources