Re: [anjuta-list] Is something like this exists for gcc/configure & friends



Hello Igor.

Am 14.04.2016 um 19:11 schrieb Igor Korot:
extern "C" makes it work as now the function will be exported without
name mangling.

However, since I need to return a C++ object this will not work as the
function has C-linkage.

What do you mean with will not work?

A pointer is a pointer. You can return a pointer to a C++ object using an extern "C" function.


So with MSVC I can use "/EXPORT:" link option to assign a name to the
exported function.

So, if I give a linker following "/EXPORT:MyFunc", MSVC will find the
appropriate function
and will export it with the name "_MyFunc", as if I use 'extern "C"'
instead of "@v MyFunc@v".

Isn't this even more complicated then declaring a extern "C" block?

You mean I can write something like this:

#ifdef WIN32
__declspec(dllexport)
#endif
MyClass *MyFunc()
{
}

and then do this:

void *dl_ptr = dlopen("my_dll" );
MYFUNC func = (MYFUNC) dlsym( dl_ptr, "MyFunc" );

and it will work. This code will find MyFunc inside libmy_dll.so
library and everything will be good?

That won't work.

PS: Have you read this page?

http://www.tldp.org/HOWTO/html_single/C++-dlopen/

You can either flatten your class and make the instance an opaque pointer (which is great for using C++ 
classes in languages other than C++) or export an abstract class (also known as an interface) to be consumed 
by C++ clients.

-- 
Mit freundlichen Grüßen
Jens Mühlenhoff

Attachment: signature.asc
Description: OpenPGP digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]