error LNK2011



 none
How to fix Linking error LNK2011: precompiled object not linked in; image may not run

  • Question

  • Hi all,

    I am linking a program with a static library ,which I compiled/linked without any error, and obtained Linking Error LNK2011. How to fix this problem? any suggestion? What is the best (or correct) way to link a static library which is using functions in other static library? Thanks in advance for your help.

    Tom Lin 
    Thursday, December 03, 2009 4:55 PM

Answers

  • Thanks Nancy for your reply.

    The first time I compiled/linked my static library, I did not 'deselect' Precompiled Header option. That's the error LNK1120 occured. After reviewing the MSDN article "Creating and Using a Static Library", I re-started it again. This time the error message is 'fatal error LNK1257: code generation failed'. Here is what I did

    1. I compiled and linked A.lib according to the MSDN article.
    2. I prepare a main program to link with A.lib library for testing purpose. It works fine. The following is the properties pages of the main program I changed:
        a. add the path of header file, i.e., A.h, to Additional Include Directory.
        b. add A.lib to Additional Dependencies.
        c. add the path of A.lib to Additional Library directory.
    3. Next I compiled/linked B.lib. This library does use functions in A.lib in its own functions.
        a. I created B.lib according to MSDN article.
        b. add the pathes of both header files, i.e., A.h and B.h to Additional Include Directory.
        c. add A.lib to additional Dependenceis.
        d. add the path of A.lib to additional Livrary directory. 
        (B.lib was compiled and linked without any error.)
    4. When I prepare a main program to link with B.lib for testing. Again I modified the properties pages accordingly. But it failed to generate the *.exe. The error message is LNK1257.

    Any suggestions or comments? Thanks in advance.

    Tom Lin
    • Marked as answer by Tom C. Lin Wednesday, December 09, 2009 10:03 PM
    Monday, December 07, 2009 2:22 PM

All replies

  • It does not seem like your library is only statically linked to everything that it references. What libraries does your library reference?

    Thursday, December 03, 2009 9:56 PM
  • Thanks Jinzai,

    I have a group of functions which is used to calculate ,said, Earth's magnetic field. I put them in a class and compile the class as a static library. I then wrote a main program to test the libray. It works fine. Next I have another class which need to call the library for Earth's magnetic field. I put this class as another static libray. The new static library compiled just fine. But when I tried to link a main program to test this new library, the error LNK2011 occured. Did I do it correctly? Any suggestions or comments? Thanks for your help.

    Tom Lin

    Friday, December 04, 2009 2:20 PM
  • Hi Tom C. Lin,

    LNK2011 means precompiled object not linked in. I guess you have not used the functionality from the static library in application correctly. Have you put this static library in Additional Include Directories ? To do this, in the Property Pages dialog box, expand the Configuration Properties node, expand the C/C++ node, and then select General. Next to Additional Include Directories, type the path of the location of the MyLib.h header file.

    For more information, please refer to MSDN article:

    Creating and Using a Static Library (C++)
    http://msdn.microsoft.com/en-us/library/ms235627.aspx

    Best Regards,
    Nancy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, December 07, 2009 9:07 AM
  • Thanks Nancy for your reply.

    The first time I compiled/linked my static library, I did not 'deselect' Precompiled Header option. That's the error LNK1120 occured. After reviewing the MSDN article "Creating and Using a Static Library", I re-started it again. This time the error message is 'fatal error LNK1257: code generation failed'. Here is what I did

    1. I compiled and linked A.lib according to the MSDN article.
    2. I prepare a main program to link with A.lib library for testing purpose. It works fine. The following is the properties pages of the main program I changed:
        a. add the path of header file, i.e., A.h, to Additional Include Directory.
        b. add A.lib to Additional Dependencies.
        c. add the path of A.lib to Additional Library directory.
    3. Next I compiled/linked B.lib. This library does use functions in A.lib in its own functions.
        a. I created B.lib according to MSDN article.
        b. add the pathes of both header files, i.e., A.h and B.h to Additional Include Directory.
        c. add A.lib to additional Dependenceis.
        d. add the path of A.lib to additional Livrary directory. 
        (B.lib was compiled and linked without any error.)
    4. When I prepare a main program to link with B.lib for testing. Again I modified the properties pages accordingly. But it failed to generate the *.exe. The error message is LNK1257.

    Any suggestions or comments? Thanks in advance.

    Tom Lin
    • Marked as answer by Tom C. Lin Wednesday, December 09, 2009 10:03 PM
    Monday, December 07, 2009 2:22 PM
  • Hello all, Just to let you all know that after I re-compiled all the libraries in VS2008, the problem went away. Now I can test all my static libraries. I think the problem was one of the library was compiled in VS2005. Thank you for your time and help. I truely appreciated it. Good Day.

    Tom Lin

    Wednesday, December 09, 2009 10:09 PM
  • Hi Tom,

    Glad to hear it works fine.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, December 10, 2009 2:02 AM
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值