Frederik
Frederik

Reputation: 23

Cannot open source file; C++; Visual Studio

I'm learning about dll files and trying to create one. My problem is that when i try to build my solution in visual studio, i'm getting errors saying e.g. "cannot open source file string.h".

This happens for multiple header files. The error is produced by a file other than mine, which includes string.h

error list from VS

I can't figure out how to fix this error, and any help will be greatly appreciated!

Upvotes: 0

Views: 25473

Answers (5)

KoKlA
KoKlA

Reputation: 978

I had the same problem with a Visual Studio Project i downloaded from github .

Issue was the Windows SDK Version was set to a version i hadn't installed. I solved it by changing the Configuration Properties -> General -> Windows SDK Version to "< inherit from parent or project defaults >"

enter image description here

Upvotes: 1

Ivan P.
Ivan P.

Reputation: 926

I had this issue once. The reason was: in VC++ Directories > Include Directories option I had ";" at the end of the line. I edited that property and left a symbol there. It should end with "$(IncludePath)". After removing that character I managed to get it working.

Instead of reinstalling Visual Studio review your project settings.

Cleaning and rebuilding project may help, as well as closing and reloading project. You may also try removing binary build artifacts generated for your project, such as .lib and .obj

Upvotes: 0

Alex Ezz21
Alex Ezz21

Reputation: 11

Hmph try unsistalling and reinstalling Visual Studio this thing happened to me 2 years ago on Vs 2017 because I opened a broken source andd it broke my visual studio :(

Upvotes: 1

Iancovici
Iancovici

Reputation: 5731

I bet you've resolved it by now, but for others who experience this issue, unless you directly deleted files from installed visual studio directory I wouldn't resort to an uninstall/reinstall solution, because then you don't know what went wrong and why.

When I ran into this issue. Two things I had to check and fix to resolve

  1. XML file may have been directly edited, and butchered
    • Edit .vcxproj file, make sure that paths between IncludePath, and LibraryPath tags aren't separated by new lines (cr/lf)
  2. Project properties may no longer be including default directories.
    • Right click project properties. Navigate to VC++ Directories, and select "inherit from parent or project defaults" for: Executable Directories, Reference Directories, Library WinRT Directories, Source Directories, Exclude Directories.

Upvotes: 1

Angelica
Angelica

Reputation: 488

Image of Visual Studio C++ Include Directories

Double clicking item will give you option to change the list. But by default it is generally not required. Until it is changed. If you feel that you have messed everything. Just uninstall visual studio and reinstall it. Every thing will be back to normal.

Upvotes: 1

Related Questions