CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2005
    Posts
    13

    VC project link error not added lib (can not find mylib.lib)

    I have a VC solution . This solution contain 1 execute project and 10 library projects. The libraries added to the execute project by
    #pragma comment(lib,"../outputbin64/lib/mylib").
    When i comment these lines to not be added these libraries to the execute project , i will have link error like this :
    LINK : fatal error LNK1104: cannot open file '../outputbin64/lib/mylib.lib'

    My library projects not added to execute project with another way.

    My question is why the execute project will link the libraries that not added to project programmatically?

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: VC project link error not added lib (can not find mylib.lib)

    1) getting your app to compile and link is one issue
    this uses importlibs in your case. removing the pragma's means the linker can no longer find a reference to the libs, so it ends up with unresolved externals.

    2) if these libs are importlibs for a dll then running your exe needs access to the dll's, this is an entirely separate issue that has nothing at all to do with issue 1.
    this either requires the dlls's to be copied into the directory where your exe is located
    or setting a proper path so they get resolved by the system.

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

    Re: VC project link error not added lib (can not find mylib.lib)

    Quote Originally Posted by hessamini View Post
    My question is why the execute project will link the libraries that not added to project programmatically?
    An obvious answer would be that your project sets the additional library dependencies not only programmatically. Or your changes are made in some unrelated source code.

    See the attached sample. When you really miss a library specification, the linker errors are different:

    Code:
    Microsoft (R) Incremental Linker Version 10.00.40219.01
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    /out:73.exe
    73.obj
    73.obj : error LNK2019: unresolved external symbol "void __cdecl foo(void)" (?foo@@YAXXZ) referenced in function _main
    73.exe : fatal error LNK1120: 1 unresolved externals
    Attached Files Attached Files
    Best regards,
    Igor

  4. #4
    Join Date
    Aug 2005
    Posts
    13

    Re: VC project link error not added lib (can not find mylib.lib)

    I have a VC solution . This solution contains 1 exe. and 10 libraries. The libraries are linked to the execute project from
    pragma comment(lib,"../outputbin64/lib/mylib")
    Before linking the.lib, I want to test the exe. without the .lib
    When I comment these lines, they should be blocked. But the exe still sees the .lib and I get a link error:
    LINK : fatal error LNK1104: cannot open file '../outputbin64/lib/mylib.lib'
    My libraries are not linked to the exe.
    My question is "Why does the exe. link the libraries to itself?

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: VC project link error not added lib (can not find mylib.lib)

    Quote Originally Posted by hessamini View Post
    I have a VC solution . This solution contains 1 exe. and 10 libraries. The libraries are linked to the execute project from
    pragma comment(lib,"../outputbin64/lib/mylib")
    Before linking the.lib, I want to test the exe. without the .lib
    When I comment these lines, they should be blocked. But the exe still sees the .lib and I get a link error:
    LINK : fatal error LNK1104: cannot open file '../outputbin64/lib/mylib.lib'
    My libraries are not linked to the exe.
    My question is "Why does the exe. link the libraries to itself?
    This is your original question from your post #1. If the replies in posts #2 and #3 haven't provided answers, might I suggest that you rephrase your question and to provide additional detail - rather than re-post the original post.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    Join Date
    Aug 2005
    Posts
    13

    Re: VC project link error not added lib (can not find mylib.lib)

    The post of "Igor Vartanov" is near to my need but I feel my text does not clear. so i did have to write another text.
    my need is emancipation from link error from be add my library automatically .

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

    Re: VC project link error not added lib (can not find mylib.lib)

    Quote Originally Posted by hessamini View Post
    I have a VC solution . This solution contains 1 exe. and 10 libraries. The libraries are linked to the execute project from
    pragma comment(lib,"../outputbin64/lib/mylib")
    Before linking the.lib, I want to test the exe. without the .lib
    Have no idea what you mean by that.

    When I comment these lines, they should be blocked. But the exe still sees the .lib and I get a link error:
    LINK : fatal error LNK1104: cannot open file '../outputbin64/lib/mylib.lib'
    As I said before, the answer is obvious. "Cannot open file" unambiguously indicates that linker is instructed to link the lib. As you don't have it built, the file cannot be opened and LNK1104 is fired.

    There may be different ways to instruct linker to link the same lib. You try to eliminate only one of those. As linker keeps telling you about being not able to link the lib, there must be the lib specification added some different way.

    My libraries are not linked to the exe.
    Again, have no idea what you mean. You don't have exe built due to the linker error, so you cannot say if they linked or not.

    My question is "Why does the exe. link the libraries to itself?
    It does that because there is an instruction somewhere to do that. Compilers do what they are instructed to do. You may repeat your question as many times as you wish, but the essence of the issue won't change.
    Best regards,
    Igor

  8. #8
    Join Date
    Aug 2005
    Posts
    13

    Re: VC project link error not added lib (can not find mylib.lib)

    I could solve this problem . This was a mistake to select configuration manager. excuse me for wasted your time.

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