1

我正在尝试在 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 进行构建,但不明白如何执行此操作。如果我尝试“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

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

4

2 回答 2

2

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

于 2013-03-20T18:03:15.703 回答
-1

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

于 2013-03-20T12:33:58.777 回答