c++ - Mac 中 Electron 中的 native C++ 插件出现问题

标签 c++ electron dylib node.js-addon n-api

我正在编写代码以从 Electron 加载 c++ 动态库。在 Mac 中尝试时出现以下错误:

dyld:找不到符号:__ZN15FcDrive2Library13InitDrive2LibEv
引用自:/Users/nikhell/Documents/Codelathe/Workspace/cl-fc-client/electron-drive-client/build/Release/electronToCppBridge.node
预期在:平面命名空间

我的 binding.gyp 文件如下所示:

{
    "targets":[
    {
        "target_name": "electronToCppBridge",
        "cflags!": [ "-fno-exceptions" ],
        "cflags_cc!": [ "-fno-exceptions" ],
        'include_dirs': [
            "<!@(node -p \"require('node-addon-api').include\")"
        ],
        'dependencies': [
            "<!(node -p \"require('node-addon-api').gyp\")"
        ],
        'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
        "copies":[
        {
            'destination': './node_modules/electron/dist',
            'files':[
                '../../cl-fc-client/release/support/common/clientca.pem',
                '../../cl-fc-client/release/support/common/clientcert.pem',
                '../../cl-fc-client/clouddrive2/config.xml',
                '../../cl-fc-client/release/support/prebuilt/translationsdc.zip'
            ]
        },
        {                        
            'destination': './src',
            'files':['../cloudDrive2Lib/LibraryEntry/cloudDrive2Library.h']
        }
        ],
        "conditions":[
            ["OS=='win'", 
            {
                "copies":[
                { 
                    'destination': './build/Release',
                    'files':[
                        '../../cl-fc-client-thirdparty/bugtrap/BugTrapU-x64.dll',
                        '../build/bin/msvc/Release64/cloudDrive2Lib.dll',
                        '../../cl-fc-client-thirdparty/openssl/1.0.2j/lib/x86_64-win32/ssleay32MD.dll',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoZip64.dll',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoXML64.dll',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoUtil64.dll',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoNetSSL64.dll',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoNet64.dll',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoJSON64.dll',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoFoundation64.dll',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/bin64/PocoCrypto64.dll',
                        '../../cl-fc-client-thirdparty/openssl/1.0.2j/lib/x86_64-win32/libeay32MD.dll'
                    ]
                },
                {                        
                    'destination': './libs',
                    'files':['../build/bin/msvc/Release64/cloudDrive2Lib.lib']
                },
                ],
                "sources": [
                    "src/electronToCppBridge.cc",
                ],
            }
            ],
            ["OS=='mac'",
            {
                "copies":[
                {
                    'destination': './build/Release',
                    'files':[
                        '../build/bin/darwin/release/libfileclouddrive2lib.dylib',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/lib/Darwin/x86_64/libPocoCrypto.45.dylib',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/lib/Darwin/x86_64/libPocoFoundation.45.dylib',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/lib/Darwin/x86_64/libPocoJSON.45.dylib',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/lib/Darwin/x86_64/libPocoNet.45.dylib',
                        '../../cl-fc-client-thirdparty/poco/1.7.5/lib/Darwin/x86_64/libPocoNetSSL.45.dylib'
                    ]
                },
                {
                    'destination': './libs',
                    'files':[
                        '../build/bin/darwin/release/libfileclouddrive2lib.dylib'
                    ]
                },
                ],
                "sources": [
                    "src/electronToCppBridge.cc",
                    "libs/libfileclouddrive2lib.dylib",
                ],                    
            }
            ]            
        ],
    }       
    ]
}

它在Windows中工作。在 Mac 中,我也尝试过重新安装节点模块和 Electron 重建。它们都不适合我。除了 native .node 模块外,dylib 已成功复制。不知道为什么会出现此链接错误

最佳答案

没关系。我意识到需要在 binding.gyp 中添加 link_dependencies 标签。 dylib 也需要复制到项目的根目录。

关于c++ - Mac 中 Electron 中的 native C++ 插件出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57101378/

相关文章:

c++ - 在 Qt 中解析 XML 文件

node.js - LevelDOWN : NODE_MODULE_VERSION error when testing, 但未运行

javascript - 使用 JS 或 TS 或 electro 在 OSX 上测试蓝牙状态(事件或非事件)

bundle - 从 dylib 中获取 mach-o 插件包的路径

c++ - dylib 与另一个 dylib 有何不同?

c++ - 如何初始化此结构?

c++ - 如何将击键发送到窗口?

c++ - waitpid() 给出不正确的退出代码

node.js - 在 Electron 应用中,使用 webpack/electron-builder 打包后,在 worker_threads 提示 MODULE_NOT_FOUND 中需要第三方模块

c - 链接到 OSX 上的可执行文件