-
August 11th, 2010, 04:46 PM
#1
[RESOLVED] How to auto-generate .cpp and .h file in a pre-build event using Visual C++ 6.0
I'm want to use a pre-build event in Visual C++ 6.0 to run a script which will automatically generate a .cpp and .h files, but I am not sure how these files could add to project ... So when I build the project
1) script has to generate .cpp and .h files
2) Needs to add these files to project
3) Has to do a rebuild all.
can any point me in a right direction to achieve this ? any sample application also appreciated. Thank you very much in advance.
SKS
Last edited by kishoresajja; August 11th, 2010 at 04:48 PM.
-
August 11th, 2010, 04:53 PM
#2
Re: How to auto-generate .cpp and .h file in a pre-build event using Visual C++ 6.0
Manually add them once, then save the project. Deleting the files on the disk doesn't automatically remove them from the project.
Viggy
-
August 11th, 2010, 05:03 PM
#3
Re: How to auto-generate .cpp and .h file in a pre-build event using Visual C++ 6.0
Hi Thanks for your quick response. can we do this dynamically by using VC++ command line or something ? the reason why I am asking is I don't want them to add manually, once user say "build" they should automatically created and added to the project. Please bear with me ..
-
August 12th, 2010, 02:19 AM
#4
Re: How to auto-generate .cpp and .h file in a pre-build event using Visual C++ 6.0
You could do the followings steps:
- Create an empty project of the type you want to generate
- Add all files to that project (e. g. stdafx.h and stdafx.cpp when using PCH) which are not a matter of change
- Add your 'generator tool' to the 'Tools' menu of Visual Studio or - alternatively - use a separate (MFC-)application to get the basic informations for the new project to generate.
- If done so far your tool would make a copy of the 'empty template' project using the new project name given by the user.
- then it would create .cpp and .h files and add those files to the folder and to the copied .dsp file of the new project. You asily can see how VC6 adds new files to a .dsp by opening the .dsp in a text editor.
- finally you would invoke the msdev programmatically passing the new .dsp as a parameter. You can see how msdev can be started from commandline by typing 'msdev /?' at the command prompt.
Adding files to a currently opened project is not impossible but it requires COM or advanced Tools programming where I have little to no experiences with.
Regards, Alex
-
August 12th, 2010, 05:40 AM
#5
Re: How to auto-generate .cpp and .h file in a pre-build event using Visual C++ 6.0
As Mr Viggy said. the simple solution is to run the build once, and add the .cpp's and .h files once.
You can then make the .cpp file dependant on whatever file(s) is(are) serving as 'input' to generate the .cpp by specifying in the build settings of your input files that they're generating xxx.cpp.
If you have a set of input that is 'randomly' creating .cpp and .h files without predetermined filenames, then you will have to use a MAKE file.
-
August 12th, 2010, 11:29 AM
#6
Re: How to auto-generate .cpp and .h file in a pre-build event using Visual C++ 6.0
Hi All,
Thanks for replies. I could add them manually for the first time but I don't know how to add dependencies between the files in VC++ 6.0 project. Can any please point me in right direction.
In other words say I have use.cpp and use.h which will include autogen.h and use defines in autogen.cpp then how can I add dependencies for use.cpp and use.h?
autogen.h and autogen.cpp are files which were auto generated. And these files won't change until I change their base header from which these two files generated.
Thanks
SKS
-
August 12th, 2010, 01:47 PM
#7
Re: How to auto-generate .cpp and .h file in a pre-build event using Visual C++ 6.0
If you add autogen.* to the project you don't have to bother about dependencies. Just run your generation tool as a pre-build step and the build process will detect what to rebuild.
-
August 13th, 2010, 03:53 AM
#8
Re: How to auto-generate .cpp and .h file in a pre-build event using Visual C++ 6.0
Originally Posted by S_M_A
If you add autogen.* to the project you don't have to bother about dependencies. Just run your generation tool as a pre-build step and the build process will detect what to rebuild.
Yes, but this has the nasty effect that the pre-build step will ALWAYS execute.
This will ALWAYS create new versions of the .cpp/.h files
This will ALWAYS cause a recompile, possibly of everything if the .h file is used everywhere.
The better solution is to add the files that are the input to create the .cpp/.h files to the project and give those a custom build step. Make sure you properly specify outputs, and if those outputs are also in the project, it'll work much better.
This way, if the input files haven't changed, the custom build won't run, won't generate the .cpp/.h and this won't cause a recompile of anything using those.
Suppose: Input.dat is input to create A.cpp and A.H
1) Add a A.cpp and A.h to the project, make dummy/empty files if you have to.
2) Add input.dat to the project.
3) Rightclick inpit.dat, click properties, and select Custom Build Step
Command Line: whatever command is needed that is going to read input.dat and make a.cpp and a.h
Outputs: $(Inputdir)a.h;$(inputdir)a.cpp
Additional depenencies: any extra files needed to run the command. It's often good idea to add the exe that reads input.dat here.
-
August 13th, 2010, 12:04 PM
#9
Re: How to auto-generate .cpp and .h file in a pre-build event using Visual C++ 6.0
Hi All,
Thanks for replies.
OReubens, I think your suggestion will be a good bet, but I have one more question. Say other files in the project needs to include a.h and use the defines in that header file will adding custom build generate this header before compiling the files which included a.h. I am not sure about this .. can you please tell me if my question doesn't make any sense.
Thanks
SKS
-
August 13th, 2010, 05:01 PM
#10
Re: How to auto-generate .cpp and .h file in a pre-build event using Visual C++ 6.0
Maybe I did read the posts without 'really read them' so I didn' realize what your solution ment OReubens. All in all, it's a good solution.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|