如何在Ubuntu for Windows上使用curl进行交叉编译

blmhpbnm  于 2022-11-02  发布在  Windows
关注(0)|答案(1)|浏览(268)

我想编译这个源代码:


# include <curl/curl.h>

# include <iostream>

int main() {
    std::cout << "I am compiled with curl";
}

我在Ubuntu 22.04 * 上进行编译,但目标是Windows 7和Windows 10*。如this answer中所述,我必须配置curl。我在以下地址下载了curl包:https://curl.se/download/curl-7.86.0.tar.gz
我将其解压缩,并在目录中输入命令./configure --build x86_64-pc-linux-gnu --host x86_64-w64-mingw32 --prefix=/usr/x86_64-w64-mingw32 --without-ssl

configure: amending tests/server/Makefile
configure: amending tests/libtest/Makefile
configure: amending docs/examples/Makefile
configure: Configured to build curl/libcurl:

  Host setup:       x86_64-w64-mingw32
  Install prefix:   /usr/x86_64-w64-mingw32
  Compiler:         x86_64-w64-mingw32-gcc
   CFLAGS:          -O2 -pthread
   CPPFLAGS:        
   LDFLAGS:         
   LIBS:            -lbcrypt -ladvapi32 -lcrypt32 -lwldap32 -lws2_32

  curl version:     7.86.0
  SSL:              no      (--with-{openssl,gnutls,nss,mbedtls,wolfssl,schannel,secure-transport,amissl,bearssl,rustls} )
  SSH:              no      (--with-{libssh,libssh2})
  zlib:             no      (--with-zlib)
  brotli:           no      (--with-brotli)
  zstd:             no      (--with-zstd)
  GSS-API:          no      (--with-gssapi)
  GSASL:            no      (libgsasl not found)
  TLS-SRP:          no      (--enable-tls-srp)
  resolver:         POSIX threaded
  IPv6:             enabled
  Unix sockets:     enabled
  IDN:              no      (--with-{libidn2,winidn})
  Build libcurl:    Shared=yes, Static=yes
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  Code coverage:    disabled
  SSPI:             no      (--enable-sspi)
  ca cert bundle:   no
  ca cert path:     
  ca fallback:      
  LDAP:             enabled (winldap)
  LDAPS:            enabled
  RTSP:             enabled
  RTMP:             no      (--with-librtmp)
  PSL:              no      (libpsl not found)
  Alt-svc:          enabled (--disable-alt-svc)
  Headers API:      enabled (--disable-headers-api)
  HSTS:             no      (--enable-hsts)
  HTTP1:            enabled (internal)
  HTTP2:            no      (--with-nghttp2, --with-hyper)
  HTTP3:            no      (--with-ngtcp2, --with-quiche --with-msh3)
  ECH:              no      (--enable-ech)
  WebSockets:       no      (--enable-websockets)
  Protocols:        DICT FILE FTP GOPHER HTTP IMAP LDAP LDAPS MQTT POP3 RTSP SMB SMTP TELNET TFTP
  Features:         AsynchDNS IPv6 Largefile NTLM UnixSockets alt-svc threadsafe

这是我在尝试编译时遇到的错误:

i686-w64-mingw32-g++ main.cpp -o main.exe -lws2_32 -lwininet -s -ffunction-sections -fdata-sections -Wno-write-strings -fno-exceptions -fmerge-all-constants -static-libstdc++ -static-libgcc
main.cpp:1:10: fatal error: curl/curl.h: No such file or directory

    1 | #include <curl/curl.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

如果添加参数-lcurl,则会出现以下错误:collect2: error: ld returned 1 exit status
我也有出售的包裹

sudo apt-get install libcurl4-gnutls-dev libcurl4-gnutls-dev

我应该怎么做?有人可以告诉我应该执行哪些命令来编译这个代码段?

**EDIT:**为了澄清我的问题,我不能使用g++,因为我有其他包含,如:


# include <winsock2.h>

# include <windows.h>

# include <ws2tcpip.h>

# include <unistd.h>

# include <iostream>

# include <conio.h>

这就是我为什么使用mingw的原因(也许是一个坏的原因,但我不知道如何使用g++在Ubuntu上编译这些库)。

ars1skjm

ars1skjm1#

我下载了curl软件包
为什么你要把糟糕的Windows步骤应用到你的Ubuntu上呢?只要安装libcurl dev包:

sudo apt install libcurlpp-dev

我应该怎么做?有人可以告诉我应该执行哪些命令来编译这个代码段?
不要在Ubuntu上使用MinGW。从Ubuntu软件包安装GCC。我假设,如果你已经安装了任何dev软件包,它已经安装了。

相关问题