public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* DLL Linking Problem
@ 2002-08-27  1:24 Niraj Agarwal
  2002-08-27  2:50 ` Gerrit P. Haase
  0 siblings, 1 reply; 7+ messages in thread
From: Niraj Agarwal @ 2002-08-27  1:24 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 636 bytes --]

Hi All,

I have written a simple dll using VC++ compiler and now i am trying to link the same to my code running in cygwin environment.

I have created a definition file and using dlltool i have generated .a file. 
I was able to compile and link program successfully but i am facing one problem when i am trying to run the program. it is saying that entry point for the funtion is not defined in the dll.

Note :The dll file, def file and sample program using dll is also attached.

Please help me in this regard.

Thanks and best regards,
Niraj Agarwal
Senior Member Technical Staff
Network Programs(I) Ltd.
Noida




[-- Attachment #2: TestDll.cpp --]
[-- Type: text/x-c, Size: 783 bytes --]

// TestDll.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "TestDll.h"
#include <stdio.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;
}


// This is an example of an exported variable
//TESTDLL_API int nTestDll=0;

// This is an example of an exported function.
TESTDLL_API  printVal()
{
	printf("Hello World");
	//return 42;
}

// This is the constructor of a class that has been exported.
// see TestDll.h for the class definition
CTestDll::CTestDll()
{ 
	return; 
}


[-- Attachment #3: TestDll.def --]
[-- Type: text/plain, Size: 37 bytes --]

LIBRARY TestDll.dll
EXPORTS
printVal

[-- Attachment #4: TestDll.h --]
[-- Type: text/x-c++, Size: 809 bytes --]


// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the TESTDLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// TESTDLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dllexport)
#else
#define TESTDLL_API __declspec(dllimport)
#endif

// This class is exported from the TestDll.dll
class TESTDLL_API CTestDll {
public:
	CTestDll(void);
	// TODO: add your methods here.
};

//extern TESTDLL_API int nTestDll;

TESTDLL_API  printVal();


[-- Attachment #5: TestMain.c --]
[-- Type: text/x-c, Size: 44 bytes --]

extern printVal();

main()
{
printVal();
}


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

* Re: DLL Linking Problem
  2002-08-27  1:24 DLL Linking Problem Niraj Agarwal
@ 2002-08-27  2:50 ` Gerrit P. Haase
  2002-08-27  3:54   ` Niraj Agarwal
  0 siblings, 1 reply; 7+ messages in thread
From: Gerrit P. Haase @ 2002-08-27  2:50 UTC (permalink / raw)
  To: Niraj Agarwal; +Cc: cygwin

Niraj schrieb:

[dll problems with simple dll]

Your example is not simple, see this really simple example:

TestDll.c:
==========
#include <stdio.h>
void  printVal()
{
        printf("Hello World!");
}

TestDll.h:
==========
void printVal();

testmain.c:
===========
#include "TestDll.h"
int main()
{
        printVal();
        return 1;
}


$ gcc -c TestDll.c -o TestDll.o

$ gcc -shared -o cygTestDll.dll \
      -Wl,--out-implib=libTestDll.dll.a \
      -Wl,--export-all-symbols \
      -Wl,--enable-auto-import \
      -Wl,--whole-archive TestDll.o \
      -Wl,--no-whole-archive
Creating library file: libTestDll.dll.a

$ gcc -o testmain testmain.c -L. -lTestDll

$ ./testmain
Hello World!


Gerrit
-- 
=^..^=
Attachment:
testmain.c
Description: Text document
Attachment:
TestDll.h
Description: Text document
Attachment:
TestDll.c
Description: Text document
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

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

* Re: DLL Linking Problem
  2002-08-27  2:50 ` Gerrit P. Haase
@ 2002-08-27  3:54   ` Niraj Agarwal
  2002-08-27  4:29     ` Gerrit P. Haase
  2002-08-27 11:32     ` news
  0 siblings, 2 replies; 7+ messages in thread
From: Niraj Agarwal @ 2002-08-27  3:54 UTC (permalink / raw)
  To: Gerrit P. Haase; +Cc: cygwin

Hi Gerrit,

This is really simple. But problem is that i want to include the dll prepared using vc++ in program written in cygwin environment.

Please help me in this regard.

Niraj
----- Original Message ----- 
From: "Gerrit P. Haase" <freeweb@nyckelpiga.de>
To: "Niraj Agarwal" <niraja@npi.stpn.soft.net>
Cc: <cygwin@cygwin.com>
Sent: Tuesday, August 27, 2002 3:20 PM
Subject: Re: DLL Linking Problem


> Niraj schrieb:
> 
> [dll problems with simple dll]
> 
> Your example is not simple, see this really simple example:
> 
> TestDll.c:
> ==========
> #include <stdio.h>
> void  printVal()
> {
>         printf("Hello World!");
> }
> 
> TestDll.h:
> ==========
> void printVal();
> 
> testmain.c:
> ===========
> #include "TestDll.h"
> int main()
> {
>         printVal();
>         return 1;
> }
> 
> 
> $ gcc -c TestDll.c -o TestDll.o
> 
> $ gcc -shared -o cygTestDll.dll \
>       -Wl,--out-implib=libTestDll.dll.a \
>       -Wl,--export-all-symbols \
>       -Wl,--enable-auto-import \
>       -Wl,--whole-archive TestDll.o \
>       -Wl,--no-whole-archive
> Creating library file: libTestDll.dll.a
> 
> $ gcc -o testmain testmain.c -L. -lTestDll
> 
> $ ./testmain
> Hello World!
> 
> 
> Gerrit
> -- 
> =^..^=

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

* Re: DLL Linking Problem
  2002-08-27  3:54   ` Niraj Agarwal
@ 2002-08-27  4:29     ` Gerrit P. Haase
  2002-08-27 11:32     ` news
  1 sibling, 0 replies; 7+ messages in thread
From: Gerrit P. Haase @ 2002-08-27  4:29 UTC (permalink / raw)
  To: Niraj Agarwal; +Cc: cygwin

Niraj schrieb:

> This is really simple. But problem is that i want to include
> the dll prepared using vc++ in program written in cygwin
> environment.

Probably the symbols are not exported from your VC DLL?
I'm sorry, but I cannot tell you how to create a good
(exporting) DLL with VC.


Gerrit
-- 
=^..^=


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

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

* Re: DLL Linking Problem
  2002-08-27  3:54   ` Niraj Agarwal
  2002-08-27  4:29     ` Gerrit P. Haase
@ 2002-08-27 11:32     ` news
  1 sibling, 0 replies; 7+ messages in thread
From: news @ 2002-08-27 11:32 UTC (permalink / raw)
  To: cygwin

On 27 Aug 2002, "Niraj Agarwal" <niraja@npi.stpn.soft.net>
wrote: 

> This is really simple. But problem is that i want to include
> the dll prepared using vc++ in program written in cygwin
> environment. 

I have little time, and have also knackered my hand, so can't 
really try anything, but are you sure this is not a case of the 
fun. name in the dll (c++) being decorated, and c not knowing 
anything about it? What happens if you compile and link your 
test program with vc++?

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

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

* RE: Dll linking problem
@ 2002-08-30  7:14 Schaible, Jörg
  0 siblings, 0 replies; 7+ messages in thread
From: Schaible, Jörg @ 2002-08-30  7:14 UTC (permalink / raw)
  To: cygwin

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1921 bytes --]

Hi Preeti,

> A dll written using VC++ environment is exporting a complete class.
> The same is being accessed through cygwin, but it is unable to link to
> the class functions.
> However if the functions are declared inline in the dll, cygwin
> application is able to link successfully with the class functions.
> 
> The same dll can be accessed successfully through a program written in
> VC++ environment.
> 
> Please let me know if anyone can suggest an analysis or a solution.

Since the functions are inline, every compilation unit has its own version and the linker removes any duplicates for the execution unit. If the compiler is smart enough (or the functions easy enough) the code of the function is included everywhere the inlined function is called increasing space gaining speed. The result is either no explicit function at all (because the code is "inlined") or each execution unit (dll or executable) has its own set of functions.

You will get problems if not all of the functions are inline or the compiler ignores the "inline" (which is just a suggestion for the compiler, no strict commend). If one function is not inline, the linker will try to call the function in the DLL which fails, since the linker symbol generation of C++ symbols is not standardized (well, not only the name, but also at which position the implicit "this" parameter is provided, how the internal data layout for the class is realized and how the vtable is implemented). Another problems are thrown execptions from the DLL.  There is also no standardized way how they are implemented.  The standard just defines how they have to work!

==> DO NOT TRY LINK C++ DLL's FROM DIFFERENT COMPILERS!

Regards,
Jörg

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

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

* Dll linking problem
@ 2002-08-30  4:30 Preeti Agarwal
  0 siblings, 0 replies; 7+ messages in thread
From: Preeti Agarwal @ 2002-08-30  4:30 UTC (permalink / raw)
  To: cygwin

Hi,

A dll written using VC++ environment is exporting a complete class.
The same is being accessed through cygwin, but it is unable to link to
the class functions.
However if the functions are declared inline in the dll, cygwin
application is able to link successfully with the class functions.

The same dll can be accessed successfully through a program written in
VC++ environment.

Please let me know if anyone can suggest an analysis or a solution.

Thanks
Preeti Agarwal


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

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

end of thread, other threads:[~2002-08-30  7:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-27  1:24 DLL Linking Problem Niraj Agarwal
2002-08-27  2:50 ` Gerrit P. Haase
2002-08-27  3:54   ` Niraj Agarwal
2002-08-27  4:29     ` Gerrit P. Haase
2002-08-27 11:32     ` news
2002-08-30  4:30 Dll linking problem Preeti Agarwal
2002-08-30  7:14 Schaible, Jörg

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