public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Create dll using gcc
@ 2003-09-02 11:49 Christian Neise
  2003-09-02 14:38 ` Igor Pechtchanski
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Neise @ 2003-09-02 11:49 UTC (permalink / raw)
  To: cygwin


Hello,

i am trying to build a dll using cygwin and gcc. The dll will be used
by a delpi application.

The dll works fine. But when allocating memory 
(e.g.: char *c = new char) the programm crashes.

When compiling the dll with visual c++ 6.0 SP5 the dll works fine -
even if allocating memory.

Any hints? 

Best regards,

Christian Neise

P.S.:

I createdthe dll the following way:
gcc  -c dll_test.cpp -o debug/dll_test.o
gcc   -shared -o debug/dll_test.dll \
-L/usr/lib \
-Wl,--export-all-symbols \
-Wl,--enable-auto-import \
-Wl,--whole-archive debug/dll_test.o \
-L/usr/lib \
-Wl,--no-whole-archive -lc -lstdc++


testdll.h:

#include <string>

 extern "C" {
      __declspec( dllexport ) BOOL APIENTRY DllMain( HANDLE hModule,
                            DWORD  ul_reason_for_call,
                            LPVOID lpReserved
         );
 }




testdll.cpp:

#include "dll_test.h"

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}



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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Create dll using gcc
  2003-09-02 11:49 Create dll using gcc Christian Neise
@ 2003-09-02 14:38 ` Igor Pechtchanski
  0 siblings, 0 replies; 2+ messages in thread
From: Igor Pechtchanski @ 2003-09-02 14:38 UTC (permalink / raw)
  To: Christian Neise; +Cc: cygwin

On Tue, 2 Sep 2003, Christian Neise wrote:

> Hello,
>
> i am trying to build a dll using cygwin and gcc. The dll will be used
> by a delpi application.
>
> The dll works fine. But when allocating memory
> (e.g.: char *c = new char) the programm crashes.
>
> When compiling the dll with visual c++ 6.0 SP5 the dll works fine -
> even if allocating memory.
>
> Any hints?
>
> Best regards,
>
> Christian Neise
>
> P.S.:
>
> I createdthe dll the following way:
> gcc  -c dll_test.cpp -o debug/dll_test.o
> gcc   -shared -o debug/dll_test.dll \
> -L/usr/lib \
> -Wl,--export-all-symbols \
> -Wl,--enable-auto-import \
> -Wl,--whole-archive debug/dll_test.o \
> -L/usr/lib \
> -Wl,--no-whole-archive -lc -lstdc++
>
>
> testdll.h:
>
> #include <string>
>
>  extern "C" {
>       __declspec( dllexport ) BOOL APIENTRY DllMain( HANDLE hModule,
>                             DWORD  ul_reason_for_call,
>                             LPVOID lpReserved
>          );
>  }
>
>
>
>
> testdll.cpp:
>
> #include "dll_test.h"
>
> BOOL APIENTRY DllMain( HANDLE hModule,
>                        DWORD  ul_reason_for_call,
>                        LPVOID lpReserved
>                                          )
> {
>     switch (ul_reason_for_call)
>         {
>                 case DLL_PROCESS_ATTACH:
>                 case DLL_THREAD_ATTACH:
>                 case DLL_THREAD_DETACH:
>                 case DLL_PROCESS_DETACH:
>                         break;
>     }
>     return TRUE;
> }

The DLL you created will require cygwin1.dll as its C runtime library.
The Delphi application most likely uses MSVCRT.DLL as it's C runtime.
It's not a good idea to mix the two runtimes (in fact, that's the most
likely reason for the crashes).  If you want to use your DLL with Delphi,
you could compile it using MinGW (by passing the "-mno-cygwin" option to
gcc), but you won't get full POSIX emulation that way.
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"I have since come to realize that being between your mentor and his route
to the bathroom is a major career booster."  -- Patrick Naughton

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-09-02 14:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-02 11:49 Create dll using gcc Christian Neise
2003-09-02 14:38 ` Igor Pechtchanski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).