Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-09-2007, 06:30 PM   #1
Registered: Apr 2006
Distribution: Red Hat, Fedora
Posts: 97

Rep: Reputation: 15
Help in Makefile


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

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

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

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
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 !!


makefile, reference, undefined

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 issue: "Makefile.src: File not found" m3rkury Linux - Software 1 02-22-2007 10:15 PM
automake, makefile, and Fond_of_Opensource Linux - Newbie 1 09-12-2006 08:35 PM
what is the meaning of Makefile,, 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 without calling ./configure ? chris78 Programming 2 05-02-2004 12:23 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:38 AM.

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