Mail Archives: cygwin/2010/02/08/03:50:25
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 -