When I tried to create folders to organize my C++ code in Visual Studio 2015, I did this in the file explorer: made several folders and dropped files in. Like this:
So the Solution Explorer in VS2015 looked like this:
It looked perfect, all filtered into folders I created. However, it threw some error when I ran the program (“xxxx” is something specifically related to the code):
Error LNK2019 unresolved external symbol “public: void __cdecl xxxxxxxxxxxx referenced in function main”
So this is saying, some functions or variables were not defined so the main() function did not recognize them. Wait, I had already defined those in the files and it ran perfectly when I had not created the folders.
I checked everything about the code itself and found two things:
- The file path in “#include” should be including the folder instead of just the file name. E.g. #include “Folder1\file1.cpp”;
- Again, take a look back at the Solution Explorer. There was a minus symbol ahead of “File1” and “File2”. It does not pop out any tip when the mouse is hovering on it, but it means the files were pending to be added to the project.
What I did was: Right click on the folder, and choose “Include in Project”, or manually right click on every file to be added to the project.
This was so simple. I figure this is a good design for situations where the developers want to compare between several large files, they can simply do the “include” instead of editing the code.