如何将 gnu-libstdc++ 包含在 JNI Java swing 项目中



我正在尝试在我的 swing 项目中包含一个C++库。

当我使用 stdio.h 编译 jnilib/so 时,它可以正常工作:

gcc -shared -o libhello.jnilib hello.c -fPIC -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include/darwin

我正在尝试导入并需要使用 gnu-libstdc++/4.9如何链接我的 Java 项目?

当我尝试构建 jni 文件时:

It will throw this:
test.c:5:10: fatal error: 'string' file not found
#include <string>

编辑

现在,当我链接到此内容时:

-I /Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include

它会抛出此错误:

/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:69:37: error: use of undeclared identifier '_U'
    static const mask graph     = _P | _U | _L | _N;
                                       ^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:69:42: error: use of undeclared identifier '_L'
    static const mask graph     = _P | _U | _L | _N;
                                            ^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:69:47: error: use of undeclared identifier '_N'
    static const mask graph     = _P | _U | _L | _N;
                                                 ^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:70:32: error: use of undeclared identifier '_C'
    static const mask cntrl     = _C;
                                  ^
/Users/tnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include/bits/ctype_base.h:71:32: error: use of undeclared identifier '_P'
    static const mask punct     = _P;
                                  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

编辑2

添加-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/platforms/android-17/arch-x86/usr/include后,现在它会抛出:

/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:164:11: error: no member named 'vfwscanf' in the global namespace
  using ::vfwscanf;
        ~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:170:11: error: no member named 'vswscanf' in the global namespace
  using ::vswscanf;
        ~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:174:11: error: no member named 'vwscanf' in the global namespace
  using ::vwscanf;
        ~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwchar:191:11: error: no member named 'wcstof' in the global namespace
  using ::wcstof;
        ~~^
In file included from hello.cpp:6:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/sstream:38:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/istream:38:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:44:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_ios.h:37:
In file included from /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/locale_facets.h:39:
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cwctype:89:11: error: no member named 'iswblank' in the global namespace; did you
      mean 'isblank'?
  using ::iswblank;
        ~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/platforms/android-17/arch-x86/usr/include/ctype.h:88:5: note: 'isblank' declared here
int     isblank(int);
        ^
1 warning and 5 errors generated.

编辑3好的,我想我更接近一点,这是更新的包括...

gcc -shared -o libhello.jnilib hello.cpp -fPIC 
-I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include 
-I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include/darwin 
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/backward 
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits 
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/debug 
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/decimal 
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/experimental 
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/ext 
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/parallel 
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/profile 
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/tr1 
-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/tr2

但现在它抛出:

/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/tr1/stdio.h:8:10: fatal error: 'tr1/cstdio' file not found #include

编辑

好的,将包含设置为基本目录包含-I /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include现在抛出:

/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:98:11: error: no member named 'FILE' in the global namespace
  using ::FILE;
        ~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:99:11: error: no member named 'fpos_t' in the global namespace
  using ::fpos_t;
        ~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:101:11: error: no member named 'clearerr' in the global namespace
  using ::clearerr;
        ~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:102:11: error: no member named 'fclose' in the global namespace
  using ::fclose;
        ~~^
/Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/cstdio:103:11: error: no member named 'feof' in the global namespace
  using ::feof;
        ~~^
clang++ -shared -o libhello.jnilib hello.cpp -fPIC -funwind-tables -no-canonical-prefixes -fexceptions -frtti -Os -g -DNDEBUG -DNDEBUG -fPIC -std=gnu++11 -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/include/darwin -isystem /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include -isystem /Users/timnuwin/Documents/ndk/android-ndk-r12b/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -I /Users/timnuwin/Documents/ndk/android-ndk-r12b/platforms/android-17/arch-x86/usr/include

该cmd能够创建我的jnilib文件。 :D3天后呵呵

最新更新