Separate Compilation in Mint

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
dihaletosis
Level 1
Level 1
Posts: 5
Joined: Wed Feb 10, 2016 2:40 am

Separate Compilation in Mint

Post by dihaletosis »

Hello, I have just in the past couple weeks started using Linux and am very new to it. I am a Computer Science student and we are learning about separate compilation. I have all of my prototypes in header files and all of my definitions in .c files.

This is my Makefile:

Code: Select all

CC = gcc 
CFLAGS = -o quad
LDFLAGS = -lm

OBJS = main.o solve_linear.o solve_quad.o solve_real.o solve_complex.open

quad: $(OBJS)
	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) 
	
clean:
	rm $(OBJS) quad

When I type 'make' in terminal, this is what I get: 
cc     Makefile.c   -o Makefile
Makefile.c:1:1: warning: data definition has no type or storage class [enabled by default]
 CC = gcc 
 ^
Makefile.c:1:6: error: ‘gcc’ undeclared here (not in a function)
 CC = gcc 
      ^
Makefile.c:2:1: error: expected ‘,’ or ‘;’ before ‘CFLAGS’
 CFLAGS = -o quad
 ^
make: *** No targets specified and no makefile found.  Stop.
Any help would be appreciated
tolkien
Level 2
Level 2
Posts: 72
Joined: Sat Nov 14, 2015 9:50 am

Re: Separate Compilation in Mint

Post by tolkien »

Make sure the name of the makefile is "Makefile" or "makefile".
And add tabs before "recipe" lines, not spaces. In other words:
quad: $(OBJS)
<TAB>$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS)
clean:
<TAB>rm $(OBJS) quad
Also, make sure that all your files are in one folder.
dihaletosis
Level 1
Level 1
Posts: 5
Joined: Wed Feb 10, 2016 2:40 am

Re: Separate Compilation in Mint

Post by dihaletosis »

tolkien wrote:Make sure the name of the makefile is "Makefile" or "makefile".
And add tabs before "recipe" lines, not spaces. In other words:
quad: $(OBJS)
<TAB>$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS)
clean:
<TAB>rm $(OBJS) quad
Also, make sure that all your files are in one folder.
I did and I'm still recieving the same errors. My makefile is name "Makefile.c" do I need to
remove the .c?
User avatar
WharfRat
Level 21
Level 21
Posts: 13909
Joined: Thu Apr 07, 2011 8:15 pm

Re: Separate Compilation in Mint

Post by WharfRat »

I'm always flabbergasted with Makefiles
My makefile is name "Makefile.c" do I need to remove the .c?
Yes, it should be just Makefile
ImageImage
dihaletosis
Level 1
Level 1
Posts: 5
Joined: Wed Feb 10, 2016 2:40 am

Re: Separate Compilation in Mint

Post by dihaletosis »

WharfRat wrote:I'm always flabbergasted with Makefiles
My makefile is name "Makefile.c" do I need to remove the .c?
Yes, it should be just Makefile
That is what I did yesterday and it just changed it to a text file. I just recently installed Clang and this time when I took off the .c, it worked. Could Clang be the reason it worked this time?
User avatar
WharfRat
Level 21
Level 21
Posts: 13909
Joined: Thu Apr 07, 2011 8:15 pm

Re: Separate Compilation in Mint

Post by WharfRat »

It could be functioning properly if you followed tolkien's instructions pertaining to tabs.

Another option is to use a '\' line continuation e.g.
quad: $(OBJS) \
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS)

As far as installing clang goes, you got me :?
ImageImage
Post Reply

Return to “Newbie Questions”