Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/135.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.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
C++ 在C++;添加随机字符_C++_Node.js_V8 - Fatal编程技术网

C++ 在C++;添加随机字符

C++ 在C++;添加随机字符,c++,node.js,v8,C++,Node.js,V8,在NodeJS中,我正在用C构建一个到共享对象的接口。我有以下代码: #include <node.h> #include "libcustom_encryption.h" namespace demo { using v8::Exception; using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Number; using v

在NodeJS中,我正在用C构建一个到共享对象的接口。我有以下代码:

#include <node.h>
#include "libcustom_encryption.h"

namespace demo {

    using v8::Exception;
    using v8::FunctionCallbackInfo;
    using v8::Isolate;
    using v8::Local;
    using v8::Number;
    using v8::Object;
    using v8::String;
    using v8::Value;

    //
    //  This is the implementation of the "add" method
    //  Input arguments are passed using the
    //  const FunctionCallbackInfo<Value>& args struct
    //
    void DeviceGetVersion(const FunctionCallbackInfo<Value>& args)
    {
        char ver[10] = {0};
        unsigned int ver_size = 0;

        device_get_version(ver, ver_size);

        Isolate* isolate = args.GetIsolate();

        //
        //  1.  Save the value in to a isolate thing
        //
        Local<Value> str = String::NewFromUtf8(isolate, "Test");

        //
        //  2.  Set the return value (using the passed in
        //      FunctionCallbackInfo<Value>&)
        //
        args.GetReturnValue().Set(str);
    }


    void Init(Local<Object> exports)
    {
        NODE_SET_METHOD(exports, "devicegetversion", DeviceGetVersion);
    }

    NODE_MODULE(addon, Init)
}
调用函数时,它会被加上前缀并附加随机字符。我假设这是随机数据,是来自内存的噪声。它看起来好像调用函数的大小比它应该的大

我不是很有经验的C++和C混合,我很想得到关于正在发生的事情的解释。 技术规格:

  • GCC版本:GCC版本4.8.5 20150623(Red Hat 4.8.5-4)(GCC)
  • NodeJS版本:v6.2.0
调用该函数时,会在其前面加上随机字符

它被称为 发生在C++中。

这里的实际错误是编译后的模块无法链接到函数
device\u get\u version()

你可能采取的行动:

  • device\u get\u version
    的实现添加到您的模块中
  • 正确链接此功能
  • 只要删除该行,错误就会消失

UPD.
<代码> DEVICHOGETGEXVIEWS/<代码>实际上可以是一个C函数,它被视为C++函数(可以用它的名字来表示它)。 确保您的函数声明为

extern "C" {
    void device_get_version(...);
}
调用该函数时,会在其前面加上随机字符

它被称为 发生在C++中。

这里的实际错误是编译后的模块无法链接到函数
device\u get\u version()

你可能采取的行动:

  • device\u get\u version
    的实现添加到您的模块中
  • 正确链接此功能
  • 只要删除该行,错误就会消失

UPD.
<代码> DEVICHOGETGEXVIEWS/<代码>实际上可以是一个C函数,它被视为C++函数(可以用它的名字来表示它)。 确保您的函数声明为

extern "C" {
    void device_get_version(...);
}

可能重复的可能重复的可能重复的那就请你帮忙理解吧。关于你的更新,我在.h文件中有。实际上,真正的问题是在外部C中,我被.h文件
\define VE_EXPORT Extern“C”\uu declspec(dllexport)
中的这一行误导了,我以为就是它。一旦我用
extern
包装了声明,一切都成功了——非常感谢:)然后感谢您帮助我理解。关于你的更新,我在.h文件中有。实际上,真正的问题是在外部C中,我被.h文件
\define VE_EXPORT Extern“C”\uu declspec(dllexport)
中的这一行误导了,我以为就是它。一旦我用
extern
包装了声明,一切都成功了——非常感谢:)