在Windows下编译Mongoose的hello.c

我想在Windows下从Mongoose编译包含的hello.c示例。 我正在使用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来做这个构build,但不知道如何做到这一点。 如果我尝试“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. 

编辑我也试图编译像用户手册 ,在Windows应该转换为“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 

有没有人有什么build议需要采取什么步骤来编译在Windows下的Mongoose hello.c示例?

我发现上面我第三次尝试的问题是“_snprintf”已被depreached,并被Visual Studio 10使用的C版本中的“_snprintf_s”替换。因此,我用_snprintf_s替换了“_snprintf”的一个出现, 。

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