Calling Convention with a shared library for android
Asked Answered
M

1

5

I created some plugin files in C++ for my Unity3d app. So far the app was just a simple protype, so I tested only on my desktop with libraries compiled as DLL for Windows. Today I recompiled those files as .so(Shared Object) for Android(both arm and x86) and got a warning message.

warning : calling convention '__stdcall' ignored for this target [-Wignored-attributes]

1. This means all functions are compiled as __cdecl?

2. Can't I specify the calling convention in .so library?

I replaced __stdcall with __cdecl, but it also occurs a warning message.

Matildematin answered 22/9, 2015 at 14:7 Comment(0)
B
8

Both of these are non-standard historical Microsoft baggage for IA32 (they are in fact non-portable, standards compliant extensions to C and C++, implemented by Microsoft's compilers and by GCC for interoperability), for which the *NIX world has - and never had a need.

On just about all ARM systems you'll ever encounter (and all Android ones), the calling convention is dictated by the ARM Procedure Call Standard. Not surprisingly, there is no equivalent for ARM as there is no need for them.

Your best course of action is to use empty macros to make them go away.

#define __cdecl
#define __stdcall
Bobbinet answered 22/9, 2015 at 22:21 Comment(4)
Wow, thanks a lot for your very informative answer! I didn't know that. But to be honest, I got more confused now.. I can remove all the calling conventions from C++ source files, that's not a big deal. But problem is in C# sources. I'm using [DllImport] attribute in order to import my unmanaged library in C#. The default calling convention of [DllImport] is StdCall. That's why I asked the first question, so that I could match them. Do you think it is okay not to set any calling conventions in C#? I'll accept your answer firstMatildematin
You'll still need them on Windows (I imagine they have no effect for IA64). You'll need to define these macros when compiling for anything but IA32/x86 on Windows.Bobbinet
okay, I'll leave them using the macros as you said. But what I wanted to know was how to deal with C# for android.. As default setting, [DllImport("myDLL")] means [DllImport("myDLL", CallingConvention=CallingConvention.StdCall)]. I thought this might cause errors in certain situations.. Thanks anyway!Matildematin
I strongly suspect that the bindings on Android won't care: There's only ever one calling convention in use. If, for some reason it complains about their absence, arrange that your macros apply only when you build the library with a non-microsoft compiler.Bobbinet

© 2022 - 2024 — McMap. All rights reserved.