Native add-on compilation error in NODE_MODULE function on 12.0.0, works on 11.15.0 - node.js

I'm maintaining the aerospike package, a client SDK for the Aerospike No-SQL database. On Node.js versions up to and including v11.15.0 this package compiles and works fine. But starting with v12.0.0 I'm getting a compile time error when building the native add-on, that I haven't been able to resolve.
The error occurs in this function (slightly abbreviated):
void Aerospike(Handle<Object> exports, Handle<Object> module)
{
AerospikeClient::Init();
export("client", Nan::New<FunctionTemplate>(client)->GetFunction());
// more exports
}
NODE_MODULE(aerospike, Aerospike)
And the error I'm getting is:
CXX(target) Release/obj.target/aerospike/src/main/aerospike.o
../src/main/aerospike.cc:102:6: error: variable has incomplete type 'void'
void Aerospike(Handle<Object> exports, Handle<Object> module)
^
../src/main/aerospike.cc:102:23: error: 'Object' does not refer to a value
void Aerospike(Handle<Object> exports, Handle<Object> module)
^
/Users/jhecking/.node-gyp/12.0.0/include/node/v8.h:3356:17: note: declared here
class V8_EXPORT Object : public Value {
^
../src/main/aerospike.cc:102:16: error: use of undeclared identifier 'Handle'
void Aerospike(Handle<Object> exports, Handle<Object> module)
^
../src/main/aerospike.cc:102:31: error: use of undeclared identifier 'exports'
void Aerospike(Handle<Object> exports, Handle<Object> module)
^
../src/main/aerospike.cc:102:47: error: 'Object' does not refer to a value
void Aerospike(Handle<Object> exports, Handle<Object> module)
^
/Users/jhecking/.node-gyp/12.0.0/include/node/v8.h:3356:17: note: declared here
class V8_EXPORT Object : public Value {
^
../src/main/aerospike.cc:102:40: error: use of undeclared identifier 'Handle'
void Aerospike(Handle<Object> exports, Handle<Object> module)
^
../src/main/aerospike.cc:102:55: error: use of undeclared identifier 'module'
void Aerospike(Handle<Object> exports, Handle<Object> module)
^
../src/main/aerospike.cc:102:62: error: expected ';' after top level declarator
void Aerospike(Handle<Object> exports, Handle<Object> module)
^
;
8 errors generated.
The module uses the older C++ add-on API, not n-api. I'm using the latest version nan v2.13.2.
The error can also be seen in this Travis CI job: https://travis-ci.org/aerospike/aerospike-client-nodejs/jobs/523788617.
The full source code is here: https://github.com/aerospike/aerospike-client-nodejs/blob/2b9554d1158abda58c17cfbd0438d78f0212ef9e/src/main/aerospike.cc#L102

The correct signature for the second arg of NODE_MODULE is void InitializerFunction(Local<Object> exports[, Local<Value> module]) (ref). Handle was removed from v8; it's replacement is Local.
If you're not upgrading to N-API, NAN is a good way to avoid these changes.

Related

Cross-compile of CPython 3.8 fails at _socket module

I am trying to cross-compile CPython 3.8 using Android NDK toolchains with enabled _socket module but unfortunately compilation failes at:
../Modules/socketmodule.c:6739:5: error: invalid use of undefined type 'struct if_nameindex'
for (i = 0; ni[i].if_index != 0 && i < INT_MAX; i++) {
^
../Modules/socketmodule.c:6739:19: error: dereferencing pointer to incomplete type
for (i = 0; ni[i].if_index != 0 && i < INT_MAX; i++) {
^
../Modules/socketmodule.c:6753:17: error: invalid use of undefined type 'struct if_nameindex'
ni[i].if_index, PyUnicode_DecodeFSDefault, ni[i].if_name);
^
../Modules/socketmodule.c:6753:19: error: dereferencing pointer to incomplete type
ni[i].if_index, PyUnicode_DecodeFSDefault, ni[i].if_name);
^
../Modules/socketmodule.c:6753:17: error: invalid use of undefined type 'struct if_nameindex'
ni[i].if_index, PyUnicode_DecodeFSDefault, ni[i].if_name);
^
../Modules/socketmodule.c:6753:62: error: dereferencing pointer to incomplete type
ni[i].if_index, PyUnicode_DecodeFSDefault, ni[i].if_name);
^
Whithout _socket module the whole cross-compilation works well, there are no errors.
Problem solved using the latest r23b version of Android NDK.

How to fix v8 deprecated GetFunction?

I'm trying to repair node-osmium so that it works with Node 12 as I've got some old code I'd like to run.
v8 has now fully deprecated a lot of APIs that do not signal failure properly. These were previously only warnings of deprecation soon, they're now errors so it will no longer build. I (think I've) fixed most of these by following this CPP STYLE GUIDE.md's use maybe version of v8 APIs section.
But, i'm stuck with this error for GetFunction:
../src/utils.hpp:39:67: error: no matching function for call to ‘v8::FunctionTemplate::GetFunction()’
Nan::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(T::constructor)->GetFunction(), 1, &ext);
I assume it's a similar fix as the other functions, but where do I get the context from in this constructor?
extract from node-osmium/src/utils.hpp:
namespace node_osmium {
template<class T>
auto unwrap(const v8::Local<v8::Object>& object) -> decltype(Nan::ObjectWrap::Unwrap<T>(object)->get()) {
return Nan::ObjectWrap::Unwrap<T>(object)->get();
}
template<class T, class... Args>
v8::Local<v8::Object> new_external(Args&&... args) {
Nan::EscapableHandleScope scope;
v8::Local<v8::Value> ext = Nan::New<v8::External>(new T(std::forward<Args>(args)...));
Nan::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(T::constructor)->GetFunction(context), 1, &ext);
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Buffer instance");
return scope.Escape(maybe_local.ToLocalChecked());
}
v8::Local<v8::Value> create_js_box(const osmium::Box& box);
osmium::osm_entity_bits::type object_to_entity_bits(v8::Local<v8::Object> options);
} // namespace node_osmium

error: expected nested-name-specifier when compile breakpad android sample app

When I try to compile android sample app of breakpad, I got this error and have no idea how to resolve it. I'm using Mac OSX 10.11 and android ndk r10e. Many Thanks in advance.
jni/../../google_breakpad/../../src/client/linux/log/log.cc:47:7: error: expected nested-name-specifier before 'AndroidLogBufferWriteFunc'
using AndroidLogBufferWriteFunc = int (*)(int bufID, int prio, const char *tag,
^
jni/../../google_breakpad/../../src/client/linux/log/log.cc:53:1: error: 'AndroidLogBufferWriteFunc' does not name a type
AndroidLogBufferWriteFunc g_android_log_buf_write = nullptr;
^
jni/../../google_breakpad/../../src/client/linux/log/log.cc: In function 'void logger::initializeCrashLogWriter()':
jni/../../google_breakpad/../../src/client/linux/log/log.cc:60:3: error: 'g_android_log_buf_write' was not declared in this scope
g_android_log_buf_write = reinterpret_cast<AndroidLogBufferWriteFunc>(
^
jni/../../google_breakpad/../../src/client/linux/log/log.cc:60:46: error: 'AndroidLogBufferWriteFunc' does not name a type
g_android_log_buf_write = reinterpret_cast<AndroidLogBufferWriteFunc>(
^
jni/../../google_breakpad/../../src/client/linux/log/log.cc: In function 'int logger::writeToCrashLog(const char*)':
jni/../../google_breakpad/../../src/client/linux/log/log.cc:68:7: error: 'g_android_log_buf_write' was not declared in this scope
if (g_android_log_buf_write) {

node-gyb build error on hello world

I was trying to compile the node hello world addon and when I call
node-gyp configure build it generates several errors.
../binding.cc:6:19: error: unknown type name 'FunctionCallbackInfo'
void Method(const FunctionCallbackInfo<Value>& args) {
^
../binding.cc:6:39: error: expected ')'
void Method(const FunctionCallbackInfo<Value>& args) {
^
../binding.cc:6:12: note: to match this '('
void Method(const FunctionCallbackInfo<Value>& args) {
^
../binding.cc:8:15: error: no matching constructor for initialization of 'v8::HandleScope'
HandleScope scope(isolate);
^ ~~~~~~~
/***/***/.node-gyp/0.10.36/deps/v8/include/v8.h:473:3: note: candidate constructor not viable: no known conversion from 'v8::Isolate *' to 'const v8::HandleScope' for 1st
argument
HandleScope(const HandleScope&);
^
/****/***/.node-gyp/0.10.36/deps/v8/include/v8.h:448:3: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
HandleScope();
^
../binding.cc:9:3: error: use of undeclared identifier 'args'
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
^
../binding.cc:9:37: error: no member named 'NewFromUtf8' in 'v8::String'
args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world"));
What can be the problem?
The problem is that the example assumes you're running Node 0.12, but you're running Node 0.10 (0.10.36 by the looks of it). There have been big (backward-incompatible) changes in the way addons are structured in Node 0.12.
Here's the 0.10-compatible version: https://github.com/joyent/node/blob/aa35564ca1c9f3854bc5f7983f2f00cb51f67ffe/test/addons/hello-world/binding.cc
An awesome package that will take care of a lot of the differences between Node versions is nan.

errors when trying to build in cygwin

Considering none of the code is my own, I feel helpless. It's an open source tool, and I can't use it.
This is the tool : http://www.gnucap.org/devel/gnucap-2013-04-23.tar.gz
And these are the errors I get when building on Cygwin (Win 7, 64b) :
$ ./configure
Configuring gnucap using --prefix=/usr/local
include
lib
In file included from /usr/include/readline/readline.h:35:0,
from test_readline.cc:2:
/usr/include/readline/rltypedefs.h:64:28: error: typedef ‘rl_getc_func_t’ is initialized (use decltype instead)
typedef int rl_getc_func_t PARAMS((FILE *));
^
/usr/include/readline/rltypedefs.h:64:28: error: ‘FILE’ was not declared in this scope
/usr/include/readline/rltypedefs.h:64:28: error: expected primary-expression before ‘)’ token
typedef int rl_getc_func_t PARAMS((FILE *));
^
/usr/include/readline/readline.h:419:20: error: ‘FILE’ was not declared in this scope
extern int rl_getc PARAMS((FILE *));
^
/usr/include/readline/readline.h:419:20: error: expected primary-expression before ‘)’ token
extern int rl_getc PARAMS((FILE *));
^
In file included from test_readline.cc:2:0:
/usr/include/readline/readline.h:542:8: error: ‘FILE’ does not name a type
extern FILE *rl_instream;
^
/usr/include/readline/readline.h:543:8: error: ‘FILE’ does not name a type
extern FILE *rl_outstream;
^
/usr/include/readline/readline.h:565:8: error: ‘rl_getc_func_t’ does not name a type
extern rl_getc_func_t *rl_getc_function;
^
/usr/include/readline/readline.h:867:3: error: ‘FILE’ does not name a type
FILE *inf;
^
/usr/include/readline/readline.h:868:3: error: ‘FILE’ does not name a type
FILE *outf;
^
either libtermcap or libreadline is missing - not using readline
modelgen
main
apps
In file included from /usr/include/readline/readline.h:35:0,
from test_readline.cc:2:
/usr/include/readline/rltypedefs.h:64:28: error: typedef ‘rl_getc_func_t’ is initialized (use decltype instead)
typedef int rl_getc_func_t PARAMS((FILE *));
^
/usr/include/readline/rltypedefs.h:64:28: error: ‘FILE’ was not declared in this scope
/usr/include/readline/rltypedefs.h:64:28: error: expected primary-expression before ‘)’ token
typedef int rl_getc_func_t PARAMS((FILE *));
^
/usr/include/readline/readline.h:419:20: error: ‘FILE’ was not declared in this scope
extern int rl_getc PARAMS((FILE *));
^
/usr/include/readline/readline.h:419:20: error: expected primary-expression before ‘)’ token
extern int rl_getc PARAMS((FILE *));
^
In file included from test_readline.cc:2:0:
/usr/include/readline/readline.h:542:8: error: ‘FILE’ does not name a type
extern FILE *rl_instream;
^
/usr/include/readline/readline.h:543:8: error: ‘FILE’ does not name a type
extern FILE *rl_outstream;
^
/usr/include/readline/readline.h:565:8: error: ‘rl_getc_func_t’ does not name a type
extern rl_getc_func_t *rl_getc_function;
^
/usr/include/readline/readline.h:867:3: error: ‘FILE’ does not name a type
FILE *inf;
^
/usr/include/readline/readline.h:868:3: error: ‘FILE’ does not name a type
FILE *outf;
^
either libtermcap or libreadline is missing - not using readline
done
Any help will be great. I feel helpless. If you can suggest resources so I can learn to fix such errors on my own, that would be teaching me how to fish..
You have to include stdio.h in lib/test_readline.cc to define FILE.

Resources