Description
Version: 13.6.0
Platform: Darwin kusti8s-iMac.local 19.0.0 Darwin Kernel Version 19.0.0: Wed Sep 25 20:18:50 PDT 2019; root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64
Subsystem: NAPI
I have a really interesting issue that first came up when I tried to port my wxWidgets bindings with NAPI to Mac. It kept on reporting that 0 displays were detected. Running it through lldb
shows the CGGetOnlineDisplayList
function returns 0 displays.
I created a very minimal test example here:
make.sh
c++ -fno-exceptions '-DNAPI_DISABLE_CPP_EXCEPTIONS' '-DNODE_GYP_MODULE_NAME=test' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-DV8_DEPRECATION_WARNINGS' '-DV8_IMMINENT_DEPRECATION_WARNINGS' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DNAPI_VERSION=4' '-D_UNICODE' '-DUNICODE' '-DBUILDING_NODE_EXTENSION' -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/include/node -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/src -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/deps/openssl/config -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/deps/openssl/openssl/include -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/deps/uv/include -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/deps/zlib -I/Users/kusti8/Library/Caches/node-gyp/13.6.0/deps/v8/include -I/Users/kusti8/Documents/GitHub/node-wx-napi/node_modules/node-addon-api -Os -gdwarf-2 -mmacosx-version-min=10.9 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -fno-common -fvisibility-inlines-hidden -MMD -MF main.o.d.raw -c -o main.o main.cpp
c++ -bundle -undefined dynamic_lookup -Wl,-no_pie -Wl,-search_paths_first -mmacosx-version-min=10.9 -arch x86_64 -L. -stdlib=libc++ -o out.node main.o -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL -framework Security -framework ApplicationServices -framework WebKit -framework QuartzCore -framework CoreGraphics
And then main.cpp
#include <ApplicationServices/ApplicationServices.h>
#include <napi.h>
Napi::Value desktopSize(const Napi::CallbackInfo &info)
{
uint32_t numDisplays = 0;
CGGetOnlineDisplayList(0, NULL, &numDisplays);
printf("Displays %d\n", numDisplays);
printf("Displays %d\n", numDisplays);
return Napi::Value();
}
Napi::Object Init(Napi::Env env, Napi::Object exports)
{
exports.Set("desktopSize", Napi::Function::New(env, desktopSize));
return exports;
}
NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
int main(int argc, char **argv)
{
uint32_t numDisplays = 0;
CGGetOnlineDisplayList(0, NULL, &numDisplays);
printf("Displays %d\n", numDisplays);
return 0;
}
When calling this through node, displays is printed as 0. However, when I remove -bundle
in the linking phase, comment out everything above int main(int argc, char **argv)
and run it as an executable, it prints out the correct number of displays: 1.
I don't know anything about how Node works on the inside, but to me it looks like some sort of sandboxing thing, but I really have no idea. Or maybe I'm forgetting a compiler flag.
Thanks,
Gustav