LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-04-2008, 11:03 AM   #1
lrios
Member
 
Registered: Mar 2008
Location: Arg
Distribution: Cent0S
Posts: 48

Rep: Reputation: 15
error in Makefile


Hi everyone
Iam doing something wrong with my Makefile. I have 2 executables server and client, 1 header network.h and network.c. When i write $make all it doesn't find network.c the but it works when i write $ gcc -o server server.c network.c -lpthread.
What are i doing wrong in TARGETS ?? HEADER can i deleted ??

Code:
CFLAGS = -Wall -g
CC = gcc
TARGETS = server client network.o
LDLIBS = -lpthread 
HEADER = network.h


all:	$(TARGETS) 
	$(CC) -o $@ $^ $(LDLIBS) $(CFLAGS)
	@echo Server && Client OK	


server:	server.c
	$(CC) -o $@ $^ $(LDLIBS) $(CFLAGS)


client:	client.c
	$(CC) -o $@ $^ $(LDLIBS) $(CFLAGS)


network.o:	network.c network.h
	gcc -c network.c


clean:
	@echo Cleaning 
	rm -f $(TARGETS) *.o *.~ *.out *.c~
	@echo OK.

.PHONY:	clean
 
Old 04-04-2008, 12:51 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
What is the exact error message you're getting?
 
Old 04-04-2008, 07:44 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,771

Rep: Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070Reputation: 2070
Code:
all:	$(TARGETS) 
	$(CC) -o $@ $^ $(LDLIBS) $(CFLAGS)
	@echo Server && Client OK
$@ expands to the name of the target, so the second line causes gcc to make an executable called "all". I don't think you need this line at all.

&& is a shell operator, so the last line echo's "Server", then tries to execute a command called Client, you should write
Code:
@echo "Server && Client OK" 
   or
@echo Server and Client OK
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Makefile error. Amrita@3086 Solaris / OpenSolaris 1 09-23-2007 02:20 AM
Makefile error nesta Programming 2 02-07-2007 05:53 AM
makefile error pantera Programming 3 05-21-2005 08:05 AM
makefile error durden2.0 Programming 2 01-25-2004 04:45 PM
makefile error puckney Linux - Newbie 3 04-25-2002 09:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration