【问题标题】:error LNK2019: unresolved external symbol referenced when compile HTTPD错误 LNK2019:编译 HTTPD 时引用了未解析的外部符号
【发布时间】:2021-06-12 01:32:45
【问题描述】:

我正在编译 HTTPD 2.4.48 以及 Lua、Zlib、cURL、jansson 和 OpenSSL。

这是我使用的文件和软件的列表:

  1. httpd-2.4.48
  2. apr-1.7.0
  3. apr-util-1.6.1
  4. 卷曲 7.77.0
  5. expat-2.4.1
  6. 杨松2.13.1
  7. Lua 5.4.3
  8. mod_fcgid 2.3.9
  9. openssl-1.1.1k
  10. pcre-8.44
  11. ZLIB 1.2.11
  12. ActivePerl v5.28.1.2801 (x64)
  13. CMake v3.20.3 (x64)
  14. NASM v2.15.05 (x64)
  15. Gawk v3.1.6-1 (x86)

我使用的整个编译语句:

Visual Studio 2015:调用“C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat”amd64

*****************
** ZLIB Build **
*****************

cd /D C:\httpd\srclib\zlib\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
nmake
nmake install

****************
** Pcre Build **
****************
cd /D C:\httpd\srclib\pcre\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DPCRE_BUILD_TESTS=OFF -DPCRE_BUILD_PCRECPP=OFF -DPCRE_BUILD_PCREGREP=OFF -DPCRE_SUPPORT_PCREGREP_JIT=OFF -DPCRE_SUPPORT_UTF=ON -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON -DPCRE_NEWLINE=CRLF -DINSTALL_MSVC_PDB=OFF ..
nmake
nmake install

*****************
** Expat Build **
*****************
cd /D C:\httpd\srclib\expat\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
nmake
nmake install

*******************
** OpenSSL Build **
*******************
cd /D C:\httpd\srclib\openssl
perl Configure VC-WIN64A --release --prefix=\phpStudy\Apache --openssldir=\phpStudy\Apache\conf enable-camellia no-idea no-mdc2 no-ssl2 no-ssl3
nmake
nmake install

***************
** Lua Build **
***************

cd /D C:\httpd\srclib\lua\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release ..
nmake
nmake install

****************
** cURL Build **
****************

cd /D C:\httpd\srclib\curl\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
nmake
nmake install

*******************
** jansson Build **
*******************

cd /D C:\httpd\srclib\jansson\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
nmake
nmake install

***************
** APR Build **
***************
cd /D C:\httpd\srclib\apr\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DMIN_WINDOWS_VER=0x0600 -DAPR_HAVE_IPV6=ON -DAPR_INSTALL_PRIVATE_H=ON -DAPR_BUILD_TESTAPR=OFF -DINSTALL_PDB=OFF ..
nmake
nmake install

********************
** APR-Util Build **
********************
cd /D C:\httpd\srclib\apr-util\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DOPENSSL_ROOT_DIR=\phpStudy\Apache  -DAPU_HAVE_CRYPTO=ON -DAPR_BUILD_TESTAPR=OFF -DINSTALL_PDB=OFF ..
nmake
nmake install

******************
** Apache Build **
******************
cd /D C:\httpd\bin
cmake -G "NMake Makefiles" -DCMAKE_INSTALL_PREFIX=\phpStudy\Apache -DCMAKE_BUILD_TYPE=Release -DENABLE_MODULES=i -DINSTALL_PDB=OFF ..
nmake
nmake install

一切工作几乎完美,但是在我编译 HTTPD 的最后一步中,我得到了错误:

[ 44%] Linking C shared library mod_md.so
LINK: command "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\link.exe /nologo @CMakeFiles\mod_md.dir\objects1.rsp /out:mod_md.so /implib:mod_md.lib /pdb:C:\httpd\bin\mod_md.pdb /dll /version:0.0 /base:@C:/httpd/bin/BaseAddr.ref,mod_md.so /machine:x64 /INCREMENTAL:NO \phpStudy\Apache\lib\libssl.lib \phpStudy\Apache\lib\libcrypto.lib \phpStudy\Apache\lib\jansson.lib mod_watchdog.lib libhttpd.lib \phpStudy\Apache\lib\libapr-1.lib \phpStudy\Apache\lib\libaprutil-1.lib \phpStudy\Apache\lib\apr_ldap-1.lib ws2_32.lib mswsock.lib \phpStudy\Apache\lib\pcre.lib ws2_32.lib mswsock.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:mod_md.so.manifest" failed (exit code 1120) with the following output:
   Creating library mod_md.lib and object mod_md.exp
md_curl.c.obj : error LNK2019: unresolved external symbol curl_global_init referenced in function md_curl_init
md_curl.c.obj : error LNK2019: unresolved external symbol curl_slist_append referenced in function curlify_headers
md_curl.c.obj : error LNK2019: unresolved external symbol curl_slist_free_all referenced in function md_curl_req_cleanup
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_strerror referenced in function md_curl_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_init referenced in function internals_setup
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_setopt referenced in function internals_setup
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_perform referenced in function md_curl_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_cleanup referenced in function md_curl_req_cleanup
md_curl.c.obj : error LNK2019: unresolved external symbol curl_easy_getinfo referenced in function md_curl_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_init referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_add_handlereferenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_remove_handle referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_wait referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_perform referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_cleanup referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_info_read referenced in function md_curl_multi_perform
md_curl.c.obj : error LNK2019: unresolved external symbol curl_multi_strerror referenced in function md_curl_multi_perform
mod_md.so : fatal error LNK1120: 17 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.

我找到了这个问题的答案:Visual Studio 2015 curl will not statically link

md_curl.c文件的代码改为:

#pragma comment(lib, "wldap32.lib" )
#pragma comment(lib, "crypt32.lib" )
#pragma comment(lib, "Ws2_32.lib")

#define CURL_STATICLIB
#include <curl/curl.h>

但是还是会出现这个错误。

我哪里做错了?我很困惑,因为这是我在编译 HTTPD 时第一次遇到此错误。

您的回答会很有帮助。我会很感激的!

【问题讨论】:

    标签: c++ apache visual-studio-2015 linker


    【解决方案1】:

    每当您解决问题时,从第一个问题开始(因为解决问题可能会删除剩余的问题),在您的情况下似乎是:

    error LNK2019: unresolved external symbol curl_global_init referenced in function md_curl_init
    

    它基本上告诉我们,md_curl_init 方法调用curl_global_init 方法,但是虽然编译时声明可用,但链接器时需要定义 不见了。

    无论如何,要解决此问题,请确保将 curl 添加为库,我的意思是,当前不在您的链接器命令行中(至少不在您发布的内容中)。


    编辑我会建议你如何做到这一点。

    但首先,给它更多时间,我看到了:

    1. 是的,你已经编译了curl
    2. 您的“整个编译语句”正在使用C:\httpd\srclib\curl\bin 作为cURL 的构建目录。
    3. 另外,您应该能够在C:\httpd\srclib\curl\bin 目录(用作构建目录)中找到curl.lib

    方法#1:

    创建一个根CMakeFiles.txt 文件并使用add_subdirectory(...) 方法添加您的其他项目。

    推荐这种方法,因为CMake 将为您处理自动查找curl 的任务。

    我的意思是,您只需要执行以下操作:

    target_link_libraries(myTargetThatNeedsCurl
        curl
    )
    

    方法#2:

    如果您不想更改“整个编译语句”,那么您唯一的选择可能是将 curl.lib 放置在您的其他构建脚本可以找到它的地方(手动或通过一些自定义 install(...) 方法调用,我把它留给你)。

    方法#3:

    1. 首先,编辑httpd 项目(C:\httpd\CMakeFiles.txt 文件),并在开头的某处添加add_subdirectory(srclib/curl)

    2. 然后,找到cURL 目标的名称,比如,打开C:\httpd\srclib\curl\CMakeFiles.txt 文件并查看所有add_library(...) 调用的第一个参数(其中一个是我们想要的)。

    3. 最后,再次编辑 httpd 项目,但现在将您在第 2 步中找到的内容作为参数添加到 target_link_libraries(...) 方法。

    注意方法 #3 与 #2 相同,但仅适用于 cURL(而不是添加所有子目录)。

    【讨论】:

    • 我更新了将-DBUILD_SHARED_LIBS=ON 添加到编译命令行。我没有指定驱动器号,因此以后它可以在许多不同的驱动器上工作。我查看了文件夹\phpStudy\Apache,但没有找到你说的curl.lib文件,但仍然出现上述错误。但是,在 \phpStudy\Apache\bin 文件夹中,我确实看到了 curl.execurl.dll 文件!
    • @TầnQuảng 我希望你看到我的编辑(并且你现在可以修复它)。
    • 我尝试直接在根目录而不是bin目录编译。我注意到 Apache httpd 配置摘要中的 Curl 包含目录为空,即使上面检测到 CURL(当然错误仍然存​​在):i.imgur.com/llymFrx.png 这次我注意到,在文件夹 \phpStudy\apache\lib 中出现了一个文件 @987654354 @ 我以前编译但没有。我还是不明白你给的Approach #1,我用CMake编译所有东西,所以我编译的所有功能都有一个CMakeFiles.txt文件。
    • 尝试将mod_md_extra_libs 更改为SET(mod_md_extra_libs ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} ${JANSSON_LIBRARIES} mod_watchdog libcurl) 并重建(但我想知道CURL_LIBRARIES 变量包含什么)。
    • 谢谢,按你说的重新编辑后编译成功!将mod_md_extra_libs 更改为SET(mod_md_extra_libs ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} ${JANSSON_LIBRARIES} mod_watchdog libcurl)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 2012-08-31
    相关资源
    最近更新 更多