Running programs during the Build

Started by
9 comments, last by Drew_Benton 19 years, 1 month ago
Hello again good people! I have another question for the masses, which eludes me at the moment. Let's say I have a console program which takes some command line variables, and outputs a .hpp file for me to use as a sort of 'buildstamp'. Now, what would I have to do in MSVC6 to get that program to run when I compile my project? Like, every time I hit the compile, recompile all, etc, the program would be run, generating the mentioned file, before my project was compiled? I can't seem to find any options for setting up things to run before a compile, but I'm fairly certain it's possible. If anyone could point out to me the obvious (which I seem to be missing) I would be most obliged. Thanks! BTW, I need to be able to run the file with a command line argument, just so you all know. I'm sure that is not an impossibility?
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!
Advertisement
You can do this easily enough with makefiles, although I only know how to do this with GCC and GNU Make. MSVC has a program called nmake but I've never used it.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Also, you can go to the Custom Build tab in Project Settings. Then you can use that to make a new configuration. For example, if you go to the Post Build Step, and type in CMD. You will see something like:
Linking...Microsoft Windows XP [Version 5.1.2600](C) Copyright 1985-2001 Microsoft Corp.F:\Program Files\Microsoft Visual Studio\MYPROJECTS\cart cypher>cart cypher.exe - 0 error(s), 1 warning(s)


After you compile. Of course since you want to use this before you compile, you need to do the custom build. I think this does the same thing that smart_idiot has said though, just through the IDE.
I'm sorry, I'm afraid those replies went past me.. Not exactly compiler-savvy here, you see. So, um, while I do offer thanks for tryingto help, I'm afraid I'm as much in the dark as I was before [smile]

What I am looking for is a simple, plainly explained way to make sure an executable (with one command line argument) runs every time I compile the project, before the, well, compiler runs. I'm kind of in need of an explanation for obtuse people, as I literally have NO idea what goes on during a build. If anyone knows of a fairly simple example of how I could get this working, I would be quite happy. Thanks!
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!
It's been a while since I messed with VC6, but in 7.0 and 7.1 if you go to the project properties, and click on the debug entry in the left pane, there is a place you can add command arguments. I would suspect there is something similar in 6.0
Yes, I am aware of that, however, it does not seem to be what I need. As it appears to me, that adds command line arguments to be used when the program is debugged, but, as far as I can tell, it offers no way of running executables during a build. Thanks for trying though, any and all input is appreciated! [smile]
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!
VS 7.0/7.1 have "pre-build events" and "post-build events" which run programs before and after the build, respectively. VS6 may have this as well.
I'm sorry, I'm clearly not being clear enough (bad pun, I know...) about what I need.. I'm aware of those options, but I have no idea how to use them, apply them, do anything with them. I am sorely in need of someone telling me what I would have to enter, because I have, as I said, no idea. Thanks!
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!
Ok. Here's two things you can try.

Goto: Project->Settings->Pre-link Step

Under the Pre-Link command(s), you can enter in the exe file name as well as the parameters.
i.e. I made a test.exe that took a parameter and cout'd it: Test.exe "Test!"

Now when you 'Rebuild', it should be executed before it is linked.

Now that will only work after it is complied before link.

If you wish to have it ran before it is complied you must do this:

1. Hi-light all the .cpp files you wish to run this on in the project workspace (ctrl+click).
2. Go to project->settings now
3. Click on the "Always use custom build step"
4. CLick on the Custom Build Tab
5. In the commands, type out the .exe with parameters you wish to use. There are several macros you can use, such as $(InputName) to get the file name being complied

IE test.exe $(InputName)

6. Now under Outputs, type in "$(InputName)"
7. Now when you compile, the .exe is ran for each of those files!

I made a test project to show this in action. Download it here.

The Test.zip has the test exe project I run at compile time. The other one has the sample project. When you compile it you should see something like this:
--------------------Configuration: Custom Build - Win32 Debug--------------------Performing Custom Build Step on .\StdAfx.cppStdAfxPerforming Custom Build Step on ".\Custom Build.cpp"CustomCustom Build.exe - 0 error(s), 0 warning(s)


Please work (crosses fingers)[smile]. This should work for now. I don't think there will be any problems with the output, since they are just .cpp files that do not move, but I am not 100% sure. It only displays "Custom" because I made the program use argv[1] and output that, and not all of the args. That and I did not add a endl either [lol]. Goodluck and feel free to ask if you still can't get it to work!

- Drew
Thanks a lot man, I'll try that stuff out. One thing, when you say:
Quote:
i.e. I made a test.exe that took a parameter and cout'd it: Test.exe "Test!"

Regarding 'test.exe', is the full path necessary? If not, where is the directory that the executable should be? Thanks a lot!
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!

This topic is closed to new replies.

Advertisement