• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

VC++ question: building using only OBJ files

How can I build an application using only the needed OBJ files (no sources) when the makefiles are generated using VC++?  The problem is that NMAKE looks for the CPP files for depenedencies.  I want to do this with minimal changes to the makefile...
1 Solution
haimaAuthor Commented:
Adjusted points to 100
Try something like that :)

link /out:result.exe obj1.obj obj2.obj ... objN.obj

check more options of the link.exe ... it placed at ...\DevStudio\vc\bin... You can run ..\devstudio\vc\bin\vcvars32.bat to set path ans other options to run link and other command-line utils...

You can get help on link.exe by typing "link.exe | more"

Good luck

haimaAuthor Commented:
Ah... but that I already knew...
I want to do the build using the original makefiles (with possibly changes that can be obtained from a script...) so that maintainance will be minimal.  In this way I will have to update the Obj list every time, not to mention the libs used and various linker options...
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Here's an idea: I don't even know if this is possible...
Alter the make file to check for a cmd line param named "LINKONLY" and have it skip the compilation step if this is set.
Don't you just need to create a new rule for the obj's.

You have to edit the makefile in some way. You could do some creative script/batch file programming to utilize environment variables and such. But I can not be more specific without know more about what you are trying to do. You indicate that the number of obj's will change? Use an environment variable, like obj_files_to_link, to indicate the obj's to be linked and have the make file use a line like "$(link_path)\$(linker) $(link_options) $(obj_files_to_link) where link_path is the path to your linker, linker is the link executable, link_options are the options desired.
You can cheat :

1. Exit VC
2. Set the PC clock back to the beginning of time (or any date back before the OBJs were created).  BTW for DOS the world began in 1980.
3. Create dummy .c or .cpp files.  These should have really old file dates (you can check this from DOS)
4. Set the PC clock back to today's date
5. Restart VC and add the dummy .c files to your project.

The make file generated by VC will assume that compiling the .c files build the .obj's.  However because the .obj's are always newer than the .c files, they will never be compiled, however they will still be linked.

There are some "issues" with this quick'n'dirty approach:
1. "Rebuild all" will force the .c's to be compiled.  Therefore never pick this option
2. Be careful not to ever edit the dummy .c files (or you'll modify the date back forward and thus make the objs be wrongly rebuilt next time you compile)
3. Transfering over a network, e-mail, config management system or whatever that stuffs this up if the file dates are modified.

Within these limitations, this will work, but I wouldn't recommend it.  Personally I prefer a manually built make file for this type of situation, but that's clearly what you don't want.

haimaAuthor Commented:
Well I guess this will work (I kinda thought of it myself) but it is a little complicated... I was kind of hoping for a simpler solution (maybe a flag for nmake that can be used smartly to produce this effect and such...)
Yeah, well you might have gotten an actual solution from me but instead you hastily accepted a hack. As long as it works for you. Good Luck.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now