Is it possible to add a special pragma or something to tell the compiler which folder to build to based on #ifdef #else
Thanks
Printable View
Is it possible to add a special pragma or something to tell the compiler which folder to build to based on #ifdef #else
Thanks
No, but you can usually do it on the command line.
Eg
gcc src/prog.c -o obj/prog.o
Oh well. I thought that would be the case.
Thanks for replying.
So, I can build to different folders now.
And it is "relatively" simple to do.
(ignoring all the trial-and-errors and endless Google searches)
I copy-n-pasted my project vcxproj file to a new folder
(current project is ProVersion, new is TrialVersion)
I edited the new Trial vcxproj file <ItemGroup> <ClCompile Include> paths, etc.
to use the original ProVesrion source code (a.k.a. link).
I opened my Pro project (in VS2019) and clicked: Tools > Create GUID
which I then pasted into the Trial vcxproj file <ProjectGuid>
I also opened the Pro project Properties > Configuration > C/C++ > Preprocessor
and clicked Preprocessor Definitions <edit> and added PROVERSION
Close the Pro and then double-click the Trial vcxproj file
which opens in VS2019 and is ready to compile since
my source code is already full of #ifdef PROVERSION #else
Anyway, just thought I'd share.
Well if there were ever a good example of an XY problem, then this is it.
1. Create new build targets in your existing project.
How to: Create and edit configurations - Visual Studio (Windows) | Microsoft Learn
In this example, I cloned DebugPro from Debug, and ReleasePro from Release.
Attachment 16508
You can then edit the C++ preprocessor options of the two 'Pro' versions to include the PROVERSION macro definition.
2. To build every permutation of things, just use Build->Batch build...
Attachment 16509
Moments later, I have 8 executable files in 8 separate directories configured how I want.
No need to copy/edit .vcproj files, something which is both fragile and likely to break - especially at upgrade time.
Wow, you're right.
I bet you see the XY problem once a week here.
I would even say that is one of the biggest nemeses of programmers.
The other being cut-n-paste without completely editing the paste.
As for your solution...
I appreciate the education. I've been telling myself for years
that I should learn more about all of the features of VS.
Oh well. I'm going to leave it alone though.
It's already check-marked.
BTW, have you ever run across the Hacker Laws?
GitHub - dwmkerr/hacker-laws: 💻📖 Laws, Theories, Principles and Patterns that developers will find useful. #hackerlaws
(there's an easier to read pdf there)
Thanks again.
Oh, and one last nemesis related to #ifdef and #endif
Try banging your head on the wall fixing that one.Code:#ifdef PROVERSION
x=123; \
#endif
(shh... don't tell anyone: there tabs and a backslash)
Have a good day.