6 Replies Latest reply on Mar 20, 2015 9:33 AM by mhahn

    Arduino Edison Sketch C99

    Phil12d3

      Hello,

       

      I'm trying to port some code i've written using the Arduino IDE downloaded from the Intel website. When previously writting C code on the Arduino I have been able to add -std=c99 into the platform.txt file on compiler.c.flags and it compiles ok. I've done this in the i686 folder but I get the below error message:

       

      Arduino: 1.6.0 (Windows 8), Board: "Intel® Edison"

      Build options changed, rebuilding all

      C:\Users\philip.cartwright\Downloads\IntelArduino-1.6.0-Windows\arduino-1.6.0+Intel\hardware\intel\i686\cores\arduino\fast_gpio_pci.c: In function 'fastGpioPciReadAttr':

      C:\Users\philip.cartwright\Downloads\IntelArduino-1.6.0-Windows\arduino-1.6.0+Intel\hardware\intel\i686\cores\arduino\fast_gpio_pci.c:87:12: error: 'PATH_MAX' undeclared (first use in this function)

        char path[PATH_MAX];

                  ^

      C:\Users\philip.cartwright\Downloads\IntelArduino-1.6.0-Windows\arduino-1.6.0+Intel\hardware\intel\i686\cores\arduino\fast_gpio_pci.c:87:12: note: each undeclared identifier is reported only once for each function it appears in

      C:\Users\philip.cartwright\Downloads\IntelArduino-1.6.0-Windows\arduino-1.6.0+Intel\hardware\intel\i686\cores\arduino\fast_gpio_pci.c: In function 'fastGpioPciFindResourceById':

      C:\Users\philip.cartwright\Downloads\IntelArduino-1.6.0-Windows\arduino-1.6.0+Intel\hardware\intel\i686\cores\arduino\fast_gpio_pci.c:111:11: error: 'PATH_MAX' undeclared (first use in this function)

        char buf[PATH_MAX];

                 ^

      C:\Users\philip.cartwright\Downloads\IntelArduino-1.6.0-Windows\arduino-1.6.0+Intel\hardware\intel\i686\cores\arduino\fast_gpio_pci.c: In function 'fastGpioPciInit':

      C:\Users\philip.cartwright\Downloads\IntelArduino-1.6.0-Windows\arduino-1.6.0+Intel\hardware\intel\i686\cores\arduino\fast_gpio_pci.c:158:17: error: 'PATH_MAX' undeclared (first use in this function)

        char resource0[PATH_MAX];

                       ^

      C:\Users\philip.cartwright\Downloads\IntelArduino-1.6.0-Windows\arduino-1.6.0+Intel\hardware\intel\i686\cores\arduino\fast_gpio_pci.c:159:14: error: storage size of 'st' isn't known

        struct stat st;

                    ^

      C:\Users\philip.cartwright\Downloads\IntelArduino-1.6.0-Windows\arduino-1.6.0+Intel\hardware\intel\i686\cores\arduino\fast_gpio_pci.c:182:4: error: 'MAP_FILE' undeclared (first use in this function)

          MAP_FILE | MAP_SHARED, fd, 0);

          ^

      Error compiling.

        This report would have more information with

        "Show verbose output during compilation"

        enabled in File > Preferences.

       

      The code I'm compiling works fine on the Arduino IDE against the UNO board. Does anyone have an idea why I might be getting these errors when selecting the Intel Edison board?

       

      I've attached my code, although I get the same error when creating a new sketch and doing a simple 'for loop' like this:

       

      int x=0;

      for(int y=0;y<10;y++) x++;

       

      Any help much appreciated.

        • 1. Re: Arduino Edison Sketch C99
          mhahn

          IMHO Arduino code is C++ rather than C code. Hence setting "c99" flag seems a bit odd to me. What features are you missing with the default compiler settings?

          • 2. Re: Arduino Edison Sketch C99
            Phil12d3

            The Arduino IDE supports C and C++.

             

            From the Arduino website:

            The Arduino software is also open-source. The source code for the Java environment is released under the GPL and the C/C++ microcontroller libraries are under the LGPL.

             

            At the moment I'm not using any Arduino library or special features, it's just standard C - not sure if that's what you mean by features.

             

            Out of the box, the Arduino IDE doesn't allow you to do things like this:

             

            for(int i=0;i <10; i++) ...

             

            It complains about the variable 'i' been defined in the for...loop, since it's not part of the default standard. I'm porting code written in C99, so I want to be able to easily move my code across. As I said before, I've done this without any problems at all with the Arduino IDE from the Arduino website and compiled and uploaded successfully to an Arduino Uno. The issue is that I don't seem to be able to do this with the i686 (Edison) hardware libraries etc. When the Edison board is selected I get the errors shown above.

             

            The Edison libraries are also written in C and C++, so I think the C/C++ choice is really down to personal preference, but I'm wondering if I need to change other things or something else to get this working?

            • 3. Re: Arduino Edison Sketch C99
              mhahn

              well, I might also be wrong. But I wonder how the compiler should find out whether to compile for C or for C++ if both is supported?

              • 4. Re: Arduino Edison Sketch C99
                Phil12d3

                I believe the extension of the file indicates which to use. If you save a file as foo.c it will compile with GCC and if you save with .CPP it will use G++. I think it's a case of using which ever is there. In the cores folder under intel (\arduino-1.6.0+Intel\hardware\intel\i686\cores\arduino) there is a mix of C and CPP. I don't think it matters as long as the correct compiler compiles it?

                 

                The platform.txt file in the hardware folder under AVR or intel have compiler paths and flags for both C and C++.

                 

                Also, if you look at the errors I posted, the files in the Edison folders are C files, not C++.

                 

                So I don't think it's that C isn't supported. But I admit that by adding the -std=c99 flag I may have disrupted a few things and that is really my question, if anyone has any experience with these libraries or have any ideas about this?

                • 5. Re: Arduino Edison Sketch C99
                  Phil12d3

                  It just occured to me that another related question would be am I approaching this wrong in the first place, would using the native features in Eclipse be a better way of doing this?

                  • 6. Re: Arduino Edison Sketch C99
                    mhahn

                    natively it's not an issue at all to use c99 / c++11 ... The gcc coming with Edison should support both