tags:

views:

146

answers:

1

I will you show my misinterpretation.

  • it says there must be del *.obj in the bat file
  • it says there must be an obj file
  • it says the obj file must actually be a cpp file

Please, show me your interpretation.

http://computerprogramming.suite101.com/article.cfm/the_borland_win32_compiler_guide

Thanks!

+2  A: 

Your question's a little confusing but I'll try it out.

Typically, you have a group of C++ source files, for example, x.cpp and y.cpp.

The compile phase will take these and create, for example, x.obj and y.obj.

The link phase will take these and create a single executable, for example, xy.exe.

1/ The reason you would have a "del *.obj" in the batch file is to delete all object files so that the make can recreate them. Make (if you're using intelligent rules in the makefile) will only rebuild things that are needed (an example being that the cpp file will not be compiled to an obj file if the current obj file has a later date than it). Deleting the object file will force a new one to be created.

2/ There doesn't have to be an object file, these are typically created from the c or cpp source files. In addition, you can combine compile and link phases so that no object files are created (or are destroyed pretty quickly once they're finished with).

3/ The object file doesn't have to be a cpp file, but it's usually built from a cpp file with the same base name.

Update based on comment:

If you want to only specify your application name once, your comments have it like this (I think, the format's not that great as you pointed out):

  PATH=C:\BORLAND\BCC55\BIN;%PATH%
  APP=MyApp
  del *.exe
  del *.obj
  del *.res
  make -f$(APP).mak >err.txt
  if exist $(APP).exe goto RUN_EXE
:EDIT_ERR
  call notepad.exe err.txt
:RUN_EXE
  call $(APP).exe
  if exist err.txt delete err.txt :END

I think what you need is:

  PATH=C:\BORLAND\BCC55\BIN;%PATH%
  set APP=MyApp
  del *.exe
  del *.obj
  del *.res
  make -f%APP%.mak >err.txt
  if exist %APP%.exe goto :RUN_EXE
:EDIT_ERR
  call notepad.exe err.txt
  goto :END
:RUN_EXE
  call %APP%.exe
  if exist err.txt delete err.txt
:END

What you have with your "$(APP)" substitutions is something that will work inside a makefile, but not inside a cmd file. There you need to use the %APP% variant to get what you want.

paxdiablo
I tried PATH=C:\BORLAND\BCC55\BIN;%PATH% APP=MyApp del *.exe del *.obj del *.res make -f$(APP).mak err.txt if exist $(APP).exe goto RUN_EXE :EDIT_ERR call notepad.exe err.txt :RUN_EXE call $(APP).exe if exist err.txt delete err.txt :END but is there a way to write MyApp once (the command is not being recognized)?
Delirium tremens
Why isn't indenting working???
Delirium tremens
Pax, your answer is helping clear things a lot! Thanks!
Delirium tremens
@DT, indenting won't work in the comments, try editing your question (add to the end).
paxdiablo
@PAX, I'm reading a book with a different cpp code per chapter. Will I have to create a bat and a mak file per chapter too? I will have so many chances to be wrong...
Delirium tremens
It might be worth mentioning that you could download another compiler with an IDE, such as MSVC++ Express, and you wouldn't have to do all this. It seems like a lot of work for a beginner to wade through for no particular reason.
jalf
@Delerium, yes, you probably will. But your attempt is a good one - it means you can just copy the previous chapters files and change the single "set APP=MyApp" line. Consider seriously what @jalf says - the Borland IDEs were brilliant but their command-line compiler's not really suited for a learner. You might want to consider downloading MSVC Express from Microsoft.
paxdiablo