Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在NAPI中使用LiB钠_Node.js_Node Gyp_Libsodium - Fatal编程技术网

Node.js 在NAPI中使用LiB钠

Node.js 在NAPI中使用LiB钠,node.js,node-gyp,libsodium,Node.js,Node Gyp,Libsodium,我正在使用一个依赖LibNasdinal(libpaseto)的库。我已经在我的机器上安装了它,我正在尝试构建一个nodejs插件 我有以下binding.gyp文件: { "targets": [{ "target_name": "testaddon", "cflags!": [ "-fno-exceptions"], "cflags_cc!": [ "-fno-exceptions" ], "cflags_cc":["-

我正在使用一个依赖LibNasdinal(libpaseto)的库。我已经在我的机器上安装了它,我正在尝试构建一个nodejs插件

我有以下
binding.gyp
文件:

{
    "targets": [{
        "target_name": "testaddon",
        "cflags!": [ "-fno-exceptions"],
        "cflags_cc!": [ "-fno-exceptions" ],
        "cflags_cc":["-std=c++1z" ,"-lsodium","$(pkg-config --cflags libsodium)"],
        "ldflags_cc":["$(pkg-config --libs libsodium)"],
        "sources": [
            "cppsrc/main.cpp",
            "cppsrc/functionexample.cpp",
            "cppsrc/libpaseto/src/helpers.c",
            "cppsrc/libpaseto/src/paseto.c",
            "cppsrc/libpaseto/src/paseto_v2_local.c",
            "cppsrc/libpaseto/src/paseto_v2_public.c",
        ],
        'include_dirs': [
            "<!@(node -p \"require('node-addon-api').include\")"
        ],
        'libraries': [],
        'dependencies': [
            "<!(node -p \"require('node-addon-api').gyp\")"
        ],
        'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ,'SODIUM_STATIC=1',
            'HAVE_LIBM=1']
    }]
}
{
    "targets": [{
        "target_name": "testaddon",
        "cflags!": [ "-fno-exceptions"],
        "cflags_cc!": [ "-fno-exceptions" ],
        "cflags_cc":["-std=c++1z"],

        "sources": [
            "cppsrc/main.cpp",
            "cppsrc/functionexample.cpp",
            "cppsrc/libpaseto/src/helpers.c",
            "cppsrc/libpaseto/src/paseto.c",
            "cppsrc/libpaseto/src/paseto_v2_local.c",
            "cppsrc/libpaseto/src/paseto_v2_public.c",
        ],
        'include_dirs': [
            "<!@(node -p \"require('node-addon-api').include\")"
        ],
        'libraries': ['-lsodium'],
        'dependencies': [
            "<!(node -p \"require('node-addon-api').gyp\")"
        ],
        'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ,'SODIUM_STATIC=1',
            'HAVE_LIBM=1']
    }]
}

如何修复它?

因此我终于找到了答案。在libnaude文档中提到,要想能够顺利编译,我必须做的是在binding.gyp中的库中添加此标志。这是我最后的
binding.gyp
文件:

{
    "targets": [{
        "target_name": "testaddon",
        "cflags!": [ "-fno-exceptions"],
        "cflags_cc!": [ "-fno-exceptions" ],
        "cflags_cc":["-std=c++1z" ,"-lsodium","$(pkg-config --cflags libsodium)"],
        "ldflags_cc":["$(pkg-config --libs libsodium)"],
        "sources": [
            "cppsrc/main.cpp",
            "cppsrc/functionexample.cpp",
            "cppsrc/libpaseto/src/helpers.c",
            "cppsrc/libpaseto/src/paseto.c",
            "cppsrc/libpaseto/src/paseto_v2_local.c",
            "cppsrc/libpaseto/src/paseto_v2_public.c",
        ],
        'include_dirs': [
            "<!@(node -p \"require('node-addon-api').include\")"
        ],
        'libraries': [],
        'dependencies': [
            "<!(node -p \"require('node-addon-api').gyp\")"
        ],
        'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ,'SODIUM_STATIC=1',
            'HAVE_LIBM=1']
    }]
}
{
    "targets": [{
        "target_name": "testaddon",
        "cflags!": [ "-fno-exceptions"],
        "cflags_cc!": [ "-fno-exceptions" ],
        "cflags_cc":["-std=c++1z"],

        "sources": [
            "cppsrc/main.cpp",
            "cppsrc/functionexample.cpp",
            "cppsrc/libpaseto/src/helpers.c",
            "cppsrc/libpaseto/src/paseto.c",
            "cppsrc/libpaseto/src/paseto_v2_local.c",
            "cppsrc/libpaseto/src/paseto_v2_public.c",
        ],
        'include_dirs': [
            "<!@(node -p \"require('node-addon-api').include\")"
        ],
        'libraries': ['-lsodium'],
        'dependencies': [
            "<!(node -p \"require('node-addon-api').gyp\")"
        ],
        'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ,'SODIUM_STATIC=1',
            'HAVE_LIBM=1']
    }]
}
{
“目标”:[{
“目标名称”:“testaddon”,
“cflags!”:[“-fno异常”],
“cflags_cc!”:[“-fno异常”],
“cflags_cc”:[“-std=c++1z”],
“资料来源”:[
“cppsrc/main.cpp”,
“cppsrc/functionexample.cpp”,
“cppsrc/libpaseto/src/helpers.c”,
“cppsrc/libpaseto/src/paseto.c”,
“cppsrc/libpaseto/src/paseto_v2_local.c”,
“cppsrc/libpaseto/src/paseto_v2_public.c”,
],
“包含目录”:[
"