Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: LNK2019 error - a vague question...  (Read 3928 times)

0 Members and 1 Guest are viewing this topic.

dbran

    Topic Starter


    Rookie
    • Experience: Experienced
    • OS: Windows 7
    LNK2019 error - a vague question...
    « on: October 17, 2012, 12:13:05 PM »
    OK, the scenario…

    I have a VS C++ program (a dll) that calls a static library (the static library uses Multibyte Character set)…

    The static library calls a method from another dll (this dll uses Unicode Character set)…

    I have the dll linked to the calling application through the linker property “Additional Dependencies”.

    If I run the code, it will work as expected (which is unfortunately broken)…  Now, I try to add a new method to the dll.  I add the method prototype/declaration, rebuild it successfully, and move the new library to the path where the “Additional Dependencies” property expects it to be.

    I then add a call to the new method and rebuild the static library.  The static library builds successfully.

    I then rebuild the calling application.  It fails with a LNK2019 error, unresolved symbol on the new method.  Why could this be?  The method added in the dll is modeled after an existing method so its form should be correct.  The path for the dependencies has not changed and the new library is in that folder.

    Any ideas?  Thanks.

    dbran

      Topic Starter


      Rookie
      • Experience: Experienced
      • OS: Windows 7
      Re: LNK2019 error - a vague question...
      « Reply #1 on: October 17, 2012, 01:04:59 PM »
      I guess I could add for clarity:

      The function in the dll looks like this -

      Code: [Select]
       

      MyObj* MyClass::funct1(std::string str1, std::string str2, long var1, long var2, std::string str3)
      {
          MessageBox(0, s2ws(str1).c_str(), L"String 1 Value", 1);
          MessageBox(0, s2ws( str2).c_str(), L"String 2 Value", 1);
          MessageBox(0, s2ws(str3).c_str(), L"String 3 Value", 1);

          // Code to return the object is here.

      }


       where  function s2ws is defined as (found online) -

      Code: [Select]

      std::wstring s2ws(const std::string& s)
      {
      int len;
      int slength = -1;

      len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);

      wchar_t* buf = new wchar_t[len];
      MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);

      std::wstring r(buf);

      delete[] buf;
      return r;
      };


      This results in mangled names being displayed for the string values even though they are correctly passed into the function.  I was wondering if this was due to the differences in the character sets being used between the static and dynamic libraries.  The next thing I wanted to try was to convert the strings to wide string before passing them into the dll.

      So on the static side I took the strings and passed them to the s2ws function before passing them in and checked both versions there.  They were correct.  So next I needed a new function in the dll to take wstring values.  It is pretty much the same as above -

      Code: [Select]

      MyObj* MyClass::funct1(std::wstring str1, std::wstring str2, long var1, long var2, std::wstring str3)
      {
          MessageBox(0, str1.c_str(), L"String 1 Value", 1);
          MessageBox(0, str2.c_str(), L"String 2 Value", 1);
          MessageBox(0, str3.c_str(), L"String 3 Value", 1);

          // Code to return the object is here.

      }


      That gets me back to the scenario I described first.  After rebuilding everything, I am getting the LNK2019 error.

      Thanks...

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: LNK2019 error - a vague question...
      « Reply #2 on: October 17, 2012, 01:12:54 PM »
      I can't say much to help, but I can say that changing the parameter types will change the mangled name that the compiler generates for a function, which will result in unresolved externals.

      Aside from that I just wanted to post so at least you know you weren't being completely ignored...
      I was trying to dereference Null Pointers before it was cool.

      dbran

        Topic Starter


        Rookie
        • Experience: Experienced
        • OS: Windows 7
        Re: LNK2019 error - a vague question...
        « Reply #3 on: October 17, 2012, 01:22:06 PM »
        Thanks for the post BC...  I just noticed the error in my post that may have led to your comment.  The second function that I created was not supposed to look like I was overloading the original.  The prototype for that one is actually -

        Code: [Select]

        MyObj* MyClass::funct2(std::wstring str1, std::wstring str2, long var1, long var2, std::wstring str3);


         - with a funct2 name and not funct1.  And the mangling was coming before this.  I was merely passing a std::string into the dll and trying to use it in a message box (which because it is a Unicode dll defaults to MessageBoxW).