【问题标题】:Compiling a library (redland) in Cygwin using gcc and using the output in Visual Studio (c++)使用 gcc 在 Cygwin 中编译库 (redland) 并使用 Visual Studio (c++) 中的输出
【发布时间】:2013-05-28 18:42:38
【问题描述】:

我目前正在尝试在 Windows 下编译 redland (librdf http://librdf.org/)。根据他们的网站,它应该在 Windows 下构建。因为我不想花时间修复 .sln,所以我考虑在 cygwin 中编译 librdf(和必要的项目),然后在 Visual Studio 中使用该库。

所以我的问题是: 是否可以在 Windows 应用程序中使用在 cygwin 中编译的库?如果是的话怎么办?

由于我是 Windows 开发人员,我不知道创建的 .a 文件与 .dll 是否有任何区别。我已经阅读了该主题,并且有必要在项目中包含 cygwin1.dll,但这不是问题。

或者有没有人知道如何将 redland 编译为 windows dll? 我想过使用mingw,但直到现在我都没有设法编译它。

我们将不胜感激。

谢谢

更新:

感谢 Yaakov(以及他非常酷的 cygwin 端口)的帮助,同时我设法编译了 raptor(这是 librdf 的先决条件)。 我所要做的就是为配置添加另一个参数:--with-xml2-config=/usr/x86_64-w64-mingw32/sys-root/mingw/bin/xml2-config

现在我正在尝试编译 rasqal,它是另一个 requesite,也依赖于 raptor2。 为了让它工作,我必须为 pkg-config 导出 PKG_CONFIG_PATH="/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/" 以找到正确的 raptor 安装。

所以为 rasqal 配置工作,但是当我尝试进行配置时,我收到以下错误:

Making all in src
make[1]: Entering directory `/home/Stefan/workspace/rasqal/src'
make  all-am
make[2]: Entering directory `/home/Stefan/workspace/rasqal/src'
/bin/sh ../libtool  --tag=CC    --mode=compile x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H  -I.   -DRASQAL_INTERNAL=1   -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/raptor2       -g -O2   -DMTWIST_CONFIG -I../libmtwist -g -O2 -MT rasqal_algebra.lo -MD -MP -MF .deps/rasqal_algebra.Tpo -c -o rasqal_algebra.lo rasqal_algebra.c
libtool: compile:  x86_64-w64-mingw32-gcc -DHAVE_CONFIG_H -I. -DRASQAL_INTERNAL=1 -I/usr/x86_64-w64-mingw32/sys-root/mingw/include/raptor2 -g -O2 -DMTWIST_CONFIG -I../libmtwist -g -O2 -MT rasqal_algebra.lo -MD -MP -MF .deps/rasqal_algebra.Tpo -c rasqal_algebra.c  -DDLL_EXPORT -DPIC -o .libs/rasqal_algebra.o
In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/sys/time.h:10:0,
                 from rasqal.h:116,
                 from rasqal_algebra.c:39:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/time.h:260:8: error: redefinition of 'struct timezone'
./win32_rasqal_config.h:62:8: note: originally defined here
Makefile:1045: recipe for target `rasqal_algebra.lo' failed
make[2]: *** [rasqal_algebra.lo] Error 1
make[2]: Leaving directory `/home/Stefan/workspace/rasqal/src'
Makefile:720: recipe for target `all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/Stefan/workspace/rasqal/src'
Makefile:484: recipe for target `all-recursive' failed
make: *** [all-recursive] Error 1

我无法理解我并不是真正喜欢交叉编译。 有人能指出我正确的方向吗?

【问题讨论】:

  • 您的操作正确;您刚刚遇到了可移植性问题。现在有两组适用于 Windows 的 GCC 兼容头文件和导入库:mingw.org 和 mingw-w64。后者更新、更完整,并且支持 x64,但这些差异可能与最初设计用于前者的软件包中的解决方法冲突,这似乎是这里的问题。 (我从未说过这会简单。)我会先删除win32_rasqal_config.h 文件中的冲突类型定义,然后尝试继续构建。
  • win32_rasqal_config.h 在 cygwin 下构建时不应使用。而是使用自动工具生成的rasqal_config.h

标签: visual-studio visual-c++ cygwin redland raptor2


【解决方案1】:

MSVC 和 Cygwin 运行时不兼容,因此您不能在 VS 中使用 Cygwin 编译的二进制文件。但是,您可以使用 Cygwin 交叉编译适用于 Windows 的库,对于 C 库,该库应该与 VS 兼容。 (C++ 是非常特定于编译器的,尤其是符号修饰,但是 IIRC 这些库都在 C 中。)

要开始使用,您需要通过 Cygwin 的 setup.exe 安装程序安装 mingw64-i686-gcc-coremingw64-i686-headersmingw64-i686-runtime 软件包以及所有依赖项。然后,从依赖链的“底部”开始,构建每个库,例如:

./configure --prefix=/usr/i686-w64-mingw32/sys-root/mingw --host=i686-w64-mingw32

然后运行make,然后运行make install。对于 Windows x64,将上面的所有 i686s 替换为 x86_64

请记住,librdf很多 个(子)依赖项,但我现在不记得有多少是可选的。其中一些(但不是全部)可从Cygwin Ports 存储库获得;这些至少应该可以帮助您入门。

【讨论】:

    【解决方案2】:

    我建议您使用 Visual Studio 构建 raptor2。 我以这种方式成功地为 Visual Studio 2017 x64 做到了这一点:

    安装 libxml2 和 libxslt

    打开 PowerShell:

    git clone https://github.com/Microsoft/vcpkg
    cd vcpkg
    .\bootstrap-vcpkg.bat
    .\vcpkg install libxml2:x64-windows
    .\vcpkg install libxslt:x64-windows
    

    构建 raptor2

    下载猛禽:http://librdf.org/raptor/(http://download.librdf.org/source/raptor2-2.0.15.tar.gz)

    更改 raptor2-2.015/CMakeLists.txt,第 258 行:

    ADD_DEFINITIONS(-DHAVE_CONFIG_H)
    ->
    ADD_DEFINITIONS(-DHAVE_CONFIG_H -DYY_NO_UNISTD_H)
    

    更改 raptor2-2.015/src/CMakeLists.txt,第 118 行:

    ADD_LIBRARY(raptor2
        raptor_avltree.c
        ...
    ->
    ADD_LIBRARY(raptor2
        raptor_escaped.c
        sort_r.c
        raptor_ntriples.c
        raptor_avltree.c
        ...
    

    打开cmake: 将 LIBXML2_INCLUDE_DIR 设置为:path/to/vcpkg/installed/x64-windows/include 将 LIBXML2_LIBRARIES 设置为:path/to/vcpkg/installed/x64-windows/lib/libxml2.lib

    set LIBXSLT_INCLUDE_DIR to: path/to/vcpkg/installed/x64-windows/include
    set LIBXSLT_LIBRARIES to: path/to/vcpkg/installed/x64-windows/lib/libxlst.lib
    set LIBXSLT_EXSLT_LIBRARY to: path/to/vcpkg/installed/x64-windows/lib/libexlst.lib
    

    部署:

    CMAKE_INSTALL_PREFIX 设置为您的部署路径,例如C:\thirdparty\vs2017\x64\raptor2

    在 Visual Studio 中执行 INSTALL 目标。

    如果您不喜欢手动执行此步骤,您可以下载预构建版本here

    【讨论】:

      猜你喜欢
      • 2013-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多