Go Premium for a chance to win a PS4. Enter to Win


VC++ question: building using only OBJ files

Posted on 1998-08-27
Medium Priority
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...
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

926 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