Answered error LNK2019: unresolved external symbol

  • Saturday, April 28, 2012 11:55 PM
     
     

    Hi all,

    I know similar questions are posted, but I couldn't find the answer I'm looking for in them. I get at LNK2019 error upon building a VC++ project. This started to happen when I downloaded some header files and source files for some software I want to use in my project. I include the proper header files and point to the project where the header directory is. I know I should also link the library to the project, the problem is that the files I downloaded do not contain a library, just the .h and .cpp files.

    I tried creating a new project with just the .h and .cpp files and created a static library, then linked it to the first project, but that did not work either.

    Any idea what I can do?? 

All Replies

  • Sunday, April 29, 2012 12:34 AM
     
     

    It might be simpler if you just add the cpp file to your project.

    If you prefer to use it as a library then please give us more detail than "did not work."

  • Sunday, April 29, 2012 11:25 AM
     
     

    Hi Scott, 

    When I create a static library and link it I still get the LNK2019 error. 

    As for adding the cpp files to the project, do you mean I should go to: Solution Explorer, Source Files, right click -> add -> existing item, then select the cpp files? That doesn't work as it gives even more errors when I build the project, a lot more.

    Regards,

  • Sunday, April 29, 2012 1:59 PM
     
     

    The library must have inline functions try to get all the functions out of there respective clases and if it still does not work then make all the function definition in .cpp files whereas just right there names in .h

    that will definitely solve the issues.

    For more detail see this http://msdn.microsoft.com/EN-US/library/799kze2z(VS.110).aspx

  • Sunday, April 29, 2012 2:16 PM
     
     

    Thanks Rana, but I think the issue is something else. I just added all the source files to my project and one of them has a main block (other than that of my original project). Obviously I can't have two main blocks, but I'm not sure what to do about it, do I just use the same main block in the source file I added and copy my code to it?

    Regards, 

  • Sunday, April 29, 2012 3:02 PM
     
     Answered

    There is no general answer based on what little you have told us about the code. You need to study and understand the code you downloaded and decide what you need from it and what it is intended to be. If you get errors, don't abandon an approach: Try and figure out why. It's often just a matter of getting the required #include's in the appropriate order. But you can't get much help here just by saying "I get errors." The first few error messages are trying to tell you what is wrong. And each error code can be looked up in MSDN for additional information about what might cause that error.

    Maybe the main() function it has is intended to provide an example of how you could use the functions it has? But that's just a guess.

     

  • Monday, April 30, 2012 1:26 PM
     
     

    The other main() is indeed an example. I looked up the error codes before posting the question here, and if I found something useful, I would have used it. In any case, thanks for the efforts guys.

    Regards,