简体   繁体   中英

Visual Studio 2010: solution with referenced library requiring double build

I have a solution in Visual Studio 2010, containing two projects:

  • A static library
  • An application linking with the same library

I'm developing them side by side. Eventually I'm going to make a second application which will share some code used by the first one, hence the library.

My problem is that whenever I modify the header file in my library (only got one so far), my first rebuild of the solution gives C1083: Cannot open source file: 'mylibrary.lib': No such file or directory .

Hitting build again a second time, immediately after, it finds the library and links just fine. So basically, any time I've modified the library and wish to rebuild, I have to do it twice in a row. I've checked that the .lib file gets placed in the right directory after the first rebuild, but the application's build still fails to find it.

I have added the library as a reference under "Framework and References" in the project properties. I'm building the entire solution and VS clearly understands that it should build the two projects in the proper order, but I still get the problem described.

Any ideas how I might fix this?

Did you setup dependencies?

Right click on the solution and select properties.

Select "Project Dependencies" and select your main project in the drop down.

When adding a library as a reference, VS can link to the library file automatically (the setting is under Framework and References, [your reference], Link Library Dependencies) , and this seems to be enabled by default. If you add the .lib file to your linker options at this point, it seems to cause the problem I described.

Removing the file as a linker option makes it work correctly on the first build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM