简体   繁体   中英

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

I get unresolved external symbol __imp_td_receive . I can see error in code, but I think error in code. Maybe the error is including the.lib files in node-gyp incorrectly. Also, I get same error except about other function (from this header). And i have one warning LINK: warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification [C:\Users\poega\Desktop\node-tg-cli\build\ td_json.vcxproj]

I use node-gyp, tdlib windows x32,

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

part of 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)

binding.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' ]
      }
    ]
  }
  • If you are linking a library statically, you need to fix the #define s. Look at the header files of your library, there will be some kind of conditional #define that controls the inclusion of dllimport / dllexport decorators. Make it so they do not get included - they are needed only when building a DLL. That's why the linker generates the __imp_ prefix - it means it is trying to import from a DLL.
  • If you are linking a library DLL you need both the DLL and an import .lib library and you need to add this .lib in the libraries section:
   "conditions": [
     ["OS == 'win'", {
       "libraries": [
         "<path...>/tdjson.lib"
       ]
     }]
   ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM