SnosMe / uiohook-napi

MIT License
162 stars 37 forks source link

Issue building binary for darwin #1

Closed BhuvanRohith closed 3 years ago

BhuvanRohith commented 3 years ago

This is the gyp file i modified for darwin -

{
    'targets': [{
            'target_name': 'uiohook_napi',
            'dependencies': ['libuiohook'],
            'sources': [
                'src/lib/addon.c',
                'src/lib/napi_helpers.c',
                'src/lib/uiohook_worker.c',
            ],
            'include_dirs': [
                'libuiohook/include',
                'src/lib',
            ]
        },
        {
            'target_name': 'libuiohook',
            'type': 'static_library',
            'sources': [
                'libuiohook/src/logger.c',
            ],
            'include_dirs': [
                'libuiohook/include',
                'libuiohook/src',
            ],
            "conditions": [
                ['OS=="darwin"', {
                    "defines": [
                        "__MACOSX_CORE__"
                    ],
                    "link_settings": {
                        "libraries": [
                            "-framework IOKit",
                            "-framework Carbon",
                            "-framework CoreFoundation"
                        ],
                    },
                    'sources': [
                        "libuiohook/src/darwin/input_helper.c",
                        "libuiohook/src/darwin/input_hook.c",
                        "libuiohook/src/darwin/post_event.c",
                        "libuiohook/src/darwin/system_properties.c"
                    ],
                    'include_dirs': [
                        'libuiohook/src/darwin'
                    ]
                }],
                ['OS=="win"', {
                    'sources': [
                        'libuiohook/src/windows/input_helper.c',
                        'libuiohook/src/windows/input_hook.c',
                        'libuiohook/src/windows/post_event.c',
                        'libuiohook/src/windows/system_properties.c'
                    ],
                    'include_dirs': [
                        'libuiohook/src/windows'
                    ]
                }],
                ['OS=="linux"', {
                    'defines': [
                        'USE_XRANDR', 'USE_EVDEV', 'USE_XT'
                    ],
                    'link_settings': {
                        'libraries': [
                            '-lX11', '-lXrandr', '-lXtst', '-lpthread', '-lXt'
                        ],
                    },
                    'cflags': ['-std=c99', '-pedantic', '-Wall', '-pthread'],
                    'sources': [
                        'libuiohook/src/x11/input_helper.c',
                        'libuiohook/src/x11/input_hook.c',
                        'libuiohook/src/x11/post_event.c',
                        'libuiohook/src/x11/system_properties.c'
                    ],
                    'include_dirs': [
                        'libuiohook/src/x11'
                    ]
                }]
            ]
        }
    ]
}

Its getting compiled fine. But, when i import it and run , it throws the following error -

_### **_dyld: lazy symbol binding failed: Symbol not found: _hook_set_dispatch_proc
  Referenced from: /Users/mahadityakaushik/crewscaleagent/electron-dist/electron-darwin-x64-napi.node
  Expected in: flat namespace

dyld: Symbol not found: _hook_set_dispatch_proc
  Referenced from: /Users/mahadityakaushik/crewscaleagent/electron-dist/electron-darwin-x64-napi.node
  Expected in: flat namespace_**_

I am not able to figure out, which library linking am i missing here. Btw it works very well with linux. Kudos

SnosMe commented 3 years ago

I don't own Mac device, that's the reason why it's not prebuilt. Open to pick up by commuinity

BhuvanRohith commented 3 years ago

Any idea when does that kind of error arise in c ?

SnosMe commented 3 years ago

Try to remove libuiohook target and merge its build steps into uiohook_napi

bthalinda commented 3 years ago

@BhuvanRohith did you found any solution ?

BhuvanRohith commented 3 years ago

Hey guys, anyone facing the similar issue on MAC , please try using this Binding.gyp. Adding the required defines in os=Mac definition resolved my issue, was able to build a Mac binary

{
  'targets': [
    {
      'target_name': 'uiohook_napi',
      'dependencies': ['uiohook'],
      "win_delay_load_hook" : "true",
      'sources': [
        'src/lib/include/uiohook.h',
        'src/lib/addon.c',
        'src/lib/napi_helpers.c',
        'src/lib/napi_helpers.h',
        'src/lib/uiohook_worker.c',
      ],
      'include_dirs': [
        'libuiohook/include',
        'src/lib',
        "<!@(node -p \"require('node-addon-api').include\")"
      ],
        "configurations": {
            "Release": {
                "msvs_settings": {
                    "VCCLCompilerTool": {
                        'ExceptionHandling': 1
                    }
                }
            }
        }
    },
    {
      'target_name': 'uiohook',
      'type': 'static_library',
      'sources': [
        'libuiohook/src/logger.c',
      ],
      'include_dirs': [
        'libuiohook/include',
        'libuiohook/src',
      ],
      "conditions": [
           ['OS=="mac"', {
             "defines":[
               "__MACOSX_CORE__","USE_IOKIT","USE_COREFOUNDATION","USE_CARBON","USE_CARBON_LEGACY","USE_OBJC"
               ],
              "link_settings": {
                  "libraries": [
                  "-framework IOKit", 
                  "-framework Carbon",
                  "-framework CoreFoundation"
                    ],   
                  },
              'sources': [
                            "libuiohook/src/darwin/input_helper.c",
                            "libuiohook/src/darwin/input_hook.c",
                            "libuiohook/src/darwin/post_event.c",
                            "libuiohook/src/darwin/system_properties.c"
                             ],
              'include_dirs': [
                          'libuiohook/src/darwin',
                          "<!@(node -p \"require('node-addon-api').include\")"
                          ]
        }],
        ['OS=="win"', {
          'sources': [
            'libuiohook/src/windows/input_helper.c',
            'libuiohook/src/windows/input_hook.c',
            'libuiohook/src/windows/post_event.c',
            'libuiohook/src/windows/system_properties.c'
          ],
          'include_dirs': [
            'libuiohook/src/windows',
            "<!@(node -p \"require('node-addon-api').include\")"
          ]
        }],
        ['OS=="linux"', {
          'defines': [
            'USE_XRANDR', 'USE_EVDEV', 'USE_XT'
          ],
          'link_settings': {
            'libraries': [
              '-lX11', '-lXrandr', '-lXtst', '-lpthread', '-lXt'
            ],
          },
          'cflags': ['-std=c99', '-pedantic', '-Wall', '-pthread'],
          'sources': [
            'libuiohook/src/x11/input_helper.c',
            'libuiohook/src/x11/input_hook.c',
            'libuiohook/src/x11/post_event.c',
            'libuiohook/src/x11/system_properties.c'
          ],
          'include_dirs': [
            'libuiohook/src/x11',
            "<!@(node -p \"require('node-addon-api').include\")"
          ]
        }]
      ]
    }
  ]
}
bthalinda commented 3 years ago

Great ill test it today and let you know thank you very much for the quick response. really appreciate it . stucked for few days now. ill test and update you.