delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/02/08/03:50:25

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL,BAYES_00
X-Spam-Check-By: sourceware.org
From: Martin Henne <martin DOT henne AT web DOT de>
To: cygwin AT cygwin DOT com
Subject: build DLL that can be used by MinGW
Date: Mon, 8 Feb 2010 09:50:14 +0100
User-Agent: KMail/1.12.4 (Linux/2.6.31-19-generic; KDE/4.3.5; i686; ; )
MIME-Version: 1.0
Message-Id: <201002080950.14971.martin.henne@web.de>
X-Sender: martin DOT henne AT web DOT de
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Hello,

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;
  sayhello();
  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:

1
42
2

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
'std::cout'.

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

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...



Martin


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019