Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building a .h file?

Status
Not open for further replies.

ramonsky

Programmer
Nov 19, 2003
7
GB
I want to build a project in which Third.exe depends on (and is built using) Second.h, and in which Second.h depends on (and is built using) First.php. In other words, I want the following to happen when I click on the Build button:

(1) An external program runs to generate Second.h from First.php. (In fact, the command line to do this is "PHP -q First.php >Second.h").

(2) Third.exe is built normally, but using Second.h as one of its inputs (hence rebuilding anything which depends on it).

How do I do this?

Jill
 
sorry, but what does PHP have to do with C++ and H files?

Ion Filipski
1c.bmp
 
Er, PHP is irrelevant, dude. You're being sidetracked by the irrelevant. Let me rephrase the question so it doesn't have any PHP mentions in it.

If I were to write a makefile for a Linux project, I could easily arrange things so that when I typed "make" (1) a source or header file would be BUILT (algorithmically) using some external application, and then (2) an executable would be built using, as its input, the source file created in step 1.

What the external application is is irrelevant. All that matters is that THERE EXISTS an external application whose OUTPUT when executed is a ".cpp" file or a ".h" file.

This has GOT to be possible. I can't believe that something you can do standing on your head with gcc and gnu make can't be done at all with Visual C++. But I don't know how. If you try to edit the ".mak" file which VC++ generates you encounter a comment which indicates that the ".mak" file is auto-generated (so I shouldn't fiddle with it) from the ".dsp" file, but I don't know how to tweak the ".dsp" file to do the right thing either.

So you see, my question, in abstract, doesn't have anything to do with PHP. That's just one possibility among many. I'm asking how to use a VC++ project to GENERATE a ".cpp" or ".h" file using an external app, and then have another (or the same) VC++ project to use that generated source or header file as input. Clear?

Any help would be useful.
 
If I understand right,
you want to create an application which creates VisualStudio projects and .h/.cpp files? If so, you should use COM and COM object "VisualStudio.DTE.7" or "VisualStudio.DTE.7.1"

Ion Filipski
1c.bmp
 
No, I don't want to have to restrict this to COM objects. There ought to be a way of doing this using ANY external application.

Here's how you'd do it in Linux - you create a makefile like this:

Code:
Output.exe : Input.c Input.h
    gcc Input.c -o Output.exe

Input.h : Moreinput.xxx
    someapp which creates Input.h from Moreinput.xxx

When you run make, the following happens: (1) the creation date of MoreInput.xxx is compared with the creation date of Input.h. If Input.h is older than MoreInput.xxx then "someapp" is executed with the parameters specified. This creates or updates Input.h. THEN (2) the creation data of Output.exe is compared with the creation date of Input.c and Input.h. If Output.exe is older than either Input.c or Input.h then gcc is run (which is equivalent, in VC++ to compile and link).

I don't see how COM objects fit into this scenario. There are no restrictions on what "someapp" can be in Linux. I don't see why there should be in Windows.

I figured the REAL answer is probably something like this... From the VC++ main window, click File / New / Projects / Makefile ... but I can't figure out where to go next. It doesn't seem to do what I would expect a makefile project to do, and the MS help is very poor in this area. So I'm stuck.

Of course, I CAN run any external app MANUALLY (from outside Visual Studio). No problems there. The problem is how to AUTOMATE the process so that it happens when I click on the Build / Rebuild buttons from within VC++.
 
1. I can not understand how do you press Build/Rebuild buttons in VC++ under Linux. I can't believe.
2. VC++ have possibility to create addins. There is a special kind off C++ project. So, try it. If you want it to communicate with Linux, use TCP or some TCP based protocols like HTTP, SOAP. Also you can use RPC or CORBA.

Ion Filipski
1c.bmp
 
Ramonsky,

I understood your problem. Sadly, thats all I can say atm.

I've myself not used such a feature, nor seen anybody else use this. But would definitely be very handy.

will come back again if i find something

/Srikanth

What happens if you’re scared half to death twice?
 
Of course, we used to write elaborate "*.bat" (MSDOS batch files) when building apps using command line compiler.

U should very well be able to do ur stuff this way.

Thats ur solution!

/Srikanth

What happens if you’re scared half to death twice?
 
In the UNIX world, you'd use a Makefile. I assume you could do the same thing on Windows, perhaps with a different syntax.


Here's how to do your example with a Makefile:

Code:
# Makefile

Third.exe: main.cpp Second.h
<TAB>   gcc -o Third.exe main.cpp

Second.h: always
<TAB>   PHP -q First.php >Second.h

always:

Read this as:

To update Third.exe, update main.cpp and Second.h, then compile main.cpp (you're probably not using gcc, but you get the idea).

To update Second.h, update always, then run your PHP script.

To update always, do nothing... don't even create the file. But you still have to do &quot;nothing&quot; every time because this target is always considered out of date (not updated). That means your header file will always get remade.


If your script doesn't do anything dynamic like check the system time or talk to the user somehow, and each &quot;version&quot; generates the same header file (i.e. if you didn't change it, it'll still make the exact same header), it might make more sense to just have the header directly depend on the PHP script so you only make it if something changed.


I know VC++ has Makefiles, and the syntax should be the same for the most part, but I don't know if the &quot;always&quot; thing will work. You might have to read documentation and figure out an equivalent way of always updating a target.
 
Oh, sorry; guess I didn't tell you anything you didn't already know, there.
 
to use makefiles VisualStudio has utility nmake. Also BorlandC++ has utility make. You can download it for free from borland.com

Ion Filipski
1c.bmp
 
That was a good answer. Trouble is, I already knew that. You see, I already know how to do this from OUTSIDE the VC++ IDE. This isn't really a problem (although BTW Microsoft's NMAKE makefiles are completely non-standard, and worse - are volatile! They get overwritten when you rebuild a project).

But it would be cool to be able to do this from WITHIN the VC++ IDE. Ideally, my own custom makefile should run when I click on the Build or Rebuild All menu items or buttons. This is the part that I don't know how do.

Now, there is a distinct possibility that IT CAN'T BE DONE. However, I haven't given up hope yet. The fact that Microsoft's makefiles are volatile lends to the suspicion that everything needed to create one must be somehow configurable through the GUI. Furthermore, there are buttons to click on to create a &quot;Makefile&quot; project ... except that it doesn't seem to do what I'd expect. So what I'm looking for here is someone who's simultaneously a VC++ GUI whizz and reasonably competent with makefiles. You're in the second category (so am I), but finding ANYONE in the first category is quite hard, because the more obscure features of the GUI are, shall we say, not well documented.

(I've always felt that the MSDN help system was A Bad Thing (TM). IMO it should be ditched and replaced with a straight &quot;.chm&quot; help file like every other Windows program on the planet has. But that's another story).

The distinction between &quot;from within the GUI&quot; and &quot;from outside the GUI&quot; is not merely a matter of convenience. If I were to release this as an open source project, other (Windows) users will EXPECT the VC++ Build button to do everything because that's the norm for Windows. Sure, I could provide release notes that say something like &quot;Run this script BEFORE building with VC++&quot;, but it's a small inconvenience I'd ideally like to be able to do without.

I think Microsoft may have gone a bit over the top here. Sure, they've made it so that users don't have to deal with makefiles, which is USUALLY a good thing, because makefiles are hard, and most programs are built the same way as most other programs anyway. Fair enough. But Microsoft really has no business PREVENTING us from working with custom makefiles. Well, who knows? Maybe that's what they do; maybe it isn't. I'll await the advice of that hypothetical whizz kid I mentioned earlier.

Thanks for your reply.
Jill
 
Whoops!

My comment &quot;That was a good answer&quot; was supposed to have been in response to chipperMDW's posts on this thread, not to Ion Filipski's posts. Sorry for the confusion - it was caused by a time-lag in posting.

Jill
 
I think you should look at the &quot;Project->Settings...&quot; window, in the &quot;Custom Build&quot; tab. Here is what MSDN has to say about that tab:


Rules entered on the Custom Build tab run only when any input file is out of date in relation to its output file, or if the output file doesn’t exist.

Per-file rules that you enter on the Custom Build tab run before the normal build-system tools (such as the compiler, the resource compiler, and so forth) are run.

Important Do not attach per-file rules to the output files of build-system tools, such as .obj, .res, or .tbl files. Such per-file rules may not run as expected.

Per-project rules that you enter on the Custom Build tab run after the normal build process finishes.


I hope this helps,

Vincent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top