0

I know this question has been answered lots already, I have tried the solutions but they are not working for me.

My error is the following:

Erro: LNK1104   cannot open file 'C:\Users\...\source\repos\ont lang.obj'

I am using the latest MSVC compiler and I am using Visual Studio. I have tried going on task manager and locating tasks running it, but i couldn't find anything.

I have done Properties -> Linker -> General -> Additional Library Properties and assigned that C:\Users\...\source\repos\ont lang;%(AdditionalLibraryDirectories) but i am still getting an error. As you can see here

Screenshot of Linker -> General

This was the solution in this question but I had no luck. I compiled it about 1 minute before and it worked fine but then I got the Link Error Message 1104. I have also tried this:

here

but I still had no luck. As i said before, it worked one minute, all I did to it was more code to the file and the next minute it didn't compile. I have also tried cleaning the project and rebuilding it again but still got the same issue. So does anyone know how I would go about resolving this error?

BTW: I have checked my file is actually real, here is proof:

prooft of file is there.

  • 1
    i did nothing except that I did something... thats what version control is for. – 463035818_is_not_an_ai Dec 23 '22 at 13:33
  • You can try to clean your project and rebuild it. Looks like linker cannot open object that was built before. – Bolderaysky Dec 23 '22 at 13:36
  • @Bolderaysky Yes, I have just tried that still getting the same error. – Robert Shepherd Dec 23 '22 at 13:38
  • 2
    `C:\Users\...\source\repos\ont lang` -- Is this supposed to be one directory? If so, shouldn't you surround it with double quotes, due to the space character between `ont` and `lang`? – PaulMcKenzie Dec 23 '22 at 13:51
  • I would suggest restarting Visual Studio, opening the project file to see if that path has snuck in somewhere else, and double-checking your linker inputs. – molbdnilo Dec 23 '22 at 13:58
  • @PaulMcKenzie Thankyou, but it has now changed the error message to `LNK1104 cannot open file 'lang\.obj' ont lang C:\Users\...\source\repos\ont lang\LINK 1104 ` – Robert Shepherd Dec 23 '22 at 14:05
  • Did you make it `"C:\Users\...\source\repos\ont lang";%(AdditionalLibraryDirectories)` – drescherjm Dec 23 '22 at 14:08
  • @drescherjm I made it `"C:\Users\...\source\repos\"ont lang";%(AdditionalLibraryDirectories)` Should I have the extra `"` after `\repos\`? – Robert Shepherd Dec 23 '22 at 14:09
  • Remove the " before ont – drescherjm Dec 23 '22 at 14:10
  • @drescherjm Thankyou, but I have done that but the same error message appears – Robert Shepherd Dec 23 '22 at 14:12
  • @RobertShepherd Since I cannot copy text from an image, you should have used the entire (real, full) directory without the `...` and you should surround it with double quotes. – PaulMcKenzie Dec 23 '22 at 14:17
  • @PaulMcKenzie Thanks but I am getting the following error message (the original one): ` Error LNK1104 cannot open file 'C:\Users\rober\source\repos\ont lang.obj' ont lang C:\Users\rober\source\repos\ont lang\LINK 1` when I use: `"C:\Users\rober\source\repos\ont lang"` – Robert Shepherd Dec 23 '22 at 14:25
  • Well, since we don't have access to your machine, we don't know what is at that directory, or even if that directory exists. – PaulMcKenzie Dec 23 '22 at 14:27
  • "Erro: LNK1104 cannot open file ..." - Obvious question; does that file exist? Is it supposed to? – Jesper Juhl Dec 23 '22 at 14:27
  • @JesperJuhl, Yes it does, just double checked now. – Robert Shepherd Dec 23 '22 at 14:29
  • @PaulMcKenzie Just updated the question now, has a picture of the file. – Robert Shepherd Dec 23 '22 at 14:33
  • 1
    I don't see a file with the extension `.obj`. I don't see anything associated with an external library, no `.lib` files or `.obj` files. The directory seems to only contain Visual Studio project-related files and a `.cpp` source file. In short, that isn't a folder to be looking for external libraries, since they're not there. – PaulMcKenzie Dec 23 '22 at 14:40
  • @PaulMcKenzie Would main.obj be it? – Robert Shepherd Dec 23 '22 at 14:43
  • So would I not need the whole: Properties -> Linker -> General -> Additional Library Properties steps? – Robert Shepherd Dec 23 '22 at 14:44
  • Remove the "C:\Users\rober\source\repos\ont lang" altogether from that setting. Either you will get a linker error saying "I don't know where this function/library is", or your project will finally build correctly. If it is one where the function can't be found, at the very least you will know *what* the linker is attempting to find (instead of guessing). – PaulMcKenzie Dec 23 '22 at 14:45
  • @PaulMcKenzie So the linker is trying to find `ont lang.obj` if the error message is: `LNK1104 cannot open file 'C:\Users\rober\source\repos\ont lang\x64\Debug\ont lang.exe' `? – Robert Shepherd Dec 23 '22 at 14:48
  • `C:\Users\rober\source\repos\ont lang\x64\Debug\ont lang.exe` -- Then the issue is that the compiler is failing to create that executable due to an issue we cannot diagnose from here. Anything from permissions to an AV preventing creation, or something else. I would suggest working with directories with no spaces in the name. – PaulMcKenzie Dec 23 '22 at 14:51
  • Ok, how would i deal with the permissions, would I make run as administrator? – Robert Shepherd Dec 23 '22 at 14:53
  • Do you really need to use a space in the name of your project and folder? Maybe renaming will get you around this problem. I have learned many years ago to never use a space in a filename or folder name when using `c` or `c++` – drescherjm Dec 23 '22 at 16:14
  • Regarding LNK1104, you could refer to this document, it may be that your file name contains spaces. There may also be some problems in the process of linking the library. I suggest you refer to the method in MSDN to link the [DLL](https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=msvc-170) or [LIB](https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-static-library-cpp?view=msvc-170). – Yujian Yao - MSFT Dec 26 '22 at 03:23
  • *"This was the solution in [this question](https://stackoverflow.com/questions/63232097/how-can-i-fix-this-lnk1104-error-in-visual-studio) but I had no luck."* -- that question asked about an error finding a library (`.lib`). Your error involves not finding an object file (`.obj`). A solution for libraries is not necessarily (I would even say "probably not") a solution for object files. – JaMiT Dec 26 '22 at 11:16
  • *"I have checked my file is actually real, here is proof:"* -- your image shows the wrong directory. Your image shows the contents of `C:\Users\...\source\repos\ont lang` while the file that cannot be opened is one level up from that, in `C:\Users\...\source\repos`. *However, given the similarity, I'd guess VS got itself confused and dropped the file name. That is, it somehow managed to look for `ont lang.obj` when it should have looked for `ont lang\main.obj`. Restarting VS or rebooting the computer sometimes fixes this sort of weirdness.* – JaMiT Dec 26 '22 at 11:22
  • I suggest you refer to the solution in this [issue](https://stackoverflow.com/questions/133698/why-does-fatal-error-lnk1104-cannot-open-file-c-program-obj-occur-when-i-c), it may help you. – Yujian Yao - MSFT Mar 23 '23 at 08:28

0 Answers0