LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 09-09-2007, 06:30 PM   #1
ankit4u1
Member
 
Registered: Apr 2006
Distribution: Red Hat, Fedora
Posts: 97

Rep: Reputation: 15
Help in Makefile


Hi,

I am trying to create a project of client and server communication using sockets. I have four programs and a Makefile
1) header.h (macros and function prototypes)
2) main.c: where command line arguments are handled and server and client functions are called
3) server.c: server function is defined here
4) client.c: client program is defined here
5) Makefile

Here is my Makefile

Code:
server1: server.o main.o
	gcc server.o main.o -o server1

client1: client.o main.o
	gcc client.o main.o -o client1 

main.o: main.c header.h
	gcc -c -Wall main.c

client.o: client.c header.h
	gcc -c -Wall client.c

server.o: server.c header.h
	gcc -c -Wall server.c

clean:
	rm -f *.o
When I do "make", I get the following output:

Code:
gcc -c -Wall server.c
gcc server.o main.o -o server1
main.o:main.c:(.text+0x49d): undefined reference to "_client"
collect2: ld returned 1 exit status
make: *** [server1] Error 1
I don't understand what could be the problem. I tried to google, but without much luck.

If I don't use Makefile, i.e. use main() in both server and client programs and compile them separately and run those programs, everything goes fine....The problem occurs when I use Makefile

Can any one please help me ? Thanks in advance.
 
Old 09-09-2007, 07:12 PM   #2
ankit4u1
Member
 
Registered: Apr 2006
Distribution: Red Hat, Fedora
Posts: 97

Original Poster
Rep: Reputation: 15
Lightbulb yupppieeee

Well, coun't wait trying stuff...I solved the problem in this way:

I split main.c in two parts main1.c and main2.c

and then when i do make server1 or make client1, it runs fine !!! time to rock !!

I feel that this is one of the solutions only !! I would like to know if the above problem can be solved by only one "main" file !!!

Once again, I will format the question:

Is is possible to create a Makefile with multiple targets with only one "main" file ? If yes, then, by doing only "make", what will happen ?

1) Will it give me errors?
2) Will it create all the targets ?


Or is it mandatory that I need to do "make target" and not "make" to build the target ?

Thanks in advance !!
 
  


Reply

Tags
makefile, reference, undefined



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 issue: "Makefile.src: File not found" m3rkury Linux - Software 1 02-22-2007 10:15 PM
automake, makefile, makefile.in and makefile.am Fond_of_Opensource Linux - Newbie 1 09-12-2006 08:35 PM
what is the meaning of Makefile,Makefile.am,Makefile.in cynthia_thomas Linux - General 3 12-08-2005 05:00 AM
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 03:57 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 12:23 PM

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

All times are GMT -5. The time now is 11:12 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