fatal error LNK1120: 7 unresolved externals

37 Views Asked by At

`I am trying to create node.js addon. I am trying to call function add from hello.cxx file this file has Teamcenter related code .




hello.cxx file ===>
//==================================================
//
//  Copyright 2020 Siemens Digital Industries Software
//
//==================================================
#include <cstring>
#include "teamcenter/hello/Hello.hxx"

#include <teamcenter/soa/common/AutoPtr.hxx>
#include <teamcenter/soa/client/ModelObject.hxx>
//
#include <teamcenter/clientx/AppXSession.hxx>
#include <teamcenter/hello/DataManagement.hxx>
#include <teamcenter/hello/HomeFolder.hxx>
#include <teamcenter/hello/Query.hxx>
//
//
#include <teamcenter/soa/client/model/User.hxx>
#include <teamcenter/soa/client/RuntimeException.hxx>

#include <vector>
#include <iostream>
#ifdef WIN32
#include <tchar.h>
#endif

using namespace std;
using namespace Teamcenter::ClientX;
using namespace Teamcenter::Hello;
using namespace Teamcenter::Soa::Common;
using namespace Teamcenter::Soa::Client;
using namespace Teamcenter::Soa::Client::Model;


    /**
    * @param args    -help or -h will print out a Usage statement
    */

   #ifdef WIN32
   int _tmain(int argc, _TCHAR* argv[])
#else
int main(int argc, char* argv[])
#endif
{
    if (argc > 1)
    {
        if (strcmp( argv[1],"-help")==0 || strcmp(argv[1],"-h")==0)
        {
            cout << "usage: Hello [-host http://server:port/tc] " << endl;
            return 0;
        }
    }

    // Get optional host information
    std::string serverHost = "http://localhost:8080/tc";
    if(argc > 2 && strcmp( argv[1], "-host")==0 )
    {
        serverHost = argv[2];
    }

    AppXSession     session(serverHost);
    HomeFolder  home;
    Query       query;
    DataManagement dm;

    try
    {
        if (argc != 5) {
            std::cerr << "Usage: " << argv[0] << "Error: Username, password, group, or role cannot be empty Or Invalid Input" << std::endl;
            return 1;
        }

        std::string username = argv[1];
        std::string password = argv[2];
        std::string group = argv[3];
        std::string role = argv[4];
        // Establish a session with the Teamcenter Server
        if (username.empty() || password.empty() || group.empty() || role.empty()) {
            /*  std::cerr << "Error: Username, password, group, or role cannot be empty." << std::endl;*/
            cout << "Error: Username, password, group, or role cannot be empty Or Invalid Input" << endl;
        }
        else {
            /*Teamcenter::Soa::Common::AutoPtr<User> user = session.login();
            Teamcenter::Soa::Common::AutoPtr<User> user = session.login("infodba","infodba","dba","dba");*/
            Teamcenter::Soa::Common::AutoPtr<User> user = session.login(username, password, group, role);
            if (user.isNull())
                return 0;

            // Using the User object returned from the login service request
            // display the contents of the Home Folder
            home.listHomeFolder(user);
            std::vector<std::string> queryInputs = { "Item ID" };
            std::vector<std::string> queryValues = { "000048" };
            std::string queryName = "Item...";
            std::vector<AutoPtr<ModelObject> > foundObjs =
                query.findQueryResult(queryName, queryInputs, queryValues);

            // Perform a simple query of the database
            //query.queryItems();

            // Perform some base data management functions
            dm.createReviseAndDelete();

            // Terminate the session with the Teamcenter server
         session.logout();
        }
    }
    catch( Teamcenter::Soa::Client::RuntimeException& e)
    {
        cout << e.getMessage() << endl;
        cout << "The application will terminate." << endl;
    }
    return 0;

}`
int add(int x, int y) {
    return x + y;
}

from the above code I am trying to call add() in my addon.cpp file addon.cxx file ==>

#define NAPI_CPP_EXCEPTIONS
#include <napi.h>
#ifdef WIN32
#include <tchar.h>
#endif
extern int add(int a, int b);
Napi::Value Login(const Napi::CallbackInfo& info) {
    Napi::Env env = info.Env();
    try {
        // Calling the main function from hello.cxx
        //main();
        add(3,5); 
    }
    catch (const std::exception& ex) {
        // Handle any exceptions that may occur
        Napi::TypeError::New(env, ex.what()).ThrowAsJavaScriptException();
    }
    return env.Undefined();
}

// Wrapper function to call sayHello()
//Napi::Value CallSayHello(const Napi::CallbackInfo& info) {
  //  Napi::Env env = info.Env();
    //sayHello();
    //return env.Undefined();
//}

Napi::Number Add(const Napi::CallbackInfo& info) {
    Napi::Env env = info.Env();

    if (info.Length() < 2 || !info[0].IsNumber() || !info[1].IsNumber()) {
        Napi::TypeError::New(env, "Number expected").ThrowAsJavaScriptException();
        return Napi::Number::New(env, 0);
    }

    double a = info[0].As<Napi::Number>().DoubleValue();
    double b = info[1].As<Napi::Number>().DoubleValue();

    double sum = a + b;

    return Napi::Number::New(env, sum);
}
//Napi::Value SayHello(const Napi::CallbackInfo& info) {
 //   Napi::Env env = info.Env();

 //   sayHello(); // Call the C++ function

 //   return env.Undefined();
//}

//Napi::String Method(const Napi::CallbackInfo& info) {
 //  Napi::Env env = info.Env();
 //   return Napi::String::New(env, "world");

Napi::Object Init(Napi::Env env, Napi::Object exports) {
    exports.Set("add", Napi::Function::New(env, Add));
    // exports.Set("hello",Napi::Function::New(env, Method));
    // exports.Set("SAYHELLO", Napi::Function::New(env, CallSayHello));
    exports.Set("Login", Napi::Function::New(env, Login));
    return exports;
}

NODE_API_MODULE(addon, Init)

like above

In binding.gyp file I have mentioned all the lib files and necessary flags also but still I am facing this error . I am pasting my errors below

``` Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch. addon.cxx Hello.cxx win_delay_load_hook.cc C:\node-addon-api\node_modules\node-addon-api\napi-inl.h(3034,9): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc (compiling source file C:\dev\cppProject\soa_client\cpp\samples\TCArtiosCADIntegration\addon.cxx) [C:\node-addon-api\build\addon.vcxproj] C:\dev\cppProject\soa_client\cpp\samples\TCArtiosCADIntegration\Hello.cxx(67,5): warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc [C:\node-addon-api\build\addon.vcxproj] Creating library C:\node-addon-api\build\Release\addon.lib and object C:\node-addon-api\build\Release\addon.exp Hello.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl Teamcenter::ClientX::AppXSession::~AppXSession(void)" (??1AppXSession@ClientX@Teamcenter@@UEAA@XZ) [C:\node-addon-api\build\addon.vcxproj] Hello.obj : error LNK2001: unresolved external symbol "public: void __cdecl Teamcenter::ClientX::AppXSession::logout(void)" (?logout@AppXSession@ClientX@Teamcenter@@QEAAXXZ) [C:\node-addon-api\build\addon.vcxproj] Hello.obj : error LNK2001: unresolved external symbol "public: class Teamcenter::Soa::Common::AutoPtr __cdecl Teamcenter::ClientX::AppXSession::login(class std::basic_string,class std::allocator >,class std::basic_string,class std::allocator >,class std::basic_string,class std::allocator >,class std::basic_string,class std::allocator >)" (?login@AppXSession@ClientX@Teamcenter@@QEAA?AV?$AutoPtr@VUser@Model@Client@Soa@Teamcenter@@@Common@Soa@3@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@000@Z) [C:\node-addon-api\build\addon.vcxproj] Hello.obj : error LNK2001: unresolved external symbol "public: __cdecl Teamcenter::ClientX::AppXSession::AppXSession(class std::basic_string,class std::allocator > const &)" (??0AppXSession@ClientX@Teamcenter@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) [C:\node-addon-api\build\addon.vcxproj] Hello.obj : error LNK2001: unresolved external symbol "public: void __cdecl Teamcenter::Hello::HomeFolder::listHomeFolder(class Teamcenter::Soa::Common::AutoPtr)" (?listHomeFolder@HomeFolder@Hello@Teamcenter@@QEAAXV?$AutoPtr@VUser@Model@Client@Soa@Teamcenter@@@Common@Soa@3@@Z) [C:\node-addon-api\build\addon.vcxproj] Hello.obj : error LNK2001: unresolved external symbol "public: void __cdecl Teamcenter::Hello::DataManagement::createReviseAndDelete(void)" (?createReviseAndDelete@DataManagement@Hello@Teamcenter@@QEAAXXZ) [C:\node-addon-api\build\addon.vcxproj] Hello.obj : error LNK2001: unresolved external symbol "public: class std::vector,class std::allocator > > __cdecl Teamcenter::Hello::Query::findQueryResult(class std::basic_string,class std::allocator > const &,class std::vector,class std::allocator >,class std::allocator,class std::allocator > > > const &,class std::vector,class std::allocator >,class std::allocator,class std::allocator > > > const &)" (?findQueryResult@Query@Hello@Teamcenter@@QEAA?AV?$vector@V?$AutoPtr@VModelObject@Client@Soa@Teamcenter@@@Common@Soa@Teamcenter@@V?$allocator@V?$AutoPtr@VModelObject@Client@Soa@Teamcenter@@@Common@Soa@Teamcenter@@@std@@@std@@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@5@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@5@1@Z) [C:\node-addon-api\build\addon.vcxproj] C:\node-addon-api\build\Release\addon.node : fatal error LNK1120: 7 unresolved externals [C:\node-addon-api\build\addon.vcxproj] ``` Please help me with this , I am facing this issue from week..

I tried to analyze missing dependencies by using dependency walker but not Abel to find it. I am just looking for the solution of this problem

0

There are 0 best solutions below