Visual Studio "hidden" preprocessor definition - c++

In a project I'm working on, I have two preprocessor definitions (CPU_RENDER and GPU_RENDER) that control whether the build uses the CPU to render a scene or the GPU. I've been flipping back and forth between these two as I develop the software.
Suddenly, however, a few of the files claim GPU_RENDER is defined despite the fact that I removed it from Visual Studio's preprocessor definitions. Others work correctly. This isn't just visual, as the CPU build fails on link now, trying to find the source code for certain GPU only functions.
I've performed a search of the entire solution for "#define GPU_RENDER", just in case I did something stupid, but that came up empty. I then searched for every time I reference GPU_RENDER, but all those were just ifdefs.
I haven't used any new libraries so I don't think this could be a name collision.

Apparently the offending files had acquired their own set of preprocessor definitions. (I must have hit "Properties" with a file selected instead of the project at some point, making the file have a local set of definitions)
Deleting the file's personal definitions and ticking the "inherit from parent or project defaults" box solves the problem.

Related

defining preprocessor definitions on a single file

I'm in the process of migrating a project to C++17. There are a couple instances of old code with deprecation warning not within my control. An example of one of these warning is, _SILENCE_CXX17_SHARED_PTR_UNIQUE_DEPRECATION_WARNING. In visual studio, I've been adding these to properties->Preprocessor Def. So far this is working fine.
To prevent the possibilities of me or someone else creating new deprecated code in the future somewhere else in the project, is there a way to minimize the scope of the preprocess definition down to a single file instead of an entire project?
is there a way to minimize the scope of the preprocess definition down to a single file?
Yes, it is possible to have different preprocessor macros for a single file in Visual Studio.
In the Solution Explorer, RMB -> Properties on a specific file to change its properties.

Copy Visual Studio project settings to new project?

Background
I'm running Visual Studio Community 2015 on Windows 10, writing C++ code.
I have been handed a solution with two projects in it. I need to create a duplicate of one of the projects, but using different source and header files (containing roughly identical code, but located in another place in the file system).
The project that I want to duplicate uses a lot of libraries, and I don't know how that was set up. All I know is that it works for that project, and I need it to work for the duplicate project too.
Problem
The problem I'm having is that at least one of the libraries does not seem to be recognized. This results in code with a red squiggly line under it, no auto-complete, etc. etc.. (This is not relevant anymore, see Edit 1)
Attempted solutions
I have tried creating a new project with the new source files, adding it to the solution, and manually copying project settings by right-clicking on the existing project, selecting Properties, and copying anything that is not set to its default value. This did not work.
I have tried copying the existing .vcxproj files, adding them to the solution, removing old and re-adding new source and header files. This did not work.
In both cases, when expanding External Dependencies in the Solution Explorer, the old project has a much longer list than the duplicate.
I am aware of this question, but the accepted answer relies on knowing which settings need to be changed. I don't know that, and I don't know how to find out.
Questions
So, is there a way to copy the entire set of settings that controls this?
Alternatively, is there a way I can check in the existing project precisely why it is able to resolve a particular external reference, so that I can find out which setting I need to change in the duplicate?
Edit 1
Well, now I feel stupid. I've been fighting this issue for a few days now, but I've made a few incorrect assumptions about the files I have.
It turns out, the second set of header files (located at a new place in the file system) are similar, but not identical, to the old ones. So at first glance, they look identical, and I never bothered to check.
The new header files has #if defined(WIN64) before the relevant #include statements, which of course is why the library wasn't being included.
So, my new question is, what's a sensible way to #define WIN64 without modifying the header file? Where can I put that definition so that it's valid in that header file, without changing that header file?
The correct way to use the same project properties for multiple projects would be not copy-pasting properties between them but to use Property Manager. You should figure out how exactly you original project is configured (note that properties for particular file can differ from project properties) and create a corresponding property sheet(s). Then apply this sheet for the new project.

Function call without definition(in header, no dlls or static libs)

I have a embedded controller code handed over, it has a bunch on .c files and some headers and a lot of associated files for the embedded processor, its a motorola MC9S12DT256 and it uses a not-so-good compiler - Cosmic. i used Visual studio(just a txt editor) for modifying the code and it changes the hex file being burned to the processor.
I got it earlier this week and spent most of my time on it and it worked ok for minor changes (where changin a value in the code and compiling again made the necessary changes) Now i have to make some major changes. The code calls certain functions which are not to be found any where in the all of the .hpp/.h/.cpp i got. there are no associated dlls as well. I tried to find some basic link and put it in a .sln and still most data is not recognized (as in i cant go to declaration of defn).
So my question is - how to get to the function definiton to where it is called when VS blanks out. Find all references also does no help
Thanks
PM
They may be compiler intrinsics (functions provided by the compiler rather then in a library). But it is not clear how you have determined that they do not exist in a static library or why you think you should be able to see a definition (as opposed to a declaration).
When using Visual Studio as an embedded project IDE, you should create the project as a "makefile project" (even if you don't actually have a makefile), and you need to add all the necessary header paths for your embedded code and the Cosmic compiler standard header folder as include files to the project - VS scans the header files for declarations for Intellisense code completion and browser navigation.

What is the correct way to import a type library in Visual Studio?

Background
Our build uses ant and a custom task to build Visual Studio projects/solutions as well as some Java projects. There structure is basically a large tree and artifacts from the projects are typically copied upwards to a common build directory.
This was previously a complete mess and I've greatly simplified the ant scripts and now I'm most of the way through the Visual Studio projects/solutions. These projects are extremely old and have been upgraded through every version of Visual Studio up to 2013. Part the changes I have done was to use as many of the default project properties and macros as possible. Most of these used to be hard coded.
Although I have modified the projects to use the $(Configuration) macro to separate the artifacts from different configurations these still get copied to a common location for other dependent projects in other solutions. So to avoid confusion and actually make sure our debug builds link to all the debug libraries (which wasn't happening previously) I have been adding suffixes to the Target Name. E.g. The Target Name of a Debug Unicode build will be $(ProjectName)DU.
Problem
This has been great so far but now I'm not sure how to complete these changes for one of our COM libraries. This library has an IDL file and the MIDL compiler generates a TLB file. Maybe this isn't a good way to do it but for now I wanted the TLB file to also have a different suffix depending on the build. The problem is, when I change the Type Library property for the MIDL configuration then this breaks the Compile-time directives in the RC file. I figured it might be possible to use #ifdefs in the TEXTINCLUDE block depending on whether _UNICODE or _DEBUG are set (provided I do it via the Resource Includes dialog so I don't break the RC file). It also means that there are other importlib attributes that will also need #ifdef checks.
At the moment it kinda works without renaming the TLB files but that's only because they are currently only being used within this solution.
Has anyone ever done anything like this or know a better solution?
Update
I guess what I really need to know here is what is the best way to use types from one COM DLL in another one? Should I even be using importlib? The MSDN documentation says that in most cases you should be using the import instead. I tried this but broke a whole bunch of stuff.

Does Visual Studio support C++ code indexing?

Does Visual Studio have a source code indexing feature for C++? That is, it statically parses your project, storing symbols in an index, such that you can easily and quickly jump to a definition of a symbol or see uses of it (i.e. call hierarchy)?
From what I can tell, in Visual Studio 2010, it has "Go to Definition" and "View Call Hierarchy" functions (if you right-click a symbol), but it takes a long time (a minute on my project) to find the info and do the action. It seems to be doing a crude text search in some cases.
I'm used to using Eclipse, which has an indexer, so those actions are almost instantaneous (after the indexing has completed).
Yes, Visual Studio Intellisense does just this. If your "go to definition" is taking a long time, it indicates that the project is not set up properly inside Visual Studio. You should be able to hover the mouse over a symbol (function name, variable name, etc.) and Intellisense should pop up instantly.
One cause of slow or incorrect Intellisense is creating a new project from a folder structure. If you have a bunch of .cpp and .h files in a complicated folder hierarchy, sometimes the project does not get created in a way that Intellisense can easily do symbol indexing. Also, if your project uses a lot of third party libraries, you need to make sure the header files are included in your project or else Intellisense will not be able to do anything with those symbols.