Issues running AVR-G++ under Cygwin with include paths

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

Hello all,

 

I'm having a bit of an issue with the -I flag of AVR-G++ under cygwin.

 

Some context first:

I moved away from the Arduino IDE and I'm currently using Visual Studio Code with my own makefiles to build my project. Now, my project makes use of two libraries (at this point: Adafruit-GFX and Adafruit-TFTLCD) and since I like having things well organized and easily build I created a specific makefile for those libraries that compiles the code, produces an object archive (with AVR-AR) and installs both the .a and the header files on a suitable location to be used by my main project's makefile.

 

Since I'm working with windows which doesn't have the standard include and lib folders (mistake, I know, given that toolchains only work best in unix/linux shells) I created a set of folders to install stuff:

  • c:\projects\arduino\usr\local\lib
  • c:\projects\arduino\usr\local\include

 

Also, I added to the .bashrc of the cygwin shell the following:

export ARDUINO_ROOT=/cygdrive/c/projects/arduino

with this I can perform a make install on the library's makefile to install everything on the right place (both the .a and all the header files).

TARGET			= ${ARDUINO_ROOT}/usr/local
ARDUINO_INCLUDE	        = ${ARDUINO_ROOT}/usr/local/include
EXECUTABLE		= libadafruit-TFTLCD.a

(.. simplified...)

install: $(EXECUTABLE)
        #Copy the .a
	@echo "   [CP] $(EXECUTABLE) 	-> $(TARGET)/lib/"
	@cp  $(EXECUTABLE) $(TARGET)/lib

        # Copy the header files, maintaing any sub-folders.
	@echo "   [CP] **/.h			-> $(TARGET)/include"
	@find . -name '*.h' -exec cp --parents \{\}  $(TARGET)/include  \;

 

This all works good. The issue is when I try to compile another lib that requires those header files the compiler refuses to accept the cygwin paths ("-I${ARDUINO_INCLUDE}" ) but works with regular windows paths ("-Ic:\projects\arduino\usr\local\include"):

 

 

$ make
avr-g++ -c -g -Os "-I/cygdrive/c/projects/arduino/usr/local/include"  Adafruit_TFTLCD.cpp -o Adafruit_TFTLCD.o

(include folders and library folders from the AVR toolchain ommited for clarity)

In file included from Adafruit_TFTLCD.cpp:18:0:
Adafruit_TFTLCD.h:15:26: fatal error: Adafruit_GFX.h: No such file or directory
compilation terminated.
make: *** [Makefile:29: Adafruit_TFTLCD.o] Error 1

 

Is there a way around this? I tried other options from the AVR compiler LIKE -I-, -isystem or -iquote but to no avail. I know that I could just use the windows styled paths but I would really like to have this decoupled from the "C:\" in order for the project to be more portable.

 

I'm using avr-g++.exe (GCC) 5.4.0 that came with the Arduino IDE.

 

Thanks for any help!

 

 

 

 

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

If it's Windows why don't you simply use AS7?

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

tggm wrote:
I'm using avr-g++.exe (GCC) 5.4.0 that came with the Arduino IDE.
FSF AVR GCC made how?

Reason :

http://distribute.atmel.no/tools/opensource/Atmel-AVR-GNU-Toolchain/3.6.1/build-avr8-gnu-toolchain-git.sh

...

# See if we need to change or set some defaults
case "${OSTYPE}" in
    cygwin)
        build_platform=i686-pc-cygwin
        host_platform=i686-pc-cygwin
        ;;
    msys)
        build_platform=i686-pc-mingw32
        host_platform=i686-pc-mingw32
        ;;
    darwin*)
        build_platform=x86_64-apple-${OSTYPE}.0.0
        host_platform=x86_64-apple-${OSTYPE}.0.0
        sed_tool=gsed
        ;;
esac

...

via Atmel - Tools Distribution

 


Cygwin

https://github.com/msys2/msys2/wiki/How-does-MSYS2-differ-from-Cygwin#runtime

via MSYS2 homepage

Prebuilt GNU toolchain for avr (FSF AVR GCC 5.3.0)

Prebuilt GNU Toolchains for Windows - Building your own GNU toolchains

 

"Dare to be naïve." - Buckminster Fuller

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

I had the feeling that cygwin was no longer used for gcc - it runs natively under windows. So cygwin shell stuff is of no use. The build system should provide the path ‘magic’. Have a look at the build output of the Arduino tools to see what it does.
Note I could be completely wrong as I’ve not had to solve these challenges under windows for some time.

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

Kartman wrote:
I had the feeling that cygwin was no longer used for gcc - it runs natively under windows.
Multiple choice for Windows.

https://gcc.gnu.org/install/specific.html#windows

 

"Dare to be naïve." - Buckminster Fuller

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

clawson wrote:

If it's Windows why don't you simply use AS7?

 

Hello, I was not aware of it. I just moved on from the Arduino IDE directly to GCC and Makefiles which I've always been familar with. But I will check it out! Thanks!

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

Hello, sorry for the late reply.

 

Thank you all for your suggestions. I have in fact downloaded the "official" AVR toolchain and managed to get things working.

 

Here's a rough summary of what I did:

  1. Created a base "root" folder for arduino development in windows (something like c:\arduino\) called it ARDUINO_ROOT 
  2. Created the base directories in that ARDUINO_ROOT emulating a unix structure. Things like $ARDUINO_ROOT\var $ARDUINO_ROOT\bin $ARDUINO_ROOT\usr\include etc....
  3. Extracted the official AVR tools to this root. The .zip is already organised in the standard directories (bin, usr, etc...).
  4. Copied the arduino core library from the Arduino IDE and crafted a Makefile to compile the static library (by duplicating the build process from the arduino IDE). Also, make install copies the arduino-core.a and the header files to my $ARDUINO_ROOT\usr\lib and $ARDUINO_ROOT\usr\include
  5. Now everytime I need a new library for my project (I'm using Adafruit-GFX, Adafruit-TFTLCD, TimeLib and Adafruit-CC3000) I do the following:
    1. Extract to a folder like $ARDUINO_ROOT\projects\some-library
    2. Add a Makefile to compile and link, using the my folder structure. Something like: -I$ARDUINO_ROOT\usr\include and -L$ARDUINO_ROOT\usr\lib (you get the idea)
    3. make install the end product (.a and .h)

 

This means that I'm completely independent of arduino-ide and its outdated tools. For me this is the "proper" way of working in C/C++. The libs and includes are all stored in one place in the system and your project can reference them in a standard way. 

 

It takes a little effort to write the makefiles but once you do the first one the other ones are just copy&paste. You have to be careful with the make install target as many of these libraries from the community contain example folders with a lot of garbage. Also, not all the header files should be copied to /usr/include.

 

The env variable ${ARDUINO_ROOT} allows me to abstract the windows paths. If I ever have to move shop to Linux things should work.

 

Thanks!

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

tggm wrote:
arduino-ide and its outdated tools
In what sense "outdated"?

 

I have Arduino 1.8.8 on this machine - that have GCC 5.4.0 which is a reasonably up to date version of avr-gcc in fact. Although GCC is now up to 8.x and in fact 9.x was just released this is simply because they have changed their release numbering strategy so instead of small increments like 5.4.0, 5.4.2, 5.4.5 etc they have made large jumps to 6.x then 7.x then 8.x and so on. But a 5.4.0 is not too far out of date. Maybe 18 months to 2 years?

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

For my basic usage probably not that much outdated. But it is irrelevant: My original problem (top of the thread) stopped occurring when I changed to avr-gcc.

 

At this point the only useful thing from arduino IDE is the serial monitor which is kinda smart by allowing the upload of the binary to the board while the serial connection is active. 

 

clawson wrote:

tggm wrote:
arduino-ide and its outdated tools
In what sense "outdated"?

 

I have Arduino 1.8.8 on this machine - that have GCC 5.4.0 which is a reasonably up to date version of avr-gcc in fact. Although GCC is now up to 8.x and in fact 9.x was just released this is simply because they have changed their release numbering strategy so instead of small increments like 5.4.0, 5.4.2, 5.4.5 etc they have made large jumps to 6.x then 7.x then 8.x and so on. But a 5.4.0 is not too far out of date. Maybe 18 months to 2 years?

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

I don't even use the Arduino software but still use their

IDE on a Mac to upload code to AVR's.  I'll make a new

directory in the Arduino/libraries/ folder and put all my

project files there.  Then a simple sketch includes the

main header file from the "library" and implements a

short setup() and loop() which call functions from the

library.  I just press the "Compile" button a lot and also

the "Upload" button to try the code on a chip.

 

--Mike