首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Windows Ubuntu上交叉编译

如何在Windows Ubuntu上交叉编译
EN

Stack Overflow用户
提问于 2022-10-31 23:27:25
回答 1查看 68关注 0票数 -1

我想编译这个源代码:

代码语言:javascript
复制
#include <curl/curl.h>
#include <iostream>

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

我正在Ubuntu22.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输入到目录中。以下是输出的结尾:

代码语言:javascript
复制
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

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

代码语言:javascript
复制
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

我也吃过包裹

代码语言:javascript
复制
sudo apt-get install libcurl4-gnutls-dev libcurl4-gnutls-dev

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

编辑:为了澄清我的问题,我不能使用g++,因为我还有其他的内容,比如:

代码语言:javascript
复制
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <unistd.h>
#include <iostream>
#include <conio.h>

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

EN

回答 1

Stack Overflow用户

发布于 2022-11-01 00:25:20

i下载了curl包

为什么要将糟糕的Windows步骤应用于您的Ubuntu?只需安装libcurl dev软件包:

代码语言:javascript
复制
sudo apt install libcurlpp-dev

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

不要在Ubuntu上使用MinGW。从Ubuntu软件包安装GCC。我想,如果您已经安装了任何dev包,那么它已经安装好了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74270060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档