134

I've created a new C++ project in Visual Studio 2008. No code has been written yet; Only project settings have been changed.

When I compile the project, I receive the following fatal error:

fatal error LNK1104: cannot open file 'C:\Program.obj'

Josh Sklare
  • 4,024
  • 3
  • 23
  • 17

27 Answers27

170

This particular issue is caused by specifying a dependency to a lib file that had spaces in its path. The path needs to be surrounded by quotes for the project to compile correctly.

On the Configuration Properties -> Linker -> Input tab of the project’s properties, there is an Additional Dependencies property. This issue was fixed by adding the quotes. For example, changing this property from:

C:\Program Files\sofware sdk\lib\library.lib

To:

"C:\Program Files\sofware sdk\lib\library.lib"

where I added the quotes.

Amin Ya
  • 1,515
  • 1
  • 19
  • 30
Josh Sklare
  • 4,024
  • 3
  • 23
  • 17
  • 20
    God you've just hanged two day's bug chase to 30 second one :) – jb. May 10 '09 at 21:04
  • 11
    I had the same problem. If your Linker is correct but your lib directory is set incorrectly the same error may come up. Try looking in **Configuration Properties -> VC++ directories -> Library Directories** to see if you set the library correctly. Sometimes the lib folder consists of a x86 and a x64 folder. You have to set it to one of those (depending on your compiler) rather than the folder containing both. – M4st3rM1nd Apr 28 '13 at 22:56
  • 1
    Don't forget to put a semicolon after `"C:\Program Files\sofware sdk\lib\library.lib"`. The absence of a `;` will also cause the project to compile incorrectly. – roscioli May 23 '14 at 13:00
  • 1
    Had this problem while trying to build OpenCV using Visual Studio 2005 (on Windows 8.1)...and it solved it. Great! – AlainD Nov 07 '14 at 00:28
  • MasterMind: $(VC_LibraryPath_x86);$(WindowsSDK_LibraryPath_x86); What do I change these to? – user391339 Feb 21 '15 at 05:41
  • 1
    I tried it and it didn't work to me. **"Qt5Xmld.lib";"Qt5XmlPatternsd.lib";"Qt5Cored.lib";%(AdditionalDependencies)** -What should I chage? – STF Jan 03 '16 at 06:35
  • At first I thought the separator should be one space, at last I found it should be newline, i.e. one lib one line. – Lei Yang Dec 06 '16 at 08:45
  • how do i get to the Configuration Properties screen? – FistOfFury Apr 06 '17 at 19:45
  • 1
    The easiest way to find the guilty path (since C:\Program is of little help) is to check the linker command line arguments. (got to `Property Pages > Configuration Properties > Linker > Command Line`) It helps to copy paste that into a text editor ans search for `"Program "`. – Brandlingo Mar 28 '18 at 07:27
  • Call me old school, but I never put spaces in anything when programming. It's always either ``camelCased`` or ``spaced_with_underscores``. I like to think that this technique has saved me at least a few dozen headaches through the years. – kmiklas Jan 30 '19 at 16:36
  • In my case I accidentally erased the ```%``` in front of ```%(CoreLibraryDependencies)``` – Scott Madeux Oct 12 '22 at 08:52
76

This can happen if the file is still running as well.

:-1: error: LNK1104: cannot open file 'debug\****.exe'

Carol
  • 1,852
  • 26
  • 29
17

The problem went away for me after closing and re-opening Visual Studio. Not sure why the problem happened, but that might be worth a shot.

This was on VS 2013 Ultimate, Windows 8.1.

Daniel Neel
  • 1,197
  • 13
  • 28
10

Check also that you don't have this turned on: Configuration Properties -> C/C++ -> Preprocessor -> Preprocess to a File.

Assaf Levy
  • 1,312
  • 1
  • 12
  • 20
  • In my case it was also the issue, yet , what should I do if I do wish to turn this flag on (in order to view the Prepossessed file) ? – Guy Avraham Jun 13 '16 at 15:28
  • 2
    You've got some workarounds here: [How to output preprocessed code AND compile it (Visual Studio)](http://stackoverflow.com/questions/7826243/how-to-output-preprocessed-code-and-compile-it-visual-studio) and here: [Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile](http://stackoverflow.com/questions/3570024/compiling-a-project-vs-2008-with-the-p-argument-preprocess-to-a-file-doesn). But essentially it's a compiler option so it will do either but not both. – Assaf Levy Jun 14 '16 at 17:39
8

My problem was a missing .lib extension, I was just linking against mylib and VS decided to look for mylib.obj.

Patrizio Bertoni
  • 2,582
  • 31
  • 43
4

I had the same problem.It caused by a "," in the name of a folder of additional library path.It solved by changing the additional library path.

harsini
  • 326
  • 2
  • 14
4

Solution 1 (for my case): restart windows Explorer process (yes, the windows file manager).

Solution 2:

  1. Close Visual Studio. Windows Logoff
  2. Logon, reopen Visual Studio
  3. Build as usual. It now builds and can access the problematic file.

I presume sometimes the file system or whoever is controlling it gets lost with its permissions. Before restarting the windows session, tried to kill zombie msbuild32.exe processes, restart visual studio, check none even showing the problem file on. No build configuration issues. It happens now and then. Some internal thing in Windows does not fix up, needs a restart.

Lissandro
  • 71
  • 5
3

In my case it was a matter of a mis-directed reference. Project referenced the output of another project but the latter did not output the file where the former was looking for.

Newtopian
  • 7,543
  • 4
  • 48
  • 71
3

I had the same problem, but solution for my case is not listed in answers. My antivirus program (AVG) determined file MyProg.exe as a virus and put it into the 'virus storehouse'. You need to check this storehouse and if file is there - then just restore it. It helped me out.

2

I had the same error, just with a Nuget package i had installed (one that is not header only) and then tried to uninstall.
What was wrong for me was that i was still including a header for the package i just uninstalled in one of my .cpp files (pretty silly, yes).
I even removed the additional library directories link to it in Project -> Properties -> Linker -> General, but of course to no avail since i was still trying to reference the non-existent header.

Definitely a confusing error message in this case, since the header name was <boost/filesystem.hpp> but the error gave me "cannot open file 'llibboost_filesystem-vc140-mt-gd-1_59.lib'" and no line numbers or anything.

Matthias
  • 3,160
  • 2
  • 24
  • 38
2

in my case it was the path lenght (incl. file name).

..\..\..\..\..\..\..\SWX\Binary\VS2008\Output\Win32\Debug\boost_unit_test_framework-vc90-mt-gd-1_57.lib;

as for the release the path was (this has worked correctly):

..\..\..\..\..\..\..\SWX\Binary\VS2008\Output\Win32\Release\boost_unit_test_framework-vc90-mt-1_57.lib;

==> one char shorter.

  1. i have also verified this by renaming the lib file (using shorter name) and changing this in the

Linker -> input -> additoinal dependencies

  1. i have also verified this by adding absolut path instead of relative path as all those ".." has extended the path string, too. this has also worked.

so the problem for me was the total size of the path + filename string was too long!

  • +1 for this, beware of the 260 character Windows path length limit that can easily be reached when complicated toolchains start creating temporary files inside of temporary directories inside of well-nested project folders. – Boston Walker Aug 25 '22 at 01:12
2

I had a similar problem. I solved it with the following command to kill the running task:

taskkill /f /im [nameOfExe]

/f: Forces the task to close. /im: The next parameter is a image name aka executable name e.g. Program.exe.

Marci
  • 302
  • 5
  • 12
1

For an assembly project (ProjectName -> Build Dependencies -> Build Customizations -> masm (selected)), setting Generate Preprocessed Source Listing to True caused the problem for me too, clearing the setting fixed it. VS2013 here.

MadeOfAir
  • 2,933
  • 5
  • 31
  • 39
1

I run into the same problem with linker complaining about the main executable missing. This happened during our solution port to the new Visual Studio 2013. The solution is a varied mix of managed and un-managed projects/code. The problem (and fix) ended up being a missing app.config file in the solution folder. Took a day to figure this one out :(, as output log was not very helpful.

Nicko Po
  • 727
  • 5
  • 21
1

I checked all my settings according to this list: http://msdn.microsoft.com/en-us/library/ts7eyw4s.aspx#feedback . It is helpful to me and for my situation, I find out that Link Dependency of projects' properties has double-quote, which should not be there.

David
  • 1,646
  • 17
  • 22
0

I'm answering because I don't see this particular solution listed by anyone else.

Apparently my antivirus (Ad-Aware) was flagging a DLL one of my projects depends on, and deleting it. Even after excluding the directory where the DLL lives, the same behaviour continued until I restarted my computer.

easuter
  • 1,167
  • 14
  • 20
0

In my case, I had replaced math library files from a previous Game Engine Graphics course with GLM. The problem was that I didn't add them to the project within Visual Studio's Solution Explorer (even though they were in the project repository).

Artorias2718
  • 575
  • 5
  • 11
0

I had this issue in conjunction with the LNK2038 error, followed this post to segregate the RELEASE and the DEBUG DLLs. In this process I had cleaned up the whole folder where these dependencies were residing.

Luckily I had a backup of all these files, and got the file for which this error was throwing back into the DEBUG folder to resolve the issue. The error code was misleading in some way as I had to spend a lot of time to come to this tip from one of the answers from this post again.

Hope this answer, helps someone in need.

Community
  • 1
  • 1
N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
0

I solved it by adding an existing project to my solution, which I forgot to add in the first time.

Markus Weber
  • 1,059
  • 1
  • 11
  • 24
0

I had the same error:

fatal error LNK1104: cannot open file 'GTest.lib;'

This was caused by the ; at the end. If you have multiple libraries, they should be separated by empty space (spacebar), no comma or semi-colons!

So don't use ; or any anything else when listing libraries in Project properties >> Configuration Properties >> Linker >> Input

zar
  • 11,361
  • 14
  • 96
  • 178
0

I tried above solution but didnt work for me. So i rename the exe and rebuild the solution. It works for me.

user3500315
  • 61
  • 1
  • 4
0

I had this exact error when building a VC++ DLL in Visual Studio 2019:

LNK1104: cannot open file 'C:\Program.obj'

Turned out under project Properties > Linker > Input > Module Definition File, I had specified a def file that had an unmatched double-quote at the end of the filename. Deleting the unmatched double quote resolved the issue.

MikeOnline
  • 994
  • 11
  • 18
0

Killed msbuild32.exe and built again. It worked for me.

Imad
  • 7,126
  • 12
  • 55
  • 112
0

My issue was caused by other application using the .dll file I was trying to debug.

Closing the application that was using the .dll solved it for me.

NAGA
  • 13
  • 3
0

Possible solutions:

  1. Check if path contain any white spaces, Go to Properties > Linker > Input > additional path and include "path with white space"

  2. If program are still running, close everything and restart.

  3. Check if .obj file is not created. This happens when you directly build a project while Properties > C++ > Preprocessor > Generate preprocessor file is on. Turn it off and build the project then you can onn Properties > C++ > Preprocessor > Generate preprocessor file.

Faizanur Rahman
  • 474
  • 3
  • 12
-1

I hit the same problem with "Visual Studio 2013".

LNK1104: cannot open file 'debug\****.exe

It resolved after closing and re-starting Visual studio.

user3860869
  • 121
  • 1
  • 1
  • 6
-4

I was having the same problem , I have just copied the code to new project and started the build . Some other error started coming. error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead

To solve this problem again, I have added my one property in the Project project as below. Project -> Properties -> Configuration property -> c/c++ . In this category there is field name Preprocessor Definitions I have added _CRT_SECURE_NO_WARNINGS this to solve the problem Hope it will help ...

Thank You

Sunil
  • 3
  • 1