Skip to main content
Topic: Compile pirate-loader with MinGW (Read 2817 times) previous topic - next topic

Compile pirate-loader with MinGW

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, ...);
Got a question? Please ask in the forum for the fastest answers.

Re: Compile pirate-loader with MinGW

Reply #1
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

Re: Compile pirate-loader with MinGW

Reply #2
[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.

Re: Compile pirate-loader with MinGW

Reply #3
@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.
Got a question? Please ask in the forum for the fastest answers.

Re: Compile pirate-loader with MinGW

Reply #4
[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

Re: Compile pirate-loader with MinGW

Reply #5
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__)