LinuxQuestions.org
Visit Jeremy's Blog.
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 12-11-2018, 03:21 PM   #1
coltson
Member
 
Registered: Oct 2010
Posts: 149

Rep: Reputation: 3
make does not applies CFLAGS settings


Hello, I currently have this makefile:

Code:
CC=g++
CFLAGS=-I -O2 -fexpensive-optimizations --fast-math -march=native
DEPS = PerformanceManager.h InputHandler.h Vec3f.h Image.h FileManager.h GeometricObjects.h TGAManager.h Plane.h Sphere.h Triangle.h Scene.h TextManager.h RayTracer.hh
OBJ = PerformanceManager.o InputHandler.o Image.o FileManager.o TGAManager.o Plane.o Scene.o TextManager.o RayTracer.o main.o

%.o: %.cpp $(DEPS)
	$(CC) -c -o $@ $< $(CFLAGS)

RayTracer: $(OBJ)
	$(CC) -lpthread -o $@ $^ $(CFLAGS)

clean:
	rm -rf *.o
and while it does work, it does not apply the compiler's optimizations on the code. And I know that due to time my program is taking to execute (around 5x slower). I remove both $(CFLAGS) and replaced it by the
Code:
-O2 -fexpensive-optimizations --fast-math -march=native
that are defined in the "CFLAGS=". So what I might be doing wrong?

Thanks for the help.
 
Old 12-11-2018, 05:18 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Restore the original state, and quote the ouput of this:
Code:
make clean
make -n RayTracer
 
Old 12-15-2018, 02:08 PM   #3
coltson
Member
 
Registered: Oct 2010
Posts: 149

Original Poster
Rep: Reputation: 3
Quote:
Originally Posted by NevemTeve View Post
Restore the original state, and quote the ouput of this:
Code:
make clean
make -n RayTracer
Here it goes
Quote:
make clean
rm -rf *.o
leopoldo@leopoldo-desktop:~/asmfrtSource$ make -n RayTracer
g++ -c -o PerformanceManager.o PerformanceManager.cpp
g++ -c -o InputHandler.o InputHandler.cpp
g++ -c -o Image.o Image.cpp
g++ -c -o FileManager.o FileManager.cpp
g++ -c -o TGAManager.o TGAManager.cpp
g++ -c -o Plane.o Plane.cpp
g++ -c -o Scene.o Scene.cpp
g++ -c -o TextManager.o TextManager.cpp
g++ -c -o RayTracer.o RayTracer.cpp
g++ -c -o main.o main.cpp
g++ -lpthread -o RayTracer PerformanceManager.o InputHandler.o Image.o FileManager.o TGAManager.o Plane.o Scene.o TextManager.o RayTracer.o main.o -I -O2 -fexpensive-optimizations --fast-math -march=native
 
Old 12-15-2018, 03:09 PM   #4
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
I'm not sure, but do you get a different result if you change CFLAGS to CXXFLAGS (or CPPFLAGS) in all three locations of your Makefile?
 
1 members found this post helpful.
Old 12-15-2018, 03:52 PM   #5
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by coltson View Post
%.o: %.cpp $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
A %.o: %.cpp rule must NOT have anything behind it, so the *(DEPS) will have to be removed;
all further dependencies have to be in the recipe (the 2nd line).

Anyway, the standard flag variables for C++ compilations are CXXFLAGS or CPPFLAGS

Last edited by ehartman; 12-15-2018 at 03:53 PM.
 
1 members found this post helpful.
Old 12-16-2018, 03:50 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
@coltson: please find out the difference between [quote] and [code] tags.

One or more of your DEPS doesn't exist that's why make cannot use your rule; instead it goes with some built-in rule like this:
Code:
%.o: %.cpp
        $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ -c $<
To avoid this behaviour, you can add this line into your Makefile:
Code:
.SUFFIXES:

Last edited by NevemTeve; 12-16-2018 at 03:53 AM.
 
1 members found this post helpful.
Old 12-19-2018, 03:43 AM   #7
coltson
Member
 
Registered: Oct 2010
Posts: 149

Original Poster
Rep: Reputation: 3
Quote:
I'm not sure, but do you get a different result if you change CFLAGS to CXXFLAGS (or CPPFLAGS) in all three locations of your Makefile?
Thanks, it did work.

Quote:
A %.o: %.cpp rule must NOT have anything behind it, so the *(DEPS) will have to be removed;
all further dependencies have to be in the recipe (the 2nd line).

Anyway, the standard flag variables for C++ compilations are CXXFLAGS or CPPFLAGS
Could you expand on this? I mean, is there a reason as to why that? I was following this tutorial: http://www.cs.colby.edu/maxwell/cour...als/maketutor/ Anyway, the second line would be this
Quote:
$(CC) -c -o $@ $< $(CXXFLAGS)
? In case of yes, shall I put it behind the (CXXFLAGS) ?

Quote:
One or more of your DEPS doesn't exist that's why make cannot use your rule; instead it goes with some built-in rule like this:
Code:

%.o: %.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $@ -c $<

To avoid this behaviour, you can add this line into your Makefile:
Code:

.SUFFIXES:
Do you mean that one of my files in the DEPS line does not exist?
 
Old 12-19-2018, 03:53 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> > One or more of your DEPS doesn't exist that's why make cannot use your rule

> Do you mean that one of my files in the DEPS line does not exist?

Yes. (RayTracer.hh might be a suspect.)

Off: please find out the difference between [quote] and [code] tags.

Last edited by NevemTeve; 12-19-2018 at 06:28 AM.
 
1 members found this post helpful.
Old 01-08-2019, 04:31 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
You don't need to re-write all the rules for normal compilation, make has loads of rules built in. You are just getting in the way.
You don't even *need* a make file to use make rules.

Create a file called 'blah.cpp' in a directory with no make file and type 'make blah' and you will see.
'make -pns' will show you all the rules.
 
1 members found this post helpful.
  


Reply

Tags
cflags, make



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
LXer: Microsoft judge applies eBay's patent rule LXer Syndicated Linux News 0 06-20-2006 11:12 PM
LXer: Ibm Applies Open Source Lessons to Commercial Apps LXer Syndicated Linux News 0 06-02-2006 05:03 PM
LXer: Th-unis Applies Linux Operating Platform to New Products LXer Syndicated Linux News 0 05-03-2006 09:21 PM
wait() and signal() applies on which process ...? indian Programming 5 12-01-2004 02:43 PM
Storing CFLAGS and other compiler settings in Slackware r_jensen11 Slackware 2 08-12-2004 01:41 PM

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

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