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

I'm currently trying to compile redland (librdf http://librdf.org/ ) under Windows. According to their website, it should be built under Windows. Since I do not want to waste my time fixing .sln, I thought about compiling librdf (and the necessary projects) in cygwin, and then using the library in visual studio.

So my question is: Is it possible to use libraries in cygwin in a Windows application? And if so, how?

As a window designer, I do not know if there is any difference from the created .a files in the .dlls. I already read this topic and you will need to include cygwin1.dll in the project, but that will not be a problem.

Or does anyone know better how I can get redland compiled as a Windows DLL? I was thinking about using mingw, but so far I have not been able to compile it.

Any help would be appreciated.

thanks

Update:

Thanks to the help of Yaakov (and his pretty cool cygwin ports), in the meantime, I managed to build raptor (which is a prerequisite for librdf). All I had to do was enable one more argument for configure: --with-xml2-config = / usr / x86_64-w64-mingw32 / sys-root / mingw / bin / xml2-config

Now I am trying to compile rasqal, which is another props, and also depends on raptor2. To do this, I had to export PKG_CONFIG_PATH = "/ usr / x86_64-w64-mingw32 / sys-root / mingw / lib / pkgconfig /" for pkg-config to find the correct raptor installation.

So, configure rasqal to work, but when I try to do this, I get the following error:

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 

What I can’t get around, I’m not going to cross-compile. Can someone point me in the right direction?

+4
source share
2 answers

The MSVC and Cygwin runtimes are incompatible, so you cannot use the compiled Cygwin binary in 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 specific to the compiler, especially when encoding characters, but all of these libraries are in C.)

To get started, you need to install the mingw64-i686-gcc-core , mingw64-i686-headers and mingw64-i686-runtime , as well as all the dependencies, through the Cygwin setup.exe program. Then, starting with the "bottom" chain of dependencies, create each library, for example:

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

Then run make and then make install . For Windows x64, replace all i686 above with x86_64 .

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

+6
source

I recommend you create raptor2 using Visual Studio. I did it successfully for Visual Studio 2017 x64 as follows:

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) 

edit 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 reference path, for example. C:\thirdparty\vs2017\x64\raptor2

Run the INSTALL target in Visual Studio.

If you do not want to perform these steps manually, you can simply download the pre-build version here .

0
source

Source: https://habr.com/ru/post/1275805/


All Articles