LinuxQuestions.org
Help answer threads with 0 replies.
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 07-07-2005, 09:35 PM   #1
nelnel
Member
 
Registered: May 2005
Posts: 47

Rep: Reputation: 15
Makefile Problem


Hello, i want to create a simple Makefile to compile a group of cpp file. So i search the information of Makefile from internet. I created a simple Makefile, but don't work as my expectation.

Makefile:
CC = g++
CFLAGS = -L/opt/oracle/product/9.2.0/lib

TARGET = test

OBJS = abc.o strncat.cpp

all: $(TARGET) abc.o

clean:
rm -f $(TARGET) *.o *~ core

$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LIBS)

abc.o: abc.cpp abc.h


I expect the compilation process is:

g++ -c -o abc.o abc.cpp
g++ -L/opt/oracle/product/9.2.0/lib -c -o strncat.o strncat.cpp
g++ -L/opt/oracle/product/9.2.0/lib -o test abc.o strncat.o


but the real output is:

-L/opt/oracle/product/9.2.0/lib

how can i change the Makefile content to call the FLAGS during the compilation of the Obect file?

thx
 
Old 07-07-2005, 09:37 PM   #2
nelnel
Member
 
Registered: May 2005
Posts: 47

Original Poster
Rep: Reputation: 15
Sorry i post the wrong code

my expectation is:

g++ -L/opt/oracle/product/9.2.0/lib -c -o abc.o abc.cpp
g++ -L/opt/oracle/product/9.2.0/lib -o test abc.o strncat.cpp


but the real one is

g++ -c -o abc.o abc.cpp
g++ -L/opt/oracle/product/9.2.0/lib -o test abc.o strncat.cpp


thx
 
Old 07-07-2005, 11:55 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Errrh ... sorry, wrong reponse


Cheers,
Tink
 
Old 07-08-2005, 12:53 AM   #4
sind
Member
 
Registered: Jun 2005
Posts: 75

Rep: Reputation: 15
Hi nelnel,

Looks like you've given make the dependencies for abc.o, but not how to build it. If you don't tell make what command to use, it will use a default one that is chosen according to the source file's extension.

I think changing this:

Code:
abc.o: abc.cpp abc.h
to this:

Code:
abc.o: abc.cpp abc.h
        $(CC) $(CFLAGS) -c -o $@ abc.cpp
will give you the result that you expect.

~sind
 
Old 07-08-2005, 02:31 AM   #5
nelnel
Member
 
Registered: May 2005
Posts: 47

Original Poster
Rep: Reputation: 15
THAT's work!!!

thx v.much~~~
 
  


Reply



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
how to get (makefile -f makefile )output into the textview widget in Pygtk sailu_mvn Programming 3 02-28-2005 03:57 AM
Another problem with Makefile lucs Slackware 3 02-14-2005 05:06 PM
Problem with Makefile lucs Slackware 7 02-11-2005 09:18 AM
generate Makefile from Makefile.in without calling ./configure ? chris78 Programming 2 05-02-2004 12:23 PM
Makefile separator problem Ownasaurus Linux - Software 5 09-07-2003 01:07 PM

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

All times are GMT -5. The time now is 01:22 AM.

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