This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

build DLL that can be used by MinGW


I try to produce a DLL on cygwin, that can be linked against a MinGW compiled 
program. To test with a simple example I tried the following code:

// dllfunc.h
extern "C" {
  extern void sayhello();
  extern int sumint(int a, int b);

// dllfunc.cpp
#include <iostream>
extern "C" {
  void sayhello() {
    std::cout << "I am saying hello" << std::endl;
  int sumint(int a, int b) {
    return a+b;

// main.cpp
#include <iostream>
#include "dllfunc.h"
int main() {
  std::cout << "1" << std::endl;
  std::cout << sumint(3,39) << std::endl;
  std::cout << "2" << std::endl;
  std::cout << "3" << std::endl;

Then I created the dll (within cygwin):
$> g++ -shared dllfunc.cpp -o dllfunc.dll

Then I created the application (using MinGW)
$> g++ main.cpp -L. -ldllfunc

When I start this MinGW-Application, the call output is as follows:


Then it aborts. That means, that the call to 'sumint()' whithin the
dll works, while the call to 'sayhello()' wont. The crash occurs when using

If I compile and create the dll and the application within cygwin it works:
I am saying hello

If I compile both using MinGW it works, too.
If I compile the DLL on MinGW and the application on cygwin, it works as well.

But I need to compile the DLL on cygwin and the rest on MinGW, and this does
not work. The reason is, that I need a dll that uses the cygwin-posix-layer.

What can I do?

Thank you in advance...


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]