Search code examples
c++candroid-ndkdllexport

Error using __declspec(dllexport) : Unknown type name '__declspec'


I am trying to export a function to shared object (.so) using NDK from c++ using terminal on macOS mojave . I have installed latest versions of command line tool and Xcode.

Here's my GetNumber() which i want to export

#include <iostream>
#define DllExport __declspec(dllexport)

extern "C" {
   DllExport int GetNumber() {
      return 5 ;
   }
} 

After compiling the code using NDK , it throws the following error ,

enter image description here

I tried out clang and Xcode compiler as well as on tried same patterns on Windows and Ubuntu . I get the same error .

Tutorial i followed to export shared library using ndk


Solution

  • You should use JNIEXPORT instead of DllExport on Android platforms.

    The referenced tutorial you provided in your question is too old for current Android NDK development.