Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <41ECE515.8030905@free.fr> Date: Tue, 18 Jan 2005 11:29:41 +0100 From: David Marteau Reply-To: daim DOT project AT free DOT fr User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 MIME-Version: 1.0 To: svoboda AT cs DOT cmu DOT edu Cc: cygwin AT sourceware DOT org Subject: Re: Building DLL's using g++, not gcc References: <200501171746 DOT 26708 DOT svoboda AT cs DOT cmu DOT edu> In-Reply-To: <200501171746.26708.svoboda@cs.cmu.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Hi, The way symbol names are built in dll differs if they are related to c call convention or to c++ call, and that could be your problem. When compiling hello.c with gcc, your exported symbol corresponds to C calling convention. When compiling dll with g++, you should declare your exported function as 'extern "C"' in hello.c. David Marteau svoboda AT cs DOT cmu DOT edu wrote: >I've been trying to build a DLL using g++, and given the problems I was >having, I decided to try a 'toy' example, which is available at: > http://cygwin.com/cygwin-ug-net/dll.html >I tweaked the two files around thusly: > > >hello.C: >----- >#include >int hello() { printf("Hello World\n");} >----- > >main.C: >----- >#include >typedef void (*fn_type)(); > >extern "C" { > int dlopen(char*); > int dlsym( int, char*); >} > >int main() { > int handle = 0; > fn_type fn = 0; > if ((handle = dlopen( "hello.dll")) == 0) { > printf( "Cannot open hello.dll\n"); > } > if ((fn = (fn_type) dlsym( handle, "hello")) == 0) { > printf( "Cannot open hello()\n"); > } > fn(); >} >----- > >This way, hello.C is a valid C or C++ application, and main.C is a >valid C++ application. I build main.exe by: > > g++ -o main main.C > >If I build hello.dll this way, it works: > > gcc -shared -o hello.dll hello.C > ./main > Hello world! > >But if I build hello.dll this way, it doesn't work: > > g++ -shared -o hello.dll hello.C > ./main > bash: [2084: 2] testaddr: Inappropriate ioctl for device > >Why? What am I doing wrong? > >~David Svoboda > > > -- 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/