VC++ question: building using only OBJ files

Posted on 1998-08-27
Last Modified: 2012-05-04
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...
Question by:haima

Author Comment

ID: 1171417
Adjusted points to 100

Expert Comment

ID: 1171418
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


Author Comment

ID: 1171419
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...
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.


Expert Comment

ID: 1171420
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.

Expert Comment

ID: 1171421
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.

Accepted Solution

Answers2000 earned 100 total points
ID: 1171422
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.


Author Comment

ID: 1171423
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...)

Expert Comment

ID: 1171424
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.

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question