Rohit214 / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

Mongoose fails to compile with MinGW on Windows #35

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Check out SVN trunk
2. Run mingw32-make mingw in checkout directory

What is the expected output? What do you see instead?
Make output:
D:\Checkout\Mongoose>mingw32-make mingw
gcc -W -Wall -mthreads -Wl,--subsystem,console -DNDEBUG -Os -DHAVE_STDINT
mongoose.c -lws2_32 -shared -Wl,--out-implib=mongoose.lib -o _mongoose.dll
mongoose.c:111: error: conflicting types for 'pid_t'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/sys/types.h:75:
error:
 previous declaration of 'pid_t' was here
mongoose.c: In function `cry':
mongoose.c:397: warning: implicit declaration of function `_lock_file'
mongoose.c:413: warning: implicit declaration of function `_unlock_file'
mongoose.c: In function `mg_stat':
mongoose.c:822: error: storage size of 'st' isn't known
mongoose.c:827: warning: implicit declaration of function `_wstat64'
mongoose.c:822: warning: unused variable `st'
mongoose.c: In function `set_ports_option':
mongoose.c:3166: warning: comparison between signed and unsigned
mingw32-make: *** [mingw] Error 1

What version of the product are you using? On what operating system?
- OS WinXP SP3
- MinGW 3.4.5
- Mongoose v2.5 and SVN trunk

Please provide any additional information below.
- Tried with cmd.exe and MSYS, (expectedly) both report the same error

Original issue reported on code.google.com by arnold.k...@gmail.com on 28 Apr 2009 at 11:29

GoogleCodeExporter commented 9 years ago
I think this is fixed, please reopen if it is not.

Original comment by valenok on 28 Jun 2009 at 10:49

GoogleCodeExporter commented 9 years ago
When building with my own make using MinGW, mongoose.c, mongoose.h I get this 
same 
error. pid_t is defined twice.

Original comment by doug.rei...@gmail.com on 20 Jul 2009 at 10:35

GoogleCodeExporter commented 9 years ago
Patch is welcome :-)

Original comment by valenok on 21 Jul 2009 at 8:31

GoogleCodeExporter commented 9 years ago
I'm not sure how correct this is, but I did get this to build.

I got this working by not using pid_t directly.  I replaced pid_t with 
'procesID' and 
then conditionally typedef'd processID in windows vs unix

// For Windows and MinGW
typedef HANDLE processID;
// for Unix
typedef pid_t processID;

spawnProcess would return a processID and kill would take a processID. sendCGI 
would 
also use processID instead of pid_t

I only tested this under minGW though, and only compiled so far. But seems like 
it 
should avoid the conflict.

Original comment by doug.rei...@gmail.com on 21 Jul 2009 at 1:56

GoogleCodeExporter commented 9 years ago
It looks like the pid_t issue has been partially addressed in 
"$Id: mongoose.c 327 2009-05-05 14:11:04Z valenok $"
but using Eclipse-3.4.2/CDT-5.0.2/MinGW-3.15.2 I also had to define 
"_NO_OLDNAMES" to
avoid the error (as used in sys/types.h).  This macro definition doesn't appear 
to be
in the Makefile.

Original comment by guy.lanc...@gmail.com on 27 Jul 2009 at 7:36

GoogleCodeExporter commented 9 years ago
@guy.lancaster: I've tried to use the options -D_NO_OLDNAMES in the makefile, 
but it
gives these errors:

C:\mongoose-2.8\mongoose>mingw32-make mingw
gcc -W -Wall -mthreads -Wl,--subsystem,console -DNDEBUG -Os -DHAVE_STDINT -D_NO_
OLDNAMES mongoose.c -lws2_32 \
                -shared -Wl,--out-implib=mongoose.lib -o _mongoose.dll
mongoose.c: In function 'mg_stat':
mongoose.c:1087: warning: integer constant is too large for 'long' type
mongoose.c: In function 'send_file':
mongoose.c:2751: error: 'off_t' undeclared (first use in this function)
mongoose.c:2751: error: (Each undeclared identifier is reported only once
mongoose.c:2751: error: for each function it appears in.)
mongoose.c:2751: error: expected ')' before 'r1'
mongoose.c: In function 'send_cgi':
mongoose.c:3286: warning: implicit declaration of function 'fdopen'
mongoose.c:3286: warning: assignment makes pointer from integer without a cast
mongoose.c:3287: warning: assignment makes pointer from integer without a cast
mingw32-make: *** [mingw] Error 1

Original comment by marcu...@gmail.com on 28 Jul 2009 at 11:08

GoogleCodeExporter commented 9 years ago
I thought that defining _NO_OLDNAMES had resolved the problems so I reverted my 
other
changes last night but this morning it's back to the original problems.  

Is anyone able to build it under MinGW? If not, did it ever build?  Knowing the
history will help to understand what may be needed.  BTW, I haven't tried to 
link it
yet so there may be more issues.

I have to return to the client-side of my project for a while so there's time to
speak up if there are any suggestions before I get back to this.

Thanks.

-- Guy

Original comment by guy.lanc...@gmail.com on 28 Jul 2009 at 5:33

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I've understood how to fix this!

I've searched on some forums/mailing lists (and in particular this
http://gcc.gnu.org/ml/gcc-bugs/2004-03/msg01944.html ), and it seems that when 
you
try to use "gcc -v example.c" it shows you all the paths in which it will 
search for
libraries and so on.
So I've just read that when I gave the command 'gcc -v example.c' (this is the 
code)

#include <sys/types.h>
#include <stdio.h>

typedef int pid_t;

int main()
{

    pid_t pid = 5;
    off_t p = 6;
    printf("Pid %d %d\n", pid, p);
}

It showed me some lines, and one (or more) of these were:
ignoring nonexisting directory mingw/include

So I've renamed the mingw directory; it was C:\MinGW4-4. I've renamed it to
'c:\mingw'. Then I've fixed the environment variables (PATH, since it pointed to
mingw4-4) and tried to compile the example (see here for the log
http://pastebin.com/f451ce8ca ) and then mongoose. 

C:\mongoose-2.8\mongoose>mingw32-make mingw
gcc -W -Wall -mthreads -Wl,--subsystem,console -DNDEBUG -Os -DHAVE_STDINT mongoo
se.c -lws2_32 \
                -shared -Wl,--out-implib=mongoose.lib -o _mongoose.dll
mongoose.c: In function 'mg_stat':
mongoose.c:1088: warning: integer constant is too large for 'long' type
Creating library file: mongoose.lib
gcc -W -Wall -mthreads -Wl,--subsystem,console -DNDEBUG -Os -DHAVE_STDINT mongoo
se.c main.c -lws2_32 -ladvapi32 -o mongoose.exe
mongoose.c: In function 'mg_stat':
mongoose.c:1088: warning: integer constant is too large for 'long' type

Only some warnings without using -D_NO_OLDNAMES!! :)

PS: Please note that now it says "ignoring duplicate ..." while it said 
"ignoring
nonexisting .."!

Now it works very well :)

Bye!

Original comment by marcu...@gmail.com on 29 Jul 2009 at 8:29

GoogleCodeExporter commented 9 years ago
@marcusbu

I'm not sure I understand your 'fix'.  Moving my MinGW directory or installing 
it off 
root does not sound right to me at all.

The hello example you mention does compile if pid_t is an int.  But doesn't if 
you 
use HANDLE as demonstrated below. So is this a fix or did you just get lucky?

#include <sys/types.h>
#include <stdio.h>
#include <windows.h>

typedef HANDLE pid_t;

int main()
{

       pid_t pid = 5;
       off_t p = 6;
       printf("Pid %d %d\n", pid, p);
}

Original comment by doug.rei...@gmail.com on 29 Jul 2009 at 8:52

GoogleCodeExporter commented 9 years ago
I've compiled mongoose without problems, as you can see. The only warning I got 
was:
"integer constant is too large for 'long' type"

It however means that "typedef HANDLE pid_t" works fine.

I think it can be a solution, since gcc checked for the 'mingw/include' where 
are
defined all the headers (sys/types.h and so on) but it couldn't find them. 
Have you tried to rename your installation path?
It should be "c:\Mingw\" and not "C:\program files\mingw" and similar.
I don't know exactly why this happens (maybe the --prefix=/mingw doesn't work on
windows?), but as you can see also here (
http://web.archive.org/web/20041026163202/http://www63.tok2.com/home/bitwalk/dow
nload.html
), it's a well established fact that you must use C:\mingw.

Bye!

Original comment by marcu...@gmail.com on 30 Jul 2009 at 6:56

GoogleCodeExporter commented 9 years ago
Does not work for me.  I moved my MinGW to c:/mingw neither builds when using 
HANDLE.

And I haven't had any issues using the MinGW in my Qt directory with anything 
else so 
I'm not sure why the c:/mingw works for you.

You could be right its a MinGW problem, but I can't build mongoose even if 
c:/mingw 
is the install i use.

BTW HANDLE for my install is defined as a void* not an integer.

Incidentally it does find the headers, that's part of the problem.  pid_t is 
defined 
twice.

Thanks for the help.

Original comment by doug.rei...@gmail.com on 30 Jul 2009 at 1:44

GoogleCodeExporter commented 9 years ago
I wonder *why* pid_t is defined twice? in mongoose.c, pid_t is defined under the
_WIN32 conditional, which I though is not visible under mingw.

Original comment by valenok on 30 Jul 2009 at 2:12

GoogleCodeExporter commented 9 years ago
Yes the win32 conditional is enabled.  (In netbeans I can see the conditional 
code that 
is active.)

Also, I noticed marcusbu used gcc 4.4.  I just spent an hour setting that up. 
Still 
fails.

Original comment by doug.rei...@gmail.com on 30 Jul 2009 at 2:51

GoogleCodeExporter commented 9 years ago
@doug: 
you're right. I don't know why I had mongoose.c modified (I had typedef HANDLE
processID; and all the pid_t were processID). What a really boring error!

@valenok: 
when you use mingw, these macros are automatically defined:
http://pastebin.com/m762bb463

as you can see the second line says "_WIN32 1"

I've also tried to use -U_WIN32 in the makefile, but I get these errors:
http://pastebin.com/m5a1dd57b

Bye!

Original comment by marcu...@gmail.com on 30 Jul 2009 at 2:58