且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Visual Studio C ++ 2012中创建文件夹

更新时间:2022-05-27 04:57:24

IDE为此提供了一个命令 New Folder。它甚至出现在项目+添加上下文菜单中,使用工具+定制查看上下文菜单时可以看到一些内容。但是,它隐藏在C ++ IDE中。

The IDE has a command for that, "New Folder". It is even present in the Project + Add context menu, something you can see when you look at the context menu with Tools + Customize. It is however hidden in the C++ IDE. Intentionally.

重要的是要理解为什么隐藏它。这样可以避免麻烦,而在使用Explorer创建文件夹时会遇到麻烦。

Its important to understand why it is hidden. It keeps you out of trouble, the kind of trouble you'll get into when you create folders with Explorer.

问题所在是C ++文件的生成方式。编译完成后,它们会生成一个.obj文件。该obj文件存储在名称为项目设置的目录中。您可以通过项目+属性,常规,中间目录设置来查看它。对于单个.cpp文件,它是C / C ++,输出文件,目标文件名。该默认值是 $(IntDir)宏,该宏告诉编译器使用中间目录设置。使用默认设置,用于Debug构建的所有.obj文件最终都位于Debug子目录中。 Release版本的Release子目录。不管.cpp的存储位置。

At issue is the way C++ files get built. They produce an .obj file when the compiler is done with them. That obj file is stored in a directory whose name is a project setting. You see it with Project + Properties, General, Intermediate Directory setting. For an individual .cpp file, it is C/C++, Output Files, Object File Name. The default for that one is $(IntDir) a macro that tells the compiler to use the Intermediate Directory setting. With the default settings, all .obj files for the Debug build end up in the Debug subdirectory. Release subdirectory for the Release build. Regardless where the .cpp was stored.

也许您现在看到了陷阱。如果您使用.cpp文件创建子目录,则该子目录中的.cpp文件的名称与另一个子目录中的另一个.cpp文件相同时,您会遇到麻烦。它们产生一个具有相同名称的.obj文件。一个覆盖另一个,最后一个被编译。这会产生非常神秘的链接器错误。您将得到重复的符号错误,因为最后一次构建的.obj文件被链接了两次,并且丢失了覆盖的.obj文件的符号错误。

Maybe you see the bear trap by now. If you create a subdirectory with .cpp files then you'll get in trouble when that subdirectory has a .cpp file whose name is identical to another .cpp file in another subdirectory. They produce an .obj file with the same name. One overwrites the other, which ever one was compiled last. That produces very mystifying linker errors. You'll get duplicate symbol errors because the last built .obj file is linked twice and missing symbol errors for the overwritten .obj file.

因此,继续创建一个子目录但是要当心这个问题。如果发生这种冲突,则必须更改.cpp文件的对象文件名设置。

So go ahead and create a subdirectory but beware this problem. You have to change the Object File Name setting for the .cpp file if such a collision happens.