libCurl x64 在 Visual Studio 2013 (x64) 中的构建问题(Visual Studio & CMake)

3
我正在尝试在Windows 8.1 x64上构建libCurl x64,但是遇到了链接器错误。我需要这样做,因为我需要创建一个64位调试版本的库,以便跟踪一些奇怪的FTP相关协议问题。基本的错误输出(为简洁起见已削减)如下:

1> ------开始构建:项目:ZERO_CHECK,配置:Debug x64

...

2>;C:\Users\jcoffey\main\extlibs\curl-7.35.0\lib\smtp.c(2174):警告 C4267:“+ =”:从“size_t”转换为“long”,可能会丢失数据 2>pingpong.c 2>rtsp.c 2>curl_threads.c 2>warnless.c 2> hmac.c 2>curl_rtmp.c 2>openldap.c 2>curl_gethostname.c 2> gopher.c 2>生成代码... 2>编译... 2>idn_win32.c 2> http_negotiate_sspi.c 2>http_proxy.c 2>non-ascii.c 2>asyn-ares.c 2>asyn-thread.c 2>curl_gssapi.c 2>curl_ntlm.c 2>curl_ntlm_wb.c 2>curl_ntlm_core.c 2>curl_ntlm_msgs.c 2>curl_sasl.c 2> curl_multibyte.c 2>hostcheck.c 2>bundles.c 2>conncache.c 2> pipeline.c 2>dotdot.c 2>x509asn1.c 2>http2.c 2>生成 代码... 2>编译... 2>openssl.c 2>gtls.c 2>vtls.c 2>nss.c 2>qssl.c 2>polarssl.c 2>polarssl_threadlock.c 2>axtls.c 2> cyassl.c 2>curl_schannel.c 2>curl_darwinssl.c 2>gskit.c 2> 生成代码...

...

2>x64\Debug\file.obj : 致命错误 LNK1112: 模块 机器类型“x64”与目标机器类型“X86”冲突3>------ 开始构建:项目:curl,配置:Debug x64 ------3> 构建自定义规则 C:/Users/jcoffey/main/extlibs/curl-7.35.0/src/CMakeLists.txt

请帮忙 - 我在论坛和stackoverflow上搜索了类似的内容,但没有找到。我能够成功构建x86(win32)模式,但是当我以x64为目标时,我遇到了链接错误。
步骤1: 下载最新版本的CMake 2.8.12.2并更新Windows PATH环境变量(在我的情况下,我使用MINMGW32 bash shell提示符,但如果我使用本机Visual Studio 2013 x64 shell运行cmake也会出现完全相同的链接问题) $ export PATH=$PATH:/c/Program\ Files\ (x86)/CMake\ 2.8/bin
验证Windows上Cmake的路径和版本 $ cmake --version cmake version 2.8.12.2
步骤2: 将curl-7.35.0提取到文件夹c:\temp\curl-7.35.0中,并创建一个并行文件夹“c:\temp\curl-7.35.0 \build”。
步骤3: 更改到构建文件夹并运行Cmake,将Visual Studio 12作为所需的Visual Studio Solution / project组合进行定位 $ cmake -G "Visual Studio 12" ../curl-7.35.0
这会产生大量输出,但它确实创建了一个可工作的Visual Studio解决方案,其目标是X86机器类型。

$ cmake -G "Visual Studio 12" ../curl-7.35.0 -- The C compiler identification is MSVC 18.0.21005.1 -- Check for working C compiler using: Visual Studio 12 -- Check for working C compiler using: Visual Studio 12 -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done CMake Warning at CMakeLists.txt:47 (message): the curl cmake build system is poorly maintained. Be aware

-- curl version=[7.35.0] -- Looking for getch in ws2_32; -- Looking for getch in ws2_32; - found -- Looking for getch in winmm;ws2_32 -- Looking for getch in winmm;ws2_32 - found -- Looking for cldap_open in wldap32 -- Looking for cldap_open in wldap32 - found -- Looking for idna_to_ascii_lz in idn;winmm;ws2_32 -- Looking for idna_to_ascii_lz in idn;winmm;ws2_32 - not found -- Looking for ldap_init in ldap;winmm;ws2_32 -- Looking for ldap_init in ldap;winmm;ws2_32 - not found -- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the sys tem variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR)

-- Looking for include file ws2tcpip.h -- Looking for include file ws2tcpip.h - found -- Looking for include files ws2tcpip.h, winsock2.h -- Looking for include files ws2tcpip.h, winsock2.h - found -- Looking for 3 include files ws2tcpip.h, ..., stdio.h -- Looking for 3 include files ws2tcpip.h, ..., stdio.h - found -- Looking for 4 include files ws2tcpip.h, ..., windows.h -- Looking for 4 include files ws2tcpip.h, ..., windows.h - found -- Looking for 5 include files ws2tcpip.h, ..., winsock.h -- Looking for 5 include files ws2tcpip.h, ..., winsock.h - found -- Looking for 6 include files ws2tcpip.h, ..., sys/filio.h -- Looking for 6 include files ws2tcpip.h, ..., sys/filio.h - not found -- Looking for 6 include files ws2tcpip.h, ..., sys/ioctl.h -- Looking for 6 include files ws2tcpip.h, ..., sys/ioctl.h - not found -- Looking for 6 include files ws2tcpip.h, ..., sys/resource.h -- Looking for 6 include files ws2tcpip.h, ..., sys/resource.h - not found -- Looking for 8 include files ws2tcpip.h, ..., sys/uio.h -- Looking for 8 include files ws2tcpip.h, ..., sys/uio.h - not found -- Looking for 8 include files ws2tcpip.h, ..., sys/un.h -- Looking for 8 include files ws2tcpip.h, ..., sys/un.h - not found -- Looking for 9 include files ws2tcpip.h, ..., arpa/tftp.h -- Looking for 9 include files ws2tcpip.h, ..., arpa/tftp.h - not found -- Looking for 9 include files ws2tcpip.h, ..., assert.h -- Looking for 9 include files ws2tcpip.h, ..., assert.h - found -- Looking for 10 include files ws2tcpip.h, ..., crypto.h -- Looking for 10 include files ws2tcpip.h, ..., crypto.h - not found -- Looking for 10 include files ws2tcpip.h, ..., des.h -- Looking for 10 include files ws2tcpip.h, ..., des.h - not found -- Looking for 10 include files ws2tcpip.h, ..., err.h -- Looking for 10 include files ws2tcpip.h, ..., err.h - not found -- Looking for 10 include files ws2tcpip.h, ..., errno.h -- Looking for 10 include files ws2tcpip.h, ..., errno.h - found -- Looking for 12 include files ws2tcpip.h, ..., gssapi/gssapi.h -- Looking for 12 include files ws2tcpip.h, ..., gssapi/gssapi.h - not found -- Looking for 12 include files ws2tcpip.h, ..., gssapi/gssapi_generic.h -- Looking for 12 include files ws2tcpip.h, ..., gssapi/gssapi_generic.h - not f ound -- Looking for 12 include files ws2tcpip.h, ..., gssapi/gssapi_krb5.h -- Looking for 12 include files ws2tcpip.h, ..., gssapi/gssapi_krb5.h - not foun d -- Looking for 12 include files ws2tcpip.h, ..., idn-free.h -- Looking for 12 include files ws2tcpip.h, ..., idn-free.h - not found -- Looking for 12 include files ws2tcpip.h, ..., ifaddrs.h -- Looking for 12 include files ws2tcpip.h, ..., ifaddrs.h - not found -- Looking for 13 include files ws2tcpip.h, ..., krb.h -- Looking for 13 include files ws2tcpip.h, ..., krb.h - not found -- Looking for 13 include files ws2tcpip.h, ..., libgen.h -- Looking for 13 include files ws2tcpip.h, ..., libgen.h - not found -- Looking for 13 include files ws2tcpip.h, ..., libssh2.h -- Looking for 13 include files ws2tcpip.h, ..., libssh2.h - not found -- Looking for 13 include files ws2tcpip.h, ..., limits.h -- Looking for 13 include files ws2tcpip.h, ..., limits.h - found -- Looking for 14 include files ws2tcpip.h, ..., locale.h -- Looking for 14 include files ws2tcpip.h, ..., locale.h - found -- Looking for 15 include files ws2tcpip.h, ..., netinet/tcp.h -- Looking for 15 include files ws2tcpip.h, ..., netinet/tcp.h - not found -- Looking for 15 include files ws2tcpip.h, ..., pem.h -- Looking for 15 include files ws2tcpip.h, ..., pem.h - not found -- Looking for 15 include files ws2tcpip.h, ..., poll.h -- Looking for 15 include files ws2tcpip.h, ..., poll.h - not found -- Looking for 15 include files ws2tcpip.h, ..., rsa.h -- Looking for 15 include files ws2tcpip.h, ..., rsa.h - not found -- Looking for 17 include files ws2tcpip.h, ..., ssl.h -- Looking for 17 include files ws2tcpip.h, ..., ssl.h - not found -- Looking for 17 include files ws2tcpip.h, ..., stdbool.h -- Looking for 17 include files ws2tcpip.h, ..., stdbool.h - found -- Looking for 21 include files ws2tcpip.h, ..., stropts.h -- Looking for 21 include files ws2tcpip.h, ..., stropts.h - not found -- Looking for 22 include files ws2tcpip.h, ..., tld.h -- Looking for 22 include files ws2tcpip.h, ..., tld.h - not found -- Looking for 23 include files ws2tcpip.h, ..., stddef.h -- Looking for 23 include files ws2tcpip.h, ..., stddef.h - found -- Looking for 26 include files ws2tcpip.h, ..., ldap.h -- Looking for 26 include files ws2tcpip.h, ..., ldap.h - not found -- Looking for 26 include files ws2tcpip.h, ..., sys/utsname.h -- Looking for 26 include files ws2tcpip.h, ..., sys/utsname.h - not found -- Looking for 26 include files ws2tcpip.h, ..., idna.h -- Looking for 26 include files ws2tcpip.h, ..., idna.h - not found -- LDAP_H not found CURL_DISABLE_LDAP set ON -- LDAP needs to be enabled to support LDAPS -- Check size of size_t -- Check size of size_t - done -- Check size of ssize_t -- Check size of ssize_t - failed -- Check size of long long -- Check size of long long - done -- Check size of long -- Check size of long - done -- Check size of short -- Check size of short - done -- Check size of int -- Check size of int - done -- Check size of __int64 -- Check size of __int64 - done -- Check size of time_t -- Check size of time_t - done -- Looking for basename -- Looking for basename - not found -- Looking for strncmpi -- Looking for strncmpi - not found -- Looking for alarm -- Looking for alarm - not found -- Looking for CRYPTO_cleanup_all_ex_data -- Looking for CRYPTO_cleanup_all_ex_data - not found -- Looking for gethostbyname -- Looking for gethostbyname - found -- Looking for strtoll -- Looking for strtoll - found -- Looking for _strtoi64 -- Looking for _strtoi64 - found -- Looking for strerror_r -- Looking for strerror_r - not found -- Looking for siginterrupt -- Looking for siginterrupt - not found -- Looking for fork -- Looking for fork - not found -- Looking for freeaddrinfo -- Looking for freeaddrinfo - found -- Looking for freeifaddrs -- Looking for freeifaddrs - not found -- Looking for pipe -- Looking for pipe - not found -- Looking for ftruncate -- Looking for ftruncate - not found -- Looking for getprotobyname -- Looking for getprotobyname - found -- Looking for getrlimit -- Looking for getrlimit - not found -- Looking for idn_free -- Looking for idn_free - not found -- Looking for idna_strerror -- Looking for idna_strerror - not found -- Looking for tld_strerror -- Looking for tld_strerror - not found -- Looking for setlocale -- Looking for setlocale - found -- Looking for setrlimit -- Looking for setrlimit - not found -- Looking for fcntl -- Looking for fcntl - not found -- Looking for ioctl -- Looking for ioctl - not found -- Looking for setsockopt -- Looking for setsockopt - found -- Looking for inet_pton -- Looking for inet_pton - not found -- Performing Curl Test HAVE_FCNTL_O_NONBLOCK -- Performing Curl Test HAVE_FCNTL_O_NONBLOCK - Failed -- Performing Curl Test HAVE_IOCTLSOCKET -- Performing Curl Test HAVE_IOCTLSOCKET - Success -- Performing Curl Test HAVE_IOCTLSOCKET_CAMEL -- Performing Curl Test HAVE_IOCTLSOCKET_CAMEL - Failed -- Performing Curl Test HAVE_IOCTLSOCKET_CAMEL_FIONBIO -- Performing Curl Test HAVE_IOCTLSOCKET_CAMEL_FIONBIO - Success -- Performing Curl Test HAVE_IOCTLSOCKET_FIONBIO -- Performing Curl Test HAVE_IOCTLSOCKET_FIONBIO - Success -- Performing Curl Test HAVE_IOCTL_FIONBIO -- Performing Curl Test HAVE_IOCTL_FIONBIO - Failed -- Performing Curl Test HAVE_IOCTL_SIOCGIFADDR -- Performing Curl Test HAVE_IOCTL_SIOCGIFADDR - Failed -- Performing Curl Test HAVE_SETSOCKOPT_SO_NONBLOCK -- Performing Curl Test HAVE_SETSOCKOPT_SO_NONBLOCK - Failed -- Performing Curl Test HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID -- Performing Curl Test HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID - Failed -- Performing Curl Test HAVE_SOCKLEN_T -- Performing Curl Test HAVE_SOCKLEN_T - Success -- Performing Curl Test HAVE_BOOL_T -- Performing Curl Test HAVE_BOOL_T - Success -- Performing Curl Test HAVE_FILE_OFFSET_BITS -- Performing Curl Test HAVE_FILE_OFFSET_BITS - Failed -- Performing Curl Test HAVE_GLIBC_STRERROR_R -- Performing Curl Test HAVE_GLIBC_STRERROR_R - Failed -- Performing Curl Test HAVE_POSIX_STRERROR_R -- Performing Curl Test HAVE_POSIX_STRERROR_R - Failed -- Check size of curl_off_t -- Check size of curl_off_t - failed -- Check size of socklen_t -- Check size of socklen_t - done -- Performing Test curl_cv_recv -- Performing Test curl_cv_recv - Success -- Performing Test int recv(int, void *, size_t, int) (curl_cv_func_recv_test) -- Performing Test int recv(int, void *, size_t, int) (curl_cv_func_recv_test) - Success -- Performing Test curl_cv_send -- Performing Test curl_cv_send - Success -- Performing Test int send(int, const void *, size_t, int) (curl_cv_func_send_t est) -- Performing Test int send(int, const void *, size_t, int) (curl_cv_func_send_t est) - Success -- Performing Test HAVE_MSG_NOSIGNAL -- Performing Test HAVE_MSG_NOSIGNAL - Failed -- Performing Test HAVE_STRUCT_TIMEVAL -- Performing Test HAVE_STRUCT_TIMEVAL - Success -- Performing Test HAVE_POLL_FINE -- Performing Test HAVE_POLL_FINE - Failed -- Check size of sig_atomic_t -- Check size of sig_atomic_t - done -- Performing Test HAVE_SIG_ATOMIC_T_NOT_VOLATILE -- Performing Test HAVE_SIG_ATOMIC_T_NOT_VOLATILE - Success -- Check size of struct sockaddr_storage -- Check size of struct sockaddr_storage - failed CMake Warning (dev) at tests/CMakeLists.txt:1 (add_subdirectory): The source directory

C:/Users/jcoffey/main/extlibs/curl-7.35.0/tests/libtest

does not contain a CMakeLists.txt file.

CMake does not support this case but it used to work accidentally and is being allowed for compatibility.

Policy CMP0014 is not set: Input directories must have CMakeLists.txt. Run "cmake --help-policy CMP0014" for policy details. Use the cmake_policy command to set the policy and suppress this warning. This warning is for project developers. Use -Wno-dev to suppress it.

CMake Warning (dev) at tests/CMakeLists.txt:2 (add_subdirectory):
The source directory

C:/Users/jcoffey/main/extlibs/curl-7.35.0/tests/server

does not contain a CMakeLists.txt file.

CMake does not support this case but it used to work accidentally and is being allowed for compatibility.

Policy CMP0014 is not set: Input directories must have CMakeLists.txt. Run "cmake --help-policy CMP0014" for policy details. Use the cmake_policy command to set the policy and suppress this warning. This warning is for project developers. Use -Wno-dev to suppress it.

-- Configuring done -- Generating done -- Build files have been written to: C:/Users/jcoffey/main/extlibs/curl-7.35.0-build

步骤4: 在Visual Studio中,使用配置管理器将目标类型更改为x64(我不得不选择一个新平台,我选择了X64并从Win32复制了设置)。这是一个非常简单明了的步骤,用于针对X64机器目标,为了避免混淆,我没有在这里包含详细的步骤。

步骤5: 从Visual Studio 2013中选择解决方案并重新构建所有内容,上面的输出将随之而来。

旁注:虽然我现在不需要SSL,但知道如何告诉CMake LIBSSL事物的位置会很好(我从http://www.confusedbycode.com/curl/下载了一个预构建库包(包括SSL和其他库的32位和64位版本),但这些是发布模式,我需要能够调试libCurl以查看我遇到的一些奇怪问题。我不擅长配置CMake,但它似乎是一个非常有前途的工具,适用于那些针对多个平台但更喜欢在Windows上开发的人。它肯定比gnu autotools容易。


在 Visual Studio 中,使用配置管理器将目标类型更改为 x64。在这种情况下,您需要使用“Visual Studio 12 Win64”生成器。 - user2288008
从第4步开始,阅读我的完整帖子,您可以看到我已经尝试过了,但出现了问题:致命错误LNK1112:模块机器类型“x64”与目标机器类型“X86”冲突。 - johnco3
Visual Studio 12Visual Studio 12 Win64是不同的生成器。据我所知,您无法使用Visual Studio 12生成项目并切换到x64。请尝试使用cmake -G "Visual Studio 12 Win64" ../curl-7.35.0 - user2288008
干得好,那真的起作用了,我从来没有意识到我可以将"Win64"字符串附加到生成器字符串上。谢谢 - 非常有用,现在下一个挑战将是解决OPENSSL_LIBRARIES OPENSSL_INCLUDE_DIR - 但我怀疑这不会很困难(尽管我需要确保这些库也在Win64中构建)。再次感谢 - johnco3
4个回答

3
在干净的x64 / Win 8.1 / VS2013环境中构建64位libcurl的技巧是,首先使用"amd64"参数运行Visual Studio vcvars.bat批处理文件。这将正确设置制作环境。

然后按照winbuild\BUILD.WINDOWS.txt中所述运行“nmake…”命令即可。


1

看起来CMake生成的解决方案文件没有将X64作为潜在目标。我在这里找到了一个问题的微小变体。

这里输入链接描述

这是X64命令行选项的图片 - 如您所见,在我将配置管理器更改为使用X64后,

Command Line - Additional Options uses incorrect machine 'X86'

Command Line - Additional Options manually changed machine to 'X64'

在进行这些更改后,项目最终链接成功,我能够生成库的调试版本。


你是如何告诉nmake进入winbuild并运行Makefile.vc的呢? - NobleUplift
1

构建libCurl库(发布版和调试版)

(1)使用VS2015 x64本机工具命令提示符从extlibs/curl-7.44.0开始: (2)cd \Users\Johnc\main\extlibs\curl-7-44.0\winbuild (3)nmake /f Makefile.vc mode=dll VC=14 MACHINE=x64 GEN_PDB=yes (4)nmake /f Makefile.vc mode=dll VC=14 MACHINE=x64 DEBUG=yes GEN_PDB=yes
- johnco3
1
抱歉,我的问题表述不够清晰。你是如何在Visual Studio中设置libcurl进行构建的?每次我尝试构建项目时,它都会失败并显示找不到../<某个文件夹>的错误信息。 - NobleUplift

1
我在使用命令行构建CURL时遇到了相同的问题(module machine type 'x64' conflicts with target machine type 'X86'),这是在文件夹“curl-7.40.0 \ winbuild”中按照“BUILD.WINDOWS.txt”中的描述。我使用了以下命令行:nmake / f Makefile.vc mode = dll ENABLE_WINSSL = no ENABLE_IDN = no GEN_PDB = yes ENABLE_SSPI = no MACHINE = x64 DEBUG = no。它指定“使用Visual Studio命令提示符Shell”,但是…还有更多:“Visual Studio 2005命令提示符”无法正常工作,“Visual Studio 2005 x64 Win64命令提示符”可以(用于64位)。对我来说,它适用于Visual Studio 2005,但他们说它只需要“Platform SDK”。

0
将此脚本放置在Curl的源目录中(我将其命名为winbuild.bat),如果您不需要curl项目与解决方案的其他部分一起编译,请运行它:
@ECHO OFF
CALL "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\vcvars64.bat"
CD winbuild
nmake /f Makefile.vc mode=dll WITH_DEVEL=..\..\dll64 VC=12 WITH_SSL=dll GEN_PDB=yes MACHINE=X64
CD ..
EXIT /B 0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接