簡體   English   中英

編譯時出錯 - node-gyp windows (c++)

[英]i got an error while compiling - node-gyp windows (c++)

我得到unresolved external symbol __imp_td_receive 我可以在代碼中看到錯誤,但我認為代碼中有錯誤。 可能錯誤是在 node-gyp 中錯誤地包含了.lib 文件。 此外,除了其他 function (來自此標題)之外,我得到了同樣的錯誤。 我有一個警告LINK: warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification [C:\Users\poega\Desktop\node-tg-cli\build\ td_json.vcxproj]

我使用 node-gyp,tdlib windows x32,

td_json_client.h: https://core.telegram.org/tdlib/docs/td__json__client_8h_source.html

main.cpp 的一部分

// hello.cc
// #include <napi.h>
#include <napi.h>
#include <iostream>
//#include <node.h>
#include "td/telegram/td_json_client.h"

using std::string;

void create_client_id(Napi::CallbackInfo& info) {
      // Isolate* isolate = args.GetIsolate();
      // args.GetReturnValue().Set(String::NewFromUtf8(
      //   isolate, "world").ToLocalChecked());
      td_create_client_id();
  }
  // td_send(int client_id, const char *request)

綁定.gyp

{
    "targets": [
      {
        
        "target_name": "td_json",
        "sources": [ "lib.cc" ],
        "include_dirs": [
          "<!(node -p \"require('node-addon-api').include_dir\")",
          "<(module_root_dir)/td/tdlib/include"
          ],
        'dependencies': [
            "<!(node -p \"require('node-addon-api').gyp\")"
        ],
        "libraries": [
          "<(module_root_dir)/td/tdlib/lib/tdjson",
          ],
        #  "conditions": [        
        # ["OS==\"win\"", {
        #   "copies": [
        #     {
        #       "destination": "<(module_root_dir)/build/Release/",
        #       "files": [ "<(module_root_dir)/td/build/Release/tdjson.dll" ]
        #     }
        #   ]
        # }]
      # ],
        'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ]
      }
    ]
  }
  • 如果您要靜態鏈接庫,則需要修復#define 查看庫的 header 文件,會有某種條件#define控制dllimport / dllexport裝飾器的包含。 使其不被包括在內 - 只有在構建 DLL 時才需要它們。 這就是 linker 生成__imp_前綴的原因 - 這意味着它正在嘗試從 DLL 導入。
  • 如果要鏈接庫 DLL,則需要 DLL 和導入.lib庫,並且需要在libraries部分添加此.lib
   "conditions": [
     ["OS == 'win'", {
       "libraries": [
         "<path...>/tdjson.lib"
       ]
     }]
   ]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM