Author Topic: Compiler Optimizations  (Read 4097 times)

Offline mikejp56

  • Multiple posting newcomer
  • *
  • Posts: 11
Compiler Optimizations
« on: April 19, 2024, 06:34:52 pm »
Hi All,
I am using CB with Linux Mint 20. I get the following warning "/usr/lib/avr/include/util/delay.h:112:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
 # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
I have set the compiler optimizations for 1, 2, and 3, but I still get the same warning.
I am pretty new to CodeBlocks and AVR programming.
Please point me in the correct direction.
Thanks for reading.
Regards,
mikejp56

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1634
Re: Compiler Optimizations
« Reply #1 on: April 19, 2024, 07:45:58 pm »

Offline mikejp56

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Compiler Optimizations
« Reply #2 on: April 19, 2024, 08:27:22 pm »
Hi Miguel,
Here is the text of the build log. From what I have read it appears to have something to do with compiler optimizations.
Thanks for your time.

-------------- Build: Debug in Binary_Clock_Mods (compiler: GNU GCC Compiler for AVR)---------------

avr-gcc -Wall -mmcu=atmega328p -DF_CPU=16000000UL -g  -c main.c -o obj/Debug/main.o
avr-gcc  -o bin/Debug/Binary_Clock_Mods.elf obj/Debug/fuse.o obj/Debug/main.o  -mmcu=atmega328p -Wl,-Map=bin/Debug/Binary_Clock_Mods.map,--cref 
In file included from main.c:18:0:
/usr/lib/avr/include/util/delay.h:112:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
 # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
   ^
Output file is bin/Debug/Binary_Clock_Mods.elf with size 31.85 KB
Running project post-build steps
avr-objdump -h -S bin/Debug/Binary_Clock_Mods.elf > bin/Debug/Binary_Clock_Mods.lss
avr-objcopy -R .eeprom -R .fuse -R .lock -R .signature -O ihex bin/Debug/Binary_Clock_Mods.elf bin/Debug/Binary_Clock_Mods.hex
avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex bin/Debug/Binary_Clock_Mods.elf bin/Debug/Binary_Clock_Mods.eep
avr-objcopy --no-change-warnings -j .lock --change-section-lma .lock=0 -O ihex bin/Debug/Binary_Clock_Mods.elf bin/Debug/Binary_Clock_Mods.lock
avr-objcopy --no-change-warnings -j .signature --change-section-lma .signature=0 -O ihex bin/Debug/Binary_Clock_Mods.elf bin/Debug/Binary_Clock_Mods.sig
avr-objcopy --no-change-warnings -j .fuse --change-section-lma .fuse=0 -O ihex bin/Debug/Binary_Clock_Mods.elf bin/Debug/Binary_Clock_Mods.fuse
srec_cat bin/Debug/Binary_Clock_Mods.fuse -Intel -crop 0x00 0x01 -offset  0x00 -O bin/Debug/Binary_Clock_Mods.lfs -Intel
srec_cat bin/Debug/Binary_Clock_Mods.fuse -Intel -crop 0x01 0x02 -offset -0x01 -O bin/Debug/Binary_Clock_Mods.hfs -Intel
/bin/sh: 1: srec_cat: not found
Process terminated with status 127 (0 minute(s), 0 second(s))
0 error(s), 1 warning(s) (0 minute(s), 0 second(s))
 

-------------- Build file: Debug in Binary_Clock_Mods (compiler: GNU GCC Compiler for AVR)---------------

Nothing to be done (all items are up-to-date).

Online stahta01

  • Lives here!
  • ****
  • Posts: 7680
    • My Best Post
Re: Compiler Optimizations
« Reply #3 on: April 19, 2024, 08:46:25 pm »
https://www.avrfreaks.net/s/topic/a5C3l000000UUx7EAG/t132775

Over a decade old post; where user found problem in Code::Blocks global compiler settings.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline mikejp56

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Compiler Optimizations
« Reply #4 on: April 19, 2024, 08:56:08 pm »
Hi stahta01,
I have set the compiler optimizations to 1, 2, and 3, but this issue still occurs. There was another post about using the compiler optimizations to solve an issue that I saw.
I just tried the same code with MPLABX with the same results, and the same warning message, so it doesn't appear to be a CB issue. I am just reaching out for help from people with way more experience than me.
Regards,
mikejp56

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1634
Re: Compiler Optimizations
« Reply #5 on: April 19, 2024, 11:20:36 pm »
Were optimizations enabled in the log you posted?

Online stahta01

  • Lives here!
  • ****
  • Posts: 7680
    • My Best Post
Re: Compiler Optimizations
« Reply #6 on: April 19, 2024, 11:32:15 pm »
Hi stahta01,
I have set the compiler optimizations to 1, 2, and 3, but this issue still occurs. There was another post about using the compiler optimizations to solve an issue that I saw.
I just tried the same code with MPLABX with the same results, and the same warning message, so it doesn't appear to be a CB issue. I am just reaching out for help from people with way more experience than me.
Regards,
mikejp56

See https://www.nongnu.org/avr-libc/user-manual/group__util__delay.html

Did you define F_CPU as required?
Edit: You did as "-DF_CPU=16000000UL"

And, you need to find an website that supports your AVR compiler; because some or most of your question is off topic (OT) for this website.

Edit: Did you rebuild the project trying at least 3 different optimizations? Edit3: I suggest "O1" "O2" and "Og".
If yes, what optimizations did you try?
Post at least one build log of those opt. builds?

Edit2: Try building the project without the debug mode (-g) being used. Sometimes debug mode make things easier and sometimes harder.

Tim S.
« Last Edit: April 19, 2024, 11:40:56 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline mikejp56

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Compiler Optimizations
« Reply #7 on: April 20, 2024, 01:17:25 am »
Hi stahta01,
I did try to build using the optimizations 01, 02, and 03 with no success.
I obviously fat fingered the F_CPU define. I will retry that again without the D! This code is for a crystal controlled clock running at 16MHz. It keeps correct time without the F_CPU define.
I realized afterward that it is a compiler issue when I compiled the same exact c code in MPLABX (which I really do not like) and got the same warning from the compiler.
Regards,
mikejp56