From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9549 invoked by alias); 22 Aug 2008 02:04:38 -0000 Received: (qmail 8499 invoked by uid 22791); 22 Aug 2008 02:04:34 -0000 X-Spam-Check-By: sourceware.org Received: from dessent.net (HELO dessent.net) (69.60.119.225) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 22 Aug 2008 02:03:58 +0000 Received: from localhost.localdomain ([127.0.0.1] helo=dessent.net) by dessent.net with esmtp (Exim 4.50) id 1KWM0J-00077p-R9; Fri, 22 Aug 2008 02:03:55 +0000 Message-ID: <48AE1E8A.12ADDE12@dessent.net> Date: Fri, 22 Aug 2008 02:12:00 -0000 From: Brian Dessent Reply-To: gcc-help@gcc.gnu.org X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) MIME-Version: 1.0 To: Seyran Avanesyan CC: gcc-help@gcc.gnu.org Subject: Re: extern "C" From command line References: <200808191257.28899.zepm@gatech.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-08/txt/msg00229.txt.bz2 Seyran Avanesyan wrote: > Hi, Please don't hijack threads; start a new thread. Changing the subject line does not accomplish this. The mailing list archives on the gcc website and any threaded email client will show your message as a reply in a completely unrelated thread. > Is there any way to make exported function names unmangled without using > extern "C"? > > I'm compiling c++ file to a dll. Exported functions doesn't have extern > "C" specified for them, so their names got mangled. > The file cannot be edited. > > gcc -x c++ source.cpp -o source.o > gcc -shared -o source.dll other_source.o source.o > > If I put required names into .def file but compile as c++ file, because > of mangling I got errors: "Can not export ZZZZ: symbol not defined" The mangling is there for a reason. If you exported a function with C++ linkage but without its name mangled then it's very likely that you could call it from a compiler with a different C++ ABI, such as MSVC, and that would fail. Mangling prevents this, because it requires that to call the function you have a compiler with compatible ABI. If your complaint is simply that you don't want to put mangled names in the .def file, then I must ask: why use a .def file at all? It's usually not needed. The GNU linker has auto-export enabled by default which causes all symbols to be exported if __declspec(dllexport) is not used anywhere. And if __declspec(dllexport) is used, then the source itself already controls what functions to be exported so the .def file is extraneous. Brian