Jump to content
  • Advertisement
Sign in to follow this  
SirLuthor

Running programs during the Build

This topic is 4998 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.cpp
StdAfxPerforming Custom Build Step on ".\Custom Build.cpp"
Custom

Custom 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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!