CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2011
    Posts
    19

    How would I know which lib is missing during the linkage ?

    I am using MSVS 2010 for a C project. This project compiles but I get the error during compilation. The error is following:


    error LNK2019: unresolved external symbol _CreateRelation referenced in function _main

    Here the CreateRealtion is function. So how would I know which library is not included and causing this error?

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: How would I know which lib is missing during the linkage ?

    You'd check the documentation for the function.

  3. #3
    Join Date
    Jun 2011
    Posts
    19

    Re: How would I know which lib is missing during the linkage ?

    Hello GCDEF,

    Thanks for your reply.I don't have such documentation in the project. Or may be I could not get you well,could you please elaborate your answer.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How would I know which lib is missing during the linkage ?

    I don't have such documentation in the project.
    Bad luck, you should have to. Well typically you do, but if you don't you're on your own.
    could you please elaborate your answer.
    Okay, working on your project you know CreateRelation belongs to some particular domain in your project, say some third party API. What GCDEF meant, you need to refer to the API documentation whatever way you use to program with those API.
    Last edited by Igor Vartanov; July 3rd, 2011 at 06:09 AM.
    Best regards,
    Igor

  5. #5
    Join Date
    Mar 2010
    Location
    Melbourne Australia
    Posts
    454

    Re: How would I know which lib is missing during the linkage ?

    For example you get an linking error for CreateProcess , we know this a API exported by kernel32.dll
    so the library responsible would be kernel32.lib , if you go through MSDN then each API at least from windows is well documented. IF you using third party DLL then ask them for which lib file to include ,

    If you still do not have lib file then you can link at run time by using loadLibrary to get a HANDLE on the dll and then use GetProcAddress to obtain function pointer to the API you want to use.

    In the past I have used this method to use DLL for which there was no lib file.

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How would I know which lib is missing during the linkage ?

    If you still do not have lib file then you can link at run time by using loadLibrary to get a HANDLE on the dll and then use GetProcAddress to obtain function pointer to the API you want to use.
    Well, in case it's possible to link by means of GetProcAddress, it's always possible to make your own lib to link to the dll. But my impression was the question was about a bit different situation when the guy is not able to identify the dll to link to.
    Best regards,
    Igor

  7. #7
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: How would I know which lib is missing during the linkage ?

    Is this your yacc/bison project (see thread at http://www.codeguru.com/forum/showthread.php?t=514119 )? If so, then you might look at the documentation for the yacc/bison library that you are using.

    Note that there is a huge difference between "CreateRelation", which apparently is a function defined by you, and "_CreateRelation" (note the underscore), which is an external function for which the compiler can find a .h header, but for which the linker cannot find a .lib library file.

    So, if it's compiling, then look through your .h header files to find the header file that contains "_CreateRelation" (with the underscore). The identity of the header file should provide you with a clue as to the identity of the library that the linker needs when linking.

    Mike

  8. #8
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: How would I know which lib is missing during the linkage ?

    Quote Originally Posted by MikeAThon View Post
    Note that there is a huge difference between "CreateRelation", which apparently is a function defined by you, and "_CreateRelation" (note the underscore), which is an external function for which the compiler can find a .h header, but for which the linker cannot find a .lib library file.
    I only have a vague idea of the OP's scenario, yet I don't think so. CreateRelation() rather seems to be a function with C linkage, to which not the "fancy" C++ name mangling is applied, but instead each C symbol is prefixed with an underscore, and the linker doesn't undecorate these names. The way the linker refers to the main() function is an indication of this:

    Quote Originally Posted by __bairagi View Post
    error LNK2019: unresolved external symbol _CreateRelation referenced in function _main
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  9. #9
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: How would I know which lib is missing during the linkage ?

    Quote Originally Posted by Eri523 View Post
    ... CreateRelation() rather seems to be a function with C linkage, to which not the "fancy" C++ name mangling is applied, but instead each C symbol is prefixed with an underscore, and the linker doesn't undecorate these names. The way the linker refers to the main() function is an indication of this:
    Perhaps you're right, in which case the OP should look at the "extern C" construct. For one page of guidance, see "How to mix C and C++" at http://www.parashift.com/c++-faq-lit...c-and-cpp.html

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: How would I know which lib is missing during the linkage ?

    Quote Originally Posted by Eri523 View Post
    I only have a vague idea of the OP's scenario,
    Well, quite a typical scenario on CG: gurus are busy a lot with guessing this and guessing that after initial post or a couple, while the OP never appears in the thread anymore...
    Best regards,
    Igor

  11. #11
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: How would I know which lib is missing during the linkage ?

    Quote Originally Posted by Igor Vartanov View Post
    Well, quite a typical scenario on CG: gurus are busy a lot with guessing this and guessing that after initial post or a couple, while the OP never appears in the thread anymore...
    Of course you're basically right. I've frequently noticed that myself already. But at least this OP made it up to a total of 18 posts up to now. I don't have access to actual statistics (how should I without being at least a moderator?), but I think this is relatively good in the low-end range. (At least I think I have seen more users with one or two posts than with 18.) His current posts-per-day avarage is 2.20 - I was just curious whether he beat me, but he didn't...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured