我有一个支持OSX的本机库,在低于12的版本上一切正常。
但是可悲的是,在节点12或更高版本上,它总是返回0而不是值。
Binding.gyp
{
'targets': [{
'target_name': 'testlib',
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ],
'xcode_settings': {
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
'CLANG_CXX_LIBRARY': 'libc++',
'MACOSX_DEPLOYMENT_TARGET': '10.7',
},
'include_dirs': [
'<!@(node -p "require(\'node-addon-api\').include")',
],
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
'cflags': [
'-Wall',
'-Wparentheses',
'-Winline',
'-Wbad-function-cast',
'-Wdisabled-optimization'
],
'conditions': [
['OS == "mac"', {
'cflags+': ['-fvisibility=hidden'],
'xcode_settings': {
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
},
'include_dirs': [
'<!@(node -p "require(\'node-addon-api\').include")',
'System/Library/Frameworks/CoreFoundation.Framework/Headers',
'System/Library/Frameworks/Carbon.Framework/Headers',
'System/Library/Frameworks/ApplicationServices.framework/Headers',
'System/Library/Frameworks/OpenGL.framework/Headers',
],
'link_settings': {
'libraries': [
'-framework Carbon',
'-framework CoreFoundation',
'-framework ApplicationServices',
'-framework OpenGL'
]
}
}],
],
'sources': [
'src/main.cpp',
'src/main/screen.c',
]
}]
}
screen.c
#if defined(IS_MACOSX)
#include <ApplicationServices/ApplicationServices.h>
#endif
MMSize getDisplaySize(void)
{
#if defined(IS_MACOSX)
CGDirectDisplayID displayID = CGMainDisplayID();
return MMSizeMake(CGDisplayPixelsWide(displayID),
CGDisplayPixelsHigh(displayID));
输出11及以下:
{ width: 1920, height: 1200 }
输出Nodejs 12 +:
{ width: 0, height: 0 }
软件包版本:
我添加了有关代码的更多信息,这可能会有所帮助。
有什么想法吗?
致谢