Reference a GNU C (POSIX) DLL built in GCC against Cygwin, from C#/NET

后端 未结 5 1906
闹比i
闹比i 2020-12-05 20:52

Here is what I want: I have a huge legacy C/C++ codebase written for POSIX, including some very POSIX specific stuff like pthreads. This can be compiled on Cygwin/GCC and ru

5条回答
  •  萌比男神i
    2020-12-05 21:20

    You should first try to get your simple hello world sample running. There is not much sense in trying with a huge legacy C/C++ codebase written for POSIX depending on Cygwin if you don't even get the former right. And please note that if you are linking Cygwin in you have to GPL-license your library.

    For that have a look at the documentation (e.g. you need to specify explicitly in your hello world example if you are using Cdecl (what you currently don't do)): Consuming Unmanaged DLL Functions

    On the native side you have to initialize Cygwin (see winsup/cygwin/how-cygtls-works.txt)

    Use P/Invoke to your library directly. There is no sense in PInvoking into Win32 libraries like LoadLibrary to then invoke your libraries. This just adds another layer for errors and is gaining you exactly nothing.

    Make sure you are getting the architecture right (.Net applications run 64bit by default on 64bit machines). So make sure your dlls match/support that or limit the .Net to 32bits.

    If that works try getting your other library to work. (And you will have to have some luck if you expect to use functions that mix two entirely different threading models)

提交回复
热议问题