make uses wrong compiler.

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've been banging my head on this for some time and my monitor is becoming quite bloody...

 

make uses avr-gcc with all the right options in the "~/good/" directory, and it uses "g++" without any additional options in the "~/false/" directory, but the files are the same (no output from diff).

Both compile attempst are in the same terminal window (environment etc) and both seem to use /usr/bin/make

Does anybody have any clue in which direction to proceed to solve this?

paul@dualcore ~/false $ diff makefile ../good/makefile
paul@dualcore ~/false $ diff main.cpp ../good/main.cpp
paul@dualcore ~/false $ diff main.h ../good/main.h
paul@dualcore ~/false $ make all
g++    -c -o main.o main.cpp
In file included from main.cpp:14:0:
main.h:11:20: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
                    ^
compilation terminated.
make: *** [main.o] Error 1
paul@dualcore ~/false $ cd ../good/
paul@dualcore ~/good $ make all
avr-gcc -x c++ -c -mmcu=atmega328p -g -O3 -fshort-enums -fno-gcse -Wall -mcall-prologues -lm -I/home/paul/projects/avr/lib	 -include main.h main.cpp

paul@dualcore ~/good $ make --version
GNU Make 3.81

paul@dualcore ~/good $ g++ --version
g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2

paul@dualcore ~/good $ avr-gcc --version
avr-gcc (GCC) 4.8.2

 

 

 

 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CC=

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there a file called GNUmakefile is one of these directories?

 

Show us the makefile, it could contain a name dependant bug.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SOLVED.

 

It's a pretty simple self written makefile which I use for al my projects and the last thing I suspected was the makefile itself.

There is no CC= or GNUmakefile and hardly any automatic stuff.

 

Because the file "header.h" did not exist in " ~/false/ " my own rule for making a %.o could not be resolved and make defaulted to one of it's own rules.

 

 

Small excerpt from my make file:

MYDEPEND= main.h header.h makefile

%.o: %.cpp %.h $(MYDEPEND)
	$(COMPILE) $<

 

Whole makefile (and a bit more):

paul@dualcore ~/false $ make all --debug
Reading makefiles...
Updating goal targets....
 File `all' does not exist.
   File `main.hex' does not exist.
     File `main.elf' does not exist.
       File `main.o' does not exist.
      Must remake target `main.o'.
g++    -c -o main.o main.cpp
In file included from main.cpp:14:0:
main.h:11:20: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
                    ^
compilation terminated.
make: *** [main.o] Error 1
paul@dualcore ~/false $ cat makefile
#================================== Definition of internal variables for make.
#MCU	= atmega328
MCU	= atmega328p
#MCU	= atmega8

# main.h must be included automagically to get the main.h from the
# project directory instead of the main.h from the dir it is included from.
COMPILE	= avr-gcc -x c++ -c $(CFLAGS) -include main.h
LINK	= avr-gcc $(LINKFLAGS) $(LINKFILES)
AS	= avr-gcc -x assembler-with-cpp
RM	= rm -f

COMMON	= -mmcu=$(MCU)
MYLIB	= /home/paul/projects/avr/lib
MYDEPEND= main.h header.h makefile

# Use optimisation level -O1 for debugging with "Debug" lib.
CFLAGS  = $(COMMON) -g -O3 -fshort-enums -fno-gcse -Wall -mcall-prologues -lm
CFLAGS += -I$(MYLIB)	# Include directory for my own libs.

ASMFLAGS= $(COMMON) -Wa, -gstabs
LINKFLAGS= $(COMMON) -g -Wl,-Map=$(<:.o=.map),--cref

#============================================================= Files to link.
LINKFILES = main.o
#LINKFILES+= delay.o
LINKFILES+= lcd-pcd8544.o
#LINKFILES+= mumarnet.o
LINKFILES+= mumarnet_rf.o
LINKFILES+= timer.o
LINKFILES+= threadnetwork.o
LINKFILES+= keyboard.o
#LINKFILES+= twi.o

#======================================= Rules for compiling to object files.
# a general rules for compiling c or cpp files.
%.o: %.cpp %.h $(MYDEPEND)
	$(COMPILE) $<

%.o: %.c %.h $(MYDEPEND)
	$(COMPILE) $<

# Tell avr-gcc where to find the source code for all my own "libraries":
# They are all compiled separately because they take their (pin) configuation
# from the "main.h" file of the project they are compiled for.
delay.o: $(MYLIB)/delay/delay.cpp $(MYLIB)/delay.h $(MYDEPEND)
	$(COMPILE) $(MYLIB)/delay/delay.cpp

lcd.o: $(MYLIB)/lcd/lcd.cpp $(MYLIB)/lcd.h $(MYDEPEND)
	$(COMPILE) $(MYLIB)/lcd/lcd.cpp

lcd-pcd8544.o: $(MYLIB)/lcd-pcd8544/lcd-pcd8544.cpp $(MYLIB)/lcd-pcd8544.h $(MYDEPEND)
	$(COMPILE) $(MYLIB)/lcd-pcd8544/lcd-pcd8544.cpp

mumarnet.o: $(MYLIB)/mumarnet/mumarnet.cpp $(MYLIB)/mumarnet.h $(MYDEPEND)
	$(COMPILE) $(MYLIB)/mumarnet/mumarnet.cpp

mumarnet_rf.o: $(MYLIB)/mumarnet/mumarnet_rf.cpp $(MYLIB)/mumarnet_rf.h $(MYDEPEND)
	$(COMPILE) $(MYLIB)/mumarnet/mumarnet_rf.cpp

timer.o: $(MYLIB)/timer/timer.cpp $(MYLIB)/timer.h $(MYDEPEND)
	$(COMPILE) $(MYLIB)/timer/timer.cpp

keyboard.o: $(MYLIB)/keyboard/keyboard.cpp $(MYLIB)/keyboard.h $(MYDEPEND)
	$(COMPILE) $(MYLIB)/keyboard/keyboard.cpp

#================================================================== Targets.
main.elf: $(LINKFILES)
	$(LINK) -o main.elf
	avr-objdump -h -S main.elf > main.lst
	avr-size main.elf
#	avr-gcc $(OBJ) $(LIB) $(LDFLAGS) $(LINKFILES) -o main.elf

main.hex: main.elf
	avr-objcopy -j .text -j .data -j .bss -O ihex main.elf main.hex

all: main.hex

#avrdude -q = quiet,  -e = chip erase
program: main.hex
	avrdude -p $(MCU) -c usbasp -qe -U flash:w:main.hex:i

# m328p Internal 8MHz RC, EEsave, No wdt, brown. Engbedded, 20140627.
fuses:
	avrdude -p atmega328p -c usbasp -qeB40 -U lfuse:w:0xe2:m -U hfuse:w:0xd1:m

reset:
	avrdude -p $(MCU) -c usbasp -B300 -Ulfuse:v:0x00:m

clean:
	$(RM) *.rom *.eep *.obj *.hex
	$(RM) *.o *.s *.elf *.lst *.map
	$(RM) *.bak *.Bak *.c_sym *.avd *.aio
	$(RM) *.~h *.~c *.~bp *.~cp *.tds
	$(RM) *.h~ *.c~ *~

For anyone curious:

 

For each of my projects all the pin definitions are in the file main.h of that project.

For each "library" the makefile takes the source of that "library" and compiles it whith the right pin definitions for the current project.

In this way I can reuse my libraries and still use different hardware I/O pins for connected hardware.

Also, any update of library code is automatically updated when a project is recompiled.

This works pretty good for me. For example: "mumarnet" uses interrupt controlled uart / RS485 combination, and "mumarnet_rf" uses (hardware or software) SPI with an nRF24L01 module. These are interchangable with changing just a few lines of code and the sw SPI variant can be connected to arbitrary pins on all cpu's I've tried.

 

Some time ago I was tired of maintaining the different header files for each project and I removed them from the project source files and dumped them all in header.h.

Modern pc's are so fast that the extra overhead is negligable for avr projects. But I did overlook the problem above when recompiling one of my old projects...

 

I want to publish most of my projects, but I'm having some problems with updating my site / html, (and with makefiles).

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Sun. Apr 12, 2015 - 02:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry for the brevity of my post but I wasn't suggesting you might be afflicted by the use of CC= but that you could maybe use it yourself to guarantee the compiler being used (I guess you want to dictate the C++ compiler not the C compiler in fact). 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did some reading on:

https://www.gnu.org/software/mak...

which hinted that changing my "COMPILE = " to: "CC = " would overrule one of the auto generated rules from make and therefore would have made it easier to debug my makefile, but this does not work. If I delete the "header.h" file make still tries to use "g++".

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What bearing does a .h file have to do with make? Or are you talking about .d/dep files? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are no .d/dep or other files. "~/false/" has only 3 files. main.cpp, main.h and makefile.

My best guess is that because of this part of the makefile:

MYDEPEND= main.h header.h makefile

%.o: %.cpp %h $(MYDEPEND)
      $*CC) %<

the file header.h has to exist to satisfy the rule to buil an object file from a .cpp file. If header.h file does not exist the rule is false and make goes on trying something else, and misses avr-gcc and all it's options.

 

 


paul@dualcore ~/false $ make clean
rm -f *.rom *.eep *.obj *.hex
rm -f *.o *.s *.elf *.lst *.map
rm -f *.bak *.Bak *.c_sym *.avd *.aio
rm -f *.~h *.~c *.~bp *.~cp *.tds
rm -f *.h~ *.c~ *~
paul@dualcore ~/false $ make all
g++    -c -o main.o main.cpp
In file included from main.cpp:14:0:
main.h:11:20: fatal error: avr/io.h: No such file or directory
 #include <avr/io.h>
                    ^
compilation terminated.
make: *** [main.o] Error 1
paul@dualcore ~/false $ ls
main.cpp  main.h  makefile
paul@dualcore ~/false $ touch header.h
paul@dualcore ~/false $ make all
avr-gcc -x c++ -c -mmcu=atmega328p -g -O3 -fshort-enums -fno-gcse -Wall -mcall-prologues -lm -I/home/paul/projects/avr/lib	 -include 
...

This test confirms it. Just creating "header.h" (with touch) makes make happy enough to use avr-gcc.

 

P.s:

I'm not very good with make, but I started using my own make files back when avr-gcc still had those split make files with (if I remember well) 30kB to 40kB of text.

My own make file is (almost) simple enough for me to understand what's happening :-).

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com