dropbox / djinni

A tool for generating cross-language type declarations and interface bindings.
Apache License 2.0
2.88k stars 488 forks source link

Unable to build from node-gyp : cannot use typeid with -fno-rtti / jni.h file not found #361

Closed omatrot closed 6 years ago

omatrot commented 6 years ago

I'm using Djinni in the context of a react native project. My starting point is this repo where Djinni is linked as a submodule. In on macOS High Sierra.

When I run npm install, it tries to build Djinni...

...
gyp verb command build []
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir /Users/omatrot/.node-gyp/7.10.1
gyp verb `which` succeeded for `make` /usr/bin/make
gyp info spawn make
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
  c++ '-DNODE_GYP_MODULE_NAME=djinni_jni' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' -I/Users/omatrot/.node-gyp/7.10.1/include/node -I/Users/omatrot/.node-gyp/7.10.1/src -I/Users/omatrot/.node-gyp/7.10.1/deps/uv/include -I/Users/omatrot/.node-gyp/7.10.1/deps/v8/include -I../deps/djinni/support-lib/jni  -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++0x -stdlib=libc++ -fno-rtti -fno-exceptions -fno-threadsafe-statics -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/djinni_jni/deps/djinni/support-lib/jni/djinni_support.o.d.raw   -c -o Release/obj.target/djinni_jni/deps/djinni/support-lib/jni/djinni_support.o ../deps/djinni/support-lib/jni/djinni_support.cpp
In file included from ../deps/djinni/support-lib/jni/djinni_support.cpp:18:
In file included from ../deps/djinni/support-lib/jni/djinni_support.hpp:26:
../deps/djinni/support-lib/jni/../proxy_cache_interface.hpp:137:49: error: cannot use typeid with -fno-rtti
        ~Handle() { if (m_obj) cleanup(m_cache, typeid(TagType), get_unowning(m_obj)); }
                                                ^
In file included from ../deps/djinni/support-lib/jni/djinni_support.cpp:18:
../deps/djinni/support-lib/jni/djinni_support.hpp:28:10: fatal error: 'jni.h' file not found
#include <jni.h>
         ^~~~~~~
2 errors generated.
make: *** [Release/obj.target/djinni_jni/deps/djinni/support-lib/jni/djinni_support.o] Error 1

I'm sure that I could find a way to not use -fno-rtti but what about the missing file ? Are these 2 problems related ?

Thanks for your help.

omatrot commented 6 years ago

The first problem is a node-gyp related problem. I modified ~/.node-gyp/7.10.1/include/node/common.gypi' in line 367 to set YES instead of NO

'GCC_ENABLE_CPP_RTTI': 'YES', # -fno-rtti

omatrot commented 6 years ago

The second problem was solved by creating an environment variable: export CPLUS_INCLUDE_PATH=$(/usr/libexec/java_home)/include:$(/usr/libexec/java_home)/include/darwin/:$(cd "dirname "0"" && pwd)/deps/djinni/support-lib/cpp

There has been additional problems all solved by modifying common.gpyi:

'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',

'OTHER_CFLAGS': [
            '-fno-strict-aliasing',
            '-fobjc-arc'
          ],
omatrot commented 6 years ago

All problems solved on macOS Sierra

fbadaud commented 6 years ago

for Linux build (Ubuntu 16.04): we need to fix several issues at 3 different locations: -in our node-gyp installation: common.gypi line for 'OS in Linux .... use those flags: 'cflags_cc': [ '-frtti','-fexceptions', '-std=gnu++0x' ],