Search code examples
cwindowsmongoose-web-server

Compiling Mongoose's hello.c under Windows


I am trying to compile the included hello.c example from Mongoose under Windows. I am using the Microsoft Visual command prompt and I have copied the mongoose.c and mongoose.h to the same directory as the hello.c example.

When I write "cl hello.c" I get the following output/error:

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

hello.c
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:hello.exe
hello.obj
hello.obj : error LNK2019: unresolved external symbol _mg_stop referenced in function _main
hello.obj : error LNK2019: unresolved external symbol _mg_start referenced in function _main
hello.obj : error LNK2019: unresolved external symbol _mg_printf referenced in function _begin_request_handler
hello.obj : error LNK2019: unresolved external symbol _snprintf referenced in function _begin_request_handler
hello.obj : error LNK2019: unresolved external symbol _mg_get_request_info referenced in function _begin_request_handler

hello.exe : fatal error LNK1120: 5 unresolved externals

There is a Makefile included with the examples and I have tried to use the Makefile to do the build, but do not understand how to do this. If i try "nmake hello.exe". I get the following output/error:

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl -W -Wall -I.. -pthread -g hello.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line error D8004 : '/W' requires an argument
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.EXE"' : return code '0x2'
Stop.

EDIT I have also tried the to compile like instructed in the user manual which on windows should translate to "cl hello.c mongoose.c -o hello.exe" but then I get the following error message:

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
hello.c
mongoose.c
Generating Code...
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:hello.exe
/out:hello.exe
hello.obj
mongoose.obj
hello.obj : error LNK2019: unresolved external symbol _snprintf referenced in function _begin_request_handler
hello.exe : fatal error LNK1120: 1 unresolved externals

Does anyone have suggestions on what steps needs to be taken in order to compile the hello.c example for Mongoose under Windows?


Solution

  • I found out that the issue with my third try above was that "_snprintf" has been depreached and replaced by "_snprintf_s" in the C version used by Visual Studio 10. I thus replaced the one occurence of "_snprintf" with _snprintf_s and it worked.