Compiling a library (redland) in Cygwin using gcc and using the output in Visual Studio (c++)

空扰寡人 提交于 2019-12-05 11:19:29

The MSVC and Cygwin runtimes are incompatible, so you cannot use a Cygwin-compiled binary within VS. However, you can use Cygwin to cross-compile a library for Windows, which for C libraries, should be compatible with VS. (C++ is very compiler-specific, particularly with symbol mangling, but IIRC these libraries are all in C.)

To get started, you need to install the mingw64-i686-gcc-core, mingw64-i686-headers, and mingw64-i686-runtime packages, plus all dependencies, via Cygwin's setup.exe installer. Then, beginning with the "bottom" of the dependency chain, build each library with e.g.:

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

Then run make followed by make install. For Windows x64, substitute all the i686s above with x86_64.

Keep in mind that librdf has a lot of (sub)dependencies, but I don't remember now how many are optional. Some, but not all, of these are available from the Cygwin Ports repository; those should at least help you get started.

I recommend you to build raptor2 using Visual Studio. I did this successfully for Visual Studio 2017 x64 this way:

Install libxml2 and libxslt

Open PowerShell:

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

Build raptor2

Download raptor: http://librdf.org/raptor/ (http://download.librdf.org/source/raptor2-2.0.15.tar.gz)

Change raptor2-2.015/CMakeLists.txt, line 258:

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

change raptor2-2.015/src/CMakeLists.txt, line 118:

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

open cmake: set LIBXML2_INCLUDE_DIR to: path/to/vcpkg/installed/x64-windows/include set LIBXML2_LIBRARIES to: 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

Deployment:

Set CMAKE_INSTALL_PREFIX to your deplyoment path e.g. C:\thirdparty\vs2017\x64\raptor2

Execute the INSTALL target in Visual Studio.

If you do not like to execute this steps manually you can just download a prebuild version here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!