C/C++ How to handle the Specification and Implementation files to be used in C++?

  • Thread starter Thread starter yungman
  • Start date Start date
  • Tags Tags
    files
AI Thread Summary
The discussion revolves around the challenges of organizing and integrating C++ class files, specifically the header (.h) and implementation (.cpp) files, while using Visual Studio. The user expresses frustration over needing to use absolute paths for includes, which complicates file management. Suggestions include keeping all project files in a single folder to simplify includes, as well as utilizing Visual Studio's project properties to set additional include directories. The conversation highlights the importance of modular code organization, with a focus on separating class declarations and definitions for better management. There are also discussions about the potential for confusion when compiling separate files and the benefits of learning to manage project structures effectively. The user ultimately finds a method that works for them, though they acknowledge the learning curve and inconsistencies in Visual Studio. They also reflect on the broader concepts of object-oriented programming and the importance of understanding class structures as they progress in their studies.
  • #51
yungman said:
Why it run nicely with Project2 if it is all wrong?
Did you find the "additional include directories" property for your project, and for your source files individually?
 
Technology news on Phys.org
  • #52
Before I start digging into the file stuffs. I ran more experiments based on looking at the file explorer and to find out why the files don't show up when Project2 works.

This is what I did. With Project 2 that I use ADD-->Existing file to go to Test folder to get those files. I went to Test folder and temporary deleted the Temp.h. Project2 FAILED to compile. This means the Project2 NEVER pull in the files, just by reference(if that's the right word). That might be the reason why it doesn't show up in file explorer.

If I do copy then ADD-->New, You will see all 3 files in the file explorer like what Mark show.

So the result is, either I do all ADD-->Existing for all 3 files, OR ADD-->New and copy the codes for all 3 files. They BOTH WORK. BUT if I mix some ADD-->Existing, some ADD-->New and copy, it FAIL.

Why?

This go beyond digging through the files and all. VS obviously gives the provision of ADD-->New and ADD-->Existing. How come there is limitation? Checking into the files ONLY shows the result/symptom, WHY ADD NEW and ADD Existing cannot be combined? This is more troubling to me.

Now, I am going to look into what Jarvis said. I still don't believe they are the same.
 
Last edited:
  • #53
yungman said:
Why?
How many times will you keep asking why and ignore the answer?

Because the source file needs to be in the same directory as the include file, or the "additional include directories" of the source file needs to have the directory where the header files added.

This is the last time I'll respond to any of your posts. Good luck.
 
  • Like
Likes Vanadium 50
  • #54
yungman said:
WHY? Why it won't show if I do ADD-->Existing and navigate to another folder to get the file?
Add --> Existing item... doesn't copy files to the directories for the project you're working on. The file is added to the project and will be shown in the VS Project Explorer, but the file will still be in whatever directory it already was in.

What you should be doing is Add --> New item... This creates a blank file with the name you choose, and puts it in the right directory. Then you can copy the text from the old file, and paste it into the file you've created.
 
  • #55
Mark44 said:
Add --> Existing item... doesn't copy files to the directories for the project you're working on. The file is added to the project and will be shown in the VS Project Explorer, but the file will still be in whatever directory it already was in.

What you should be doing is Add --> New item... This creates a blank file with the name you choose, and puts it in the right directory. Then you can copy the text from the old file, and paste it into the file you've created.

Thanks for the answer

I know that. At this point this is NOT my question anymore as I posted in post #52.

My question is if it is so important to have the file physically inside the project( to show in file explorer). Why then Project2 run just fine using ALL Add-->Existing?

Why then the exact same code FAILED if I mix Add-->Existing with Add-->New? It has to be either ALL Add-->Existing OR Add-->New?I have been searching in VS, I found Exporting Template so others can use it. Is that the right way in the future to link Class Object to be used in the program? I've been trying to use Add--> Existing thinking that it's better to link external files from another folder.
Thanks
 
Last edited:
  • #56
Jarvis323 said:
How many times will you keep asking why and ignore the answer?

Because the source file needs to be in the same directory as the include file, or the "additional include directories" of the source file needs to have the directory where the header files added.

This is the last time I'll respond to any of your posts. Good luck.
I am not ignoring your answers, I actually looked back to your posts. I understand you and Mark said I need to have all 3 files inside the project using file explorer as Mark said in post #39. If I do Add-->New and copy all the files in. This, I can see in file explorer all 3 files are there.

My questions are why Project2 works without any of the files in the project folder then? I use Add-->Existing that doesn't actually pull the files in.

AND the most important question is why then if I MIX Add-->Existing and Add-->New, it fail no matter what?

I hope you can reconsider, you have been very helpful and I cannot thank you enough.

Thanks
 
Last edited:
  • #57
Hi Jarvis

You posted a video and I notice you deleted the post. I was watching the video, there's nothing similar to the video with my VS. I even tried starting with Console App or Window Desktop Wizard, they are nowhere the same as in the video. I cannot follow it. VS 2019 make it very automatic. I know how to add in the .h and .cpp file no problem at all. That's not in question.

Thanks anyway.
 
  • #58
yungman said:
Hi Jarvis

You posted a video and I notice you deleted the post. I was watching the video, there's nothing similar to the video with my VS. I even tried starting with Console App or Window Desktop Wizard, they are nowhere the same as in the video. I cannot follow it. VS 2019 make it very automatic. I know how to add in the .h and .cpp file no problem at all. That's not in question.

Thanks anyway.
I guess you misread all of my responses.

When you "add existing" to all three files, all three files are in the same directory (not in the project directory, but the cpp is in the directory that the h is in). That's why it works.

I posted the video because it shows how to put header files in a separate place as a cpp file. VS 2019 might have a different GUI, but it works the same way. You just need to figure out where the "additional include directories" setting is. I bet it would take 5 minutes to find it if you actually looked for it.

Until you figure that out, you're just wasting your time. It's like you keep walking into a closed door because you refuse to listen when someone tells you how to open it.

I deleted the video because, although it shows how to organize h and cpp files separately, the author added the path to his "src" folder in the "additional include directories", which I think doesn't make sense and could lead to confusion about how things actually work.

VS apparently allows you to set different "additional include directories" for each cpp file. This makes sense, because you might have different header files in different places with the same name, and need to control which one is included by which cpp file. VS designers had to make a choice what the default behavior is in different cases. I guess the way you are using it, the default is to NOT add the path to the header file in the "additional include directories" property of the cpp file. So you have to do that manually, or you have to figure out how to change the VS default, or do things a different way so that the default is what you wanted.
 
Last edited:
  • Like
Likes yungman
  • #59
Jarvis323 said:
I guess you misread all of my responses.

When you "add existing" to all three files, all three files are in the same directory (not in the project directory, but the cpp is in the directory that the h is in). That's why it works.

I posted the video because it shows how to put header files in a separate place as a cpp file. VS 2019 might have a different GUI, but it works the same way. You just need to figure out where the "additional include directories" setting is. I bet it would take 5 minutes to find it if you actually looked for it.

Until you figure that out, you're just wasting your time. It's like you keep walking into a closed door because you refuse to listen when someone tells you how to open it.

I deleted the video because, although it shows how to organize h and cpp files separately, the author added the path to his "src" folder in the "additional include directories", which I think doesn't make sense and could lead to confusion about how things actually work.

VS apparently allows you to set different "additional include directories" for each cpp file. This makes sense, because you might have different header files in different places with the same name, and need to control which one is included by which cpp file. VS designers had to make a choice what the default behavior is in different cases. I guess the way you are using it, the default is to NOT add the path to the header file in the "additional include directories" property of the cpp file. So you have to do that manually, or you have to figure out how to change the VS default, or do things a different way so that the default is what you wanted.
After a search, I found that the "additional include directories" option is in the C++ General tab for VS 2019.
https://docs.microsoft.com/en-us/cpp/linux/prop-pages/general-linux?view=vs-2019
 
  • Like
Likes yungman
  • #60
yungman said:
My questions are why Project2 works without any of the files in the project folder then? I use Add-->Existing that doesn't actually pull the files in.
For a project named Temp, VS keeps track of where all the files are in a file named Temp.vcxproj. This is a text file, so you can read it. It's not a good idea for you to edit it, if you don't know what you're doing. You can find the .vcxproj file for your project in the 2nd-level directory for your project, which will normally have the same name as the top-level directory.
yungman said:
AND the most important question is why then if I MIX Add-->Existing and Add-->New, it fail no matter what?
I don't know. This is not enough information to go on. I've described a way that works, so why are you exploring weird ways that you know don't work.
yungman said:
My question is if it is so important to have the file physically inside the project( to show in file explorer).
It's not important, other than to keep different projects separate from each other. The files that make up a multi-file project can be pretty much anywhere, as long as there is information about their locations in <project_name>.vcxproj, but that's not a good way to organize things.
All of your programs have been built from single projects. More complex programs can be made up of multiple projects. At the top level in Solution Explorer is the Solution, which is named Temp in your case. This solution could be made up of two or more projects, each with its own Header Files section and Source Files section, as well as its own References, External Dependencies, and Resource Files sections.
yungman said:
Why then Project2 run just fine using ALL Add-->Existing?
The project won't build if you don't save all the files -- so that the .vcxproj file gets updated. If it gets updated, then things should work just fine, but if you build before this file is updated, then you're get compile errors. That's all I can think of.
The only time I use Add -> Existing item... is when I have already copied the file into the appropriate directory, as viewed in Windows Explorer. Then I use Add --> Existing item...
 
  • Like
Likes yungman
  • #61
I printed out the response, I need to take time to read it. I'll be back.

thanks
 
  • #62
Mark44 said:
For a project named Temp, VS keeps track of where all the files are in a file named Temp.vcxproj. This is a text file, so you can read it. It's not a good idea for you to edit it, if you don't know what you're doing. You can find the .vcxproj file for your project in the 2nd-level directory for your project, which will normally have the same name as the top-level directory.
.....
Do you mean Temp.vcxproj.filter? I use notepad to open this file and these are the 3,

First one is with all 3 files physically in the project. You can see all three at the bottom.
vcxproj.filter with files in project.jpg

This one with Add-->Existence. You can see it shows the path to the files
vcxproj.filter without files in project.jpg

Finally the one with only the source.cpp physically in the project folder
vcxproj.filter one files in project.jpg

Is this what you are referring to, that I should check this to know where the files are? regarding to you said you don't have enough info to comment on the Temp project that doesn't work with mixed Add-->New and Add-->Existing. The 3rd print out is the file. You can see where the 3 files came from, see whether you can make some heads and tails out of it.

I am still reading through the responses.

Thanks
 
  • #63
Screenshot (50).png

Screenshot (51).png
 
  • Like
Likes yungman
  • #64
Jarvis323 said:
Hi Jarvis

Thanks for still helping me, I really appreciate this. I follow you and get to this point but I really don't follow what am I supposed to do with it next.

Jarvis323 said:
After a search, I found that the "additional include directories" option is in the C++ General tab for VS 2019.
https://docs.microsoft.com/en-us/cpp/linux/prop-pages/general-linux?view=vs-2019

I really don't follow what's going on here. what do you want me to learn from this? I am really lost.

Thanks
 
  • #65
yungman said:
Do you mean Temp.vcxproj.filter?
No, I mean just exactly what I said -- <project_name>.vcxproj. In this case, it would be Temp.vcxproj.
 
  • #66
Hi Guys

I really don't follow what's going on here. I thought in Solution Explorer, there is Header files that I add in the .h files and Source files that I add in the .cpp files. Maybe at this time, I should just accept that I can only do Add-->New to either the Header files and Source files in the Solution explorer, then I can move on. Any other things I need to watch out?

Thanks everyone for the time.
 
  • #67
  • #68
Mark44 said:
No, I mean just exactly what I said -- <project_name>.vcxproj. In this case, it would be Temp.vcxproj.
I tried that, this is what I got:
Nothing like you described.

Thanks
 

Attachments

  • #69
yungman said:
Hi Jarvis

Thanks for still helping me, I really appreciate this. I follow you and get to this point but I really don't follow what am I supposed to do with it next.
I really don't follow what's going on here. what do you want me to learn from this? I am really lost.

Thanks
You just add the path of your header files in that box that I pointed out. Then when the compiler compiles your program, it will look for header files in those directories that you've listed in the box. That is the solution to your problem. Then you won't get the error that the header file wasn't found, and no matter how you added the files to the project, it will work. I went over what is going on multiple times already in previous posts, but I guess there is a communication barrier we can't get through.

I recommend to just keep it as simple as possible and follow Mark's advice on how to get something working. If you want to figure out how to put files somewhere else besides the project directory, or figure out what was wrong with what you've done, you can always come back to and re-read the thread.
 
  • Like
Likes yungman
  • #70
Jarvis323 said:
You just add the path of your header files in that box that I pointed out. Then when the compiler compiles your program, it will look for header files in those directories that you've listed in the box. That is the solution to your problem. Then you won't get the error that the header file wasn't found, and no matter how you added the files to the project, it will work. I went over what is going on multiple times already in previous posts, but I guess there is a communication barrier we can't get through.

I recommend to just keep it as simple as possible and follow Mark's advice on how to get something working. If you want to figure out how to put files somewhere else besides the project directory, or figure out what was wrong with what you've done, you can always come back to and re-read the thread.
You mean like this:
Add directory.jpg


I added it in and hit apply. I went back to Solution Explorer, I did not see that. There is no indication I added anything.

yes, I feel I am wasting you and Mark's time. I just stick with using Add-->New and copy or type in the codes and it will work for now. Again, thanks for taking the time to help me.

Thanks
 
  • #71
If you have spaces in the path then you need to put quotes around it I think "c:\...". You can use the browser to select the folder if you hit the down arrow, and then the file icon.

Nothing will be indicated and no files will be added to the project. But the red squiggly under your #include "someheaderfileinrandomfolder.h" will go away and your problem that the compiler didn't know where to look for your header files will be solved and your program will compile fine.

IMPORTANT: also, the configuration selected in the upper left corner needs to be set to "All Configurations" if you want it to apply to both "Debug" and "Release" modes.
 
Last edited:
  • Like
Likes yungman
  • #72
Jarvis323 said:
If you have spaces it might be a problem. You can use the browser to select the folder if you hit the down arrow, and then the file icon.

Nothing will be indicated and no files will be added to the project. But the red squiggly under your include will go away and your program will compile fine.
I think I got it:

I click Edit, this is the menu that show up:
Edit manual.jpg


Then I hit the file icon and search the path and OK.
Add directory.jpg


But I still don't see anything added in the Solution Explorer. Looks the same as before I added it.

Thanks
 
  • #73
yungman said:
I think I got it:

I click Edit, this is the menu that show up:
View attachment 270501

Then I hit the file icon and search the path and OK.
View attachment 270502

But I still don't see anything added in the Solution Explorer. Looks the same as before I added it.

Thanks
It shouldn't look any different. But now your project will compile successfully. Also if you open the vcxproj file in notepad you will see a line that it generated.
 
  • Like
Likes yungman
  • #74
yungman said:
I tried that, this is what I got:
Nothing like you described.

Thanks
Is this from a project that doesn't build?
This is what Temp.vcxproj looks like for my working program. Down toward the bottom is where the source files and header files are listed.
XML:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>15.0</VCProjectVersion>
    <ProjectGuid>{65181934-D7D5-42C1-9FA7-E8A4CB3EF064}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>Temp</RootNamespace>
    <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClInclude Include="Rectangle.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="Rectangle.cpp" />
    <ClCompile Include="RectImpl.cpp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
 
  • #75
Jarvis323 said:
It shouldn't look any different. But now your project will compile successfully. Also if you open the vcxproj file in notepad you will see a line that it generated.
THANKS A MILLION

How do you know that! You said you don't even use VS!

Yes, that works. I did it on the Temp file and I runs!

Ha ha, I mess up something, some how, I closed the Solution Explorer and I can't get back my normal stuffs on the right. But that's a different problem I created myself.

I can sleep better now.

Thanks I really appreciate your help. This resolve my very problem. Now I know I have to go to include external files.
 
  • #76
Mark44 said:
Is this from a project that doesn't build?
This is what Temp.vcxproj looks like for my working program. Down toward the bottom is where the source files and header files are listed.
XML:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>15.0</VCProjectVersion>
    <ProjectGuid>{65181934-D7D5-42C1-9FA7-E8A4CB3EF064}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>Temp</RootNamespace>
    <WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v141</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <SDLCheck>true</SDLCheck>
      <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <ConformanceMode>true</ConformanceMode>
    </ClCompile>
    <Link>
      <SubSystem>Console</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClInclude Include="Rectangle.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="Rectangle.cpp" />
    <ClCompile Include="RectImpl.cpp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
It is not like this, there only very little stuffs in it. I linked the txt file in post#68. It looks like this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>
Anyway, I had itchy fingers, somehow I closed the Solution explorer, how can I open it back. VS has memory, I screwed up in one file, I closed it. I open another project, my screw up pass on to the next project! Now I don't have Solution Explorer in other projects. Is there a quick way to go back to default? I am having a hard time with VS, more so than C++!

Thanks
 
  • #77
yungman said:
It is not like this, there only very little stuffs in it. I linked the txt file in post#68. It looks like this:
Yes, I saw the file you had attached. If that was the whole thing, then it's no wonder the program wouldn't build. Best thing to do is to save the three files (the two .cpp files and the header file) somewhere, close VS, and from Windows Explorer, delete the directories.
Then start from scratch with a new project. If you have deleted the Temp directory and everything under it (after saving the three files I mentioned), you can
create a new empty project (you can call it Temp or whatever),
In VS, Add --> New items in the Source Files directory.
In VS, Add --> New items in the Include Files directory.
Copy each of the saved files into the source file and header file place-holders
Build.
yungman said:
Anyway, I had itchy fingers, somehow I closed the Solution explorer, how can I open it back.
View menu --> Solution Explorer
 
  • Like
Likes yungman
  • #78
Mark44 said:
Yes, I saw the file you had attached. If that was the whole thing, then it's no wonder the program wouldn't build. Best thing to do is to save the three files (the two .cpp files and the header file) somewhere, close VS, and from Windows Explorer, delete the directories.
Then start from scratch with a new project. If you have deleted the Temp directory and everything under it (after saving the three files I mentioned), you can
create a new empty project (you can call it Temp or whatever),
In VS, Add --> New items in the Source Files directory.
In VS, Add --> New items in the Include Files directory.
Copy each of the saved files into the source file and header file place-holders
Build.
View menu --> Solution Explorer
Thanks for the reply, I got back my Solution Explorer

No, it's from a working project. They all are this short. To confirm I am opening the right one, this is the one I open, this is a working project:
vcxproj.jpg


thanks for all the help.
 
  • #79
I still cannot get back to the original Solution Explorer like this that show Header file and Source file:
Solution Explorer.jpg

The solution Explorer that I got back using View-->Solution Explorer has less and not include like above as shown below. It's missing the two:
Solution Explorer short.jpg


I tried ADD --> Folder and just put back Header file and Source File? I did Add-->Existing on both Temp.cpp and Temp.h into the corresponding folder and ran. It works. Is that the right way?

Thanks
 
Last edited:
  • #80
yungman said:
The solution Explorer that I got back using View-->Solution Explorer has less and not include like above as shown below. It's missing the two:
In your 2nd screen shot, the one with Solution Explorer for your Temp project, just below where it says Solution Explorer, there are four icons. The fourth one, just to the right of the house icon, has a dropdown menu. This icon toggles between the VS solution hierarchy and the directory hierarchy. In the 2nd screen shot, you're showing the directory hierarchy. In the first screen shot, you're showing the solution hierarchy.
 
  • #81
Mark44 said:
In your 2nd screen shot, the one with Solution Explorer for your Temp project, just below where it says Solution Explorer, there are four icons. The fourth one, just to the right of the house icon, has a dropdown menu. This icon toggles between the VS solution hierarchy and the directory hierarchy. In the 2nd screen shot, you're showing the directory hierarchy. In the first screen shot, you're showing the solution hierarchy.
Thank Mark for all the help.
Now I know.

But I did something more stupid along the way last night. I think I deleted something. If I knew about toggling the hierarchy, I might not accidentally deleted the folder. Here is the screen shot of the Solution Hierarchy of Project2 that was working before. You can see the the Header folder and Source folder are all gone. There is no file in it. You can see below there there is no Header folder and Source folder. All the files have yellow triangle with '!', there is no file in them and obviously cannot compile, everything is gone.

This is Project2, it was a working program that I use Add--> Existing to link Temp.h to the Header folder and Temp.cpp and source.cpp to the Header folder from external folder. How do I get those back. I added back those folders manually, it worked last night, but I cannot repeat it on this project.

Solution Explorer short.jpg


Thanks
 
  • #82
Here's what I said before in post #77.
Mark44 said:
Best thing to do is to save the three files (the two .cpp files and the header file) somewhere, close VS, and from Windows Explorer, delete the directories.
Then start from scratch with a new project. If you have deleted the Temp directory and everything under it (after saving the three files I mentioned), you can
create a new empty project (you can call it Temp or whatever),
In VS, Add --> New items in the Source Files directory.
In VS, Add --> New items in the Include Files directory.
Copy each of the saved files into the source file and header file place-holders
Build.
Since we're just going around in circles, with little or no forward progress, I'm closing this thread.
 
  • Like
Likes Vanadium 50
Back
Top