Shop OBEX P1 Docs P2 Docs Learn Events
Compile with PC version of GCC? — Parallax Forums

Compile with PC version of GCC?

RaymanRayman Posts: 14,826
edited 2012-08-22 22:06 in Propeller 1
I think I remember being able to compile Catalina C code using a PC target compiler
(don't remember if it was gcc or Visual Studio...)

This seemed to be a nice way to test and debug code on the PC before trying on Propeller...

I think Ross did this by using a lot of ifdefs...

Does this type of thing work with PropGCC too?
Is there an easy way to compile the code in Visual Studio with PC target?

Comments

  • jazzedjazzed Posts: 11,803
    edited 2012-08-21 11:14
    Rayman wrote: »
    I think I remember being able to compile Catalina C code using a PC target compiler
    (don't remember if it was gcc or Visual Studio...)

    This seemed to be a nice way to test and debug code on the PC before trying on Propeller...

    I think Ross did this by using a lot of ifdefs...

    Does this type of thing work with PropGCC too?
    Is there an easy way to compile the code in Visual Studio with PC target?
    Sure. Propeller GCC has built-in defines like __PROPELLER__, so this can be used:

    #ifdef __PROPELLER__
    // propeller specific code
    #else
    // other specific code
    #endif

    Only the compiler needs to change for use with tools.

    There are several IDE alternatives that you might like. Geany is one which I've used - it is very nice, small, and is easy to configure.

    From my brief investigations though, off-the-shelf Visual Studio doesn't seem to offer easy non-microsoft tool settings. There is a makefile build, but that probably uses nmake.

    Isn't there an SDK for Visual Studio for customizing things? I've seen some recent migration of Atmel or Microchip (?) tools to Visual Studio.
  • RaymanRayman Posts: 14,826
    edited 2012-08-21 13:26
    No, I'm asking about using the Visual Studio as an editor...

    I'm wondering if I can change the compiler and compile the exact same code so that it runs on a PC...

    For standard C or C++, it seems like it could be made to work.
    I think it's helpful for debugging...
  • ersmithersmith Posts: 6,096
    edited 2012-08-21 13:45
    Standard C code (using only things defined in the ANSI C89 or C99 standards) will compile on both the Propeller and PC without any changes -- although to get some C99 features you'll have to use GCC on the PC, since Visual C++ only supports a subset of the C99 standard.

    You will have to use #ifdefs to support any propeller specific code on the PC -- obviously it's pretty hard to start a COG on the PC, and toggling LEDs is done in a very different way :-).
  • RaymanRayman Posts: 14,826
    edited 2012-08-21 13:51
    Thanks. I think with Catalina, what I did was just change the compiler in Code::Blocks to GCC and many of the examples worked on the PC.
    I think this is very useful for figuring things out. I'll be glad if it works a little Visual Studio... Maybe I could use Code::Blocks for this too...
  • jazzedjazzed Posts: 11,803
    edited 2012-08-21 13:57
    Rayman wrote: »
    No, I'm asking about using the Visual Studio as an editor...

    I'm wondering if I can change the compiler and compile the exact same code so that it runs on a PC...

    For standard C or C++, it seems like it could be made to work.
    I think it's helpful for debugging...

    MinGW is the windows GCC package. So that's easy enough.
    Exactly the same code would be #ifdef'd as mentioned before.

    Is there a way to specify another compiler in vanilla Visual Studio?

    A batch file would work, but you need to use a %PREFIX% variable for the compiler and tools.
    The MinGW equivalent of "propeller-elf-gcc" is just "gcc" ...
    "avr-gcc", "avr32-gcc", "pic32-gcc" or "arm-gcc" could be used too ....

    Rayman wrote: »
    Maybe I could use Code::Blocks for this too...

    Ya, Code::Blocks is definitely much better suited to open source than Visual Studio.
  • RaymanRayman Posts: 14,826
    edited 2012-08-21 14:01
    Is MiniGW installed with SimpleIDE? If it were, could you then add an option to compile with regular gcc?
  • jazzedjazzed Posts: 11,803
    edited 2012-08-21 14:03
    Rayman wrote: »
    Is MiniGW installed with SimpleIDE? If it were, could you then add an option to compile with regular gcc?

    MinGW is not installed with SimpleIDE.

    I've definitely thought about adding support for it, but i have other things to do at the moment.
  • LeonLeon Posts: 7,620
    edited 2012-08-21 14:03
    jazzed wrote: »
    Isn't there an SDK for Visual Studio for customizing things? I've seen some recent migration of Atmel or Microchip (?) tools to Visual Studio.

    Atmel uses Visual Studio, Microchip uses NetBeans.
  • RaymanRayman Posts: 14,826
    edited 2012-08-21 16:53
    For once, I'm jealous of Atmel...
    I'd gladly pay $200 for a Visual Studio Propeller plugin...
  • RaymanRayman Posts: 14,826
    edited 2012-08-22 06:49
    Ok, I tried out the forumists/jazzed calc example in Visual Studio and I think it works with some minor changes...

    First, I had to disable use of precompiled headers in the project settings:
    Precompile.png


    Second, I had to change unistd.h to Windows.h like this:
    //#include <unistd.h>
    #include <Windows.h>
    

    Then, had to change sleep to Sleep like this:
    //sleep(1);
    Sleep(1000);      // give terminal time to start
    //RJA Changed from sleep and from 1 to 1000
    

    It then compiles and runs in a DOS window in full Debug mode with any breakpoints you want:
    WinCalc.png


    Since Visual Studio Express is a free download, this may offer people a way to test out and debug GCC code...
    850 x 297 - 22K
    789 x 517 - 37K
  • Heater.Heater. Posts: 21,230
    edited 2012-08-22 12:07
    Aghh! There it is again, GCC and Visual Studio. Cats and dogs sleeping together, the end times are near.
  • jazzedjazzed Posts: 11,803
    edited 2012-08-22 22:06
    Heater. wrote: »
    Cats and dogs sleeping together, the end times are near.
    LOL, could be.

    I see nothing wrong with using Visual Studio.
Sign In or Register to comment.