在Windows下编译Mongoose的hello.c

时间:2013-03-20 11:48:43

标签: c windows mongoose-web-server

我正在尝试从Windows下的hello.c编译包含的Mongoose示例。我正在使用Microsoft Visual命令提示符,我已将mongoose.c和mongoose.h复制到与hello.c示例相同的目录中。

当我写“cl hello.c”时,我得到以下输出/错误:

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

示例中包含Makefile,我尝试使用Makefile进行构建,但不了解如何执行此操作。如果我尝试“nmake hello.exe”。我得到以下输出/错误:

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.

修改 我也尝试过按照user manual中的指示进行编译,它应该转换为“cl hello.c mongoose.c -o hello.exe”,但后来我收到以下错误信息:

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

有没有人建议在Windows下编译Mongoose的hello.c示例需要采取哪些步骤?

2 个答案:

答案 0 :(得分:2)

我发现上面第三次尝试的问题是“_snprintf”已被删除并被Visual Studio 10使用的C版本中的“_snprintf_s”取代。因此,我用_snprintf_s替换了“_snprintf”的出现。它起作用了。

答案 1 :(得分:-1)

看起来你没有为mongoose指定与库(DLL,无论它实际是什么)的链接。这就是为什么你有未解决的外部因素。它需要知道在哪里找到它们,以便可执行文件可以在运行时找到它们(如果它是动态链接的),或者在.exe中包含代码(如果静态地完成)。