Visual Studio: LINK : fatal error LNK1181: cannot open input file

后端 未结 17 2749
盖世英雄少女心
盖世英雄少女心 2020-12-05 03:47

I\'ve been encountering a strange bug in Visual Studio 2010 for some time now.

I have a solution consisting of a project which compiles to a static library, and anot

相关标签:
17条回答
  • 2020-12-05 04:19

    For me the problem was a wrong include directory. I have no idea why this caused the error with the seemingly missing lib as the include directory only contains the header files. And the library directory had the correct path set.

    0 讨论(0)
  • 2020-12-05 04:23

    I'm stumbling into the same issue. For me it seems to be caused by having 2 projects with the same name, one depending on the other.

    For example, I have one project named Foo which produces Foo.lib. I then have another project that's also named Foo which produces Foo.exe and links in Foo.lib.

    I watched the file activity w/ Process Monitor. What seems to be happening is Foo(lib) is built first--which is proper because Foo(exe) is marked as depending on Foo(lib). This is all fine and builds successfully, and is placed in the output directory--$(OutDir)$(TargetName)$(TargetExt). Then Foo(exe) is triggered to rebuild. Well, a rebuild is a clean followed by a build. It seems like the 'clean' stage of Foo.exe is deleting Foo.lib from the output directory. This also explains why a subsequent 'build' works--that doesn't delete output files.

    A bug in VS I guess.

    Unfortunately I don't have a solution to the problem as it involves Rebuild. A workaround is to manually issue Clean, and then Build.

    0 讨论(0)
  • 2020-12-05 04:23

    I created a bin directory at the project_dir level, then created a release/debug directory inside the bin folder, which solved the problem for me.

    0 讨论(0)
  • 2020-12-05 04:24

    I had the same problem. Solved it by defining a macro OBJECTS that contains all the linker objects e.g.:

    OBJECTS = target.exe kernel32.lib mylib.lib (etc)
    

    And then specifying $(OBJECTS) on the linker's command line.

    I don't use Visual Studio though, just nmake and a .MAK file

    0 讨论(0)
  • 2020-12-05 04:25

    Go to:

    Project properties -> Linker -> General -> Link Library Dependencies set No.
    
    0 讨论(0)
  • 2020-12-05 04:26

    I can see only 1 things happening here: You did't set properly dependences to thelibrary.lib in your project meaning that thelibrary.lib is built in the wrong order (Or in the same time if you have more then 1 CPU build configuration, which can also explain randomness of the error). ( You can change the project dependences in: Menu->Project->Project Dependencies )

    0 讨论(0)
提交回复
热议问题