Dangerous Prototypes

Dangerous Prototypes => Bus Pirate Support => Pirate PIC programmer => Topic started by: ian on June 15, 2010, 05:48:28 pm

Title: Compile pirate-loader with MinGW
Post by: ian on June 15, 2010, 05:48:28 pm
I've been playing with mingw for a updated PIC programmer, cross platform, console app. I started by compiling the pirate-loader.c for the v4 bootloader - it's a simple single file with all the components needed (HEX parsing, serial coms, etc). In the source it looks like Piotr made POSIX-compatible read, write, close, and open, functions for windows. When I compile with MinGW I get an error that write, read, and open are already defined in io.h (I guess it already has posix substitutes?). I commented out the version in io.h and it compiles and works fine (I tried removing the version in the app, but it didn't work right, opening serial port error). This doesn't seem like an ideal solution. Does anyone have any suggestions? Here's the prototypes for the functions:

From pirate-loader.c:
   int write(int fd, const void* buf, int len)
   int read(int fd, void* buf, int len)
   int open(const char* path, unsigned long flags)

From MinGW io.h:
//_CRTIMP int __cdecl __MINGW_NOTHROW write (int, const void*, unsigned int);
//_CRTIMP int __cdecl __MINGW_NOTHROW read (int, void*, unsigned int);
//_CRTIMP int __cdecl __MINGW_NOTHROW open (const char*, int, ...);
Title: Re: Compile pirate-loader with MinGW
Post by: Sjaak on June 15, 2010, 09:01:29 pm
Looks like open needs some more arguments in mingw (the flags section is a bit different I guess)

Can you also fix the upper/lowercase error? :D
Title: Re: Compile pirate-loader with MinGW
Post by: rsdio on June 16, 2010, 02:29:44 am
[quote author="ian"]In the source it looks like Piotr made POSIX-compatible read, write, close, and open, functions for windows. When I compile with MinGW I get an error that write, read, and open are already defined in io.h[/quote]Would it be possible to rename all of the MinGW functions as mwrite, mread, mopen so that they do not conflict with the POSIX versions?  I guess that would be a massive edit.
Title: Re: Compile pirate-loader with MinGW
Post by: ian on June 16, 2010, 11:17:16 am
@Sjaak - I think there is a version or patch that fixes that. I can't find it, but I recall Piotr or robots addressing this issue at some point.

@rsdio - since I'm only using it for this program I just commented it out, but renaming is probably a better idea. Or I can add a define, or maybe undefine the old one? I'm having fun with this, so I'm documenting it for a post. I'll try a few different approaches.

I'm also going to split this. This is related to the v4 bootloader, but not directly. I should have started a new topic.
Title: Re: Compile pirate-loader with MinGW
Post by: Sjaak on June 16, 2010, 11:28:49 am
[quote author="ian"]
@Sjaak - I think there is a version or patch that fixes that. I can't find it, but I recall Piotr or robots addressing this issue at some point.

[/quote]

the topic is here: http://dangerousprototypes.com/forum/in ... opic=437.0 (http://dangerousprototypes.com/forum/index.php?topic=437.0)
Title: Re: Compile pirate-loader with MinGW
Post by: robots on June 16, 2010, 12:04:43 pm
There is "ifdef" that checks for WIN32, and if that is defined it uses internal read/open/write functions. As MINGW has these functions, you just need to change the ifdef to ommit these functions when "defined(__MINGW32__)".

I think something like this should work:
Code: [Select]
#if defined(WIN32) && !defined(__MINGW32__)