【发布时间】:2019-10-12 18:51:06
【问题描述】:
我正在尝试将 curl 和 libgcc 编译为静态库,因此我不必在我的程序中包含 dll 文件。当我通过命令提示符运行可执行文件时,我遇到了 libcurl.dll 未找到的问题。此外,还有另一个错误libgcc_s_dw2-1.dll 未找到。
当我将 dll 文件与可执行文件放在同一个文件夹中时它可以工作,但这不是我真正喜欢的。我已按照此处的建议将-DCURL_STATICLIB 放入CMAKE_CXX_FLAGS:
https://curl.haxx.se/docs/install.html
这是我的 CMakeLists.txt
project(ham)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_FLAGS -m32 -DCURL_STATICLIB)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -std=c++14 -LC:/curlx86 -lcurl")
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -static-libgcc -static-libstdc++ -lwsock32 -lws2_32 -lwinmm")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bstatic,--whole-archive -Wl,--no-whole-archive")
project(untitled3)
add_executable(ham Ham/ham.cpp)
target_link_libraries(ham "C:/curlx86/libcurl.dll.a")
我希望我的程序在不包含任何额外 dll 文件的情况下运行。我该怎么办?
Edit
当我使用
target_link_libraries(ham "C:/curlx86/libcurl.dll.a")
我收到这些错误。
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl。 a(easy.o):(.text+0x8f): 未定义引用libssh2_init'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(easy.o):(.text+0x16b): undefined reference tolibssh2_exit'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2 .o):(.text+0xcd): 未定义引用nghttp2_version'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2.o):(.text+0x2ca): undefined reference tonghttp2_submit_rst_stream'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2 .o):(.text+0x2dc): 未定义引用nghttp2_session_send'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2.o):(.text+0x31d): undefined reference tonghttp2_session_set_stream_user_data'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2 .o):(.text+0x3c0): 未定义引用nghttp2_pack_settings_payload'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2.o):(.text+0x4bd): undefined reference tonghttp2_session_resume_data'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2 .o):(.text+0x4fe): 未定义引用nghttp2_session_mem_recv'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2.o):(.text+0x51c): undefined reference tonghttp2_strerror'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2 .o):(.text+0x5c3): 未定义引用nghttp2_priority_spec_init'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2.o):(.text+0x614): undefined reference tonghttp2_submit_priority'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/curlx86/libcurl.a(http2 .o):(.text+0x621): 未定义对 `nghttp2_session_send' 的引用
【问题讨论】:
-
文件
.dll.a是动态库的导入文件,这不是静态库。你需要链接libcurl.a左右,没有.dll部分。 -
嗨,我试过了,我在上面编辑了我的结果。使用
libcurl.a时出现很多错误。我不得不从上面的文本中删除大部分错误,因为它们有很多。我猜我错过了ssl和其他类似的库。 -
是的,当与 static 库链接时,您需要手动 链接给定库所依赖的所有库。与 dynamic 库不同,static 库不存储所需库的列表。
标签: c++ curl cmake mingw libcurl