【发布时间】:2023-03-31 16:20:01
【问题描述】:
您好,我想使用 DevCpp 和 MinGW64 编译器编译一个 windows .EXE 应用程序。我要编译的应用程序非常简单,需要 CURL 库。我正在使用 Windows 8 64 位,Orwell Dev-C++ V 5.3.0.4。我已经从官方网站(Win64 - MinGW64 devel v.28.1)下载了 CURL 库。我已将所有包含、bin 和 lib 文件复制到 MinGW64 文件夹,但程序无法编译,因为它得到以下链接器错误:
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0x37): undefined reference to `__imp_curl_global_init'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0x74): undefined reference to `__imp_curl_formadd'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0xb1): undefined reference to `__imp_curl_formadd'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0xba): undefined reference to `__imp_curl_easy_init'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0xd5): undefined reference to `__imp_curl_slist_append'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0x100): undefined reference to `__imp_curl_easy_setopt'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0x157): undefined reference to `__imp_curl_easy_setopt'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0x173): undefined reference to `__imp_curl_easy_setopt'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0x183): undefined reference to `__imp_curl_easy_perform'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0x19a): undefined reference to `__imp_curl_easy_strerror'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0x1cc): undefined reference to `__imp_curl_easy_cleanup'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0x1dc): undefined reference to `__imp_curl_formfree'
[Linker error] C:\Users\Panos\AppData\Local\Temp\ccSFo7Pn.o:upload.cpp:(.text+0x1ec): undefined reference to `__imp_curl_slist_free_all'
collect2: ld returned 1 exit status
我设法编译程序的唯一方法是使用编译器的 -DCURL_STATICLIB -c -h -Icurl\include 选项,但我得到的只是一个无法在我的操作系统中运行的 16 位应用程序!
我要编译的代码是这个 CURL 示例: http://curl.haxx.se/libcurl/c/postit2.html
我花了很多时间在互联网上搜索和阅读指南以使我的程序编译但没有任何运气。请帮助我并告诉我我做错了什么!
谢谢!
【问题讨论】:
-
这些问题不在编译过程中,而是在链接过程中。您需要添加库的路径。您需要谷歌如何告诉链接器在哪里可以找到 lib 文件。这是特定于环境的(在您的情况下,Orwell Dev-C++)
-
我已经通过工具>编译器选项>目录添加了文件的路径
-
再次,您需要链接器选项,而不是编译器。通过将目录添加到编译器选项,您已经告诉 Orwell Dev-C++ 在哪里可以找到头文件,而不是编译器库。这就是编译成功的原因(在链接问题之前)。查找有关“链接器选项”的信息
-
没有链接器选项选项,但我可以为链接器设置命令行选项。我如何告诉它包含库?
-
取决于环境,正如我已经说过的。我不知道如何为 Orwell Dev-C++ 做到这一点。对于 gcc,您可以像这样将路径添加到库中:
-L/full/or/relative/path/to/the/library -llabrary_name(大写-L前缀用于路径,小写-l前缀用于库)