Click to See Complete Forum and Search --> : determine DLL dependency from .cpp file
dpthinh
May 31st, 2002, 08:04 PM
Hello,
suppose i have an.cpp file. Is there anyway i could determine all the DLLs that associate with this .cpp file??? Any help is breatly appreciated.
Jupiter
June 2nd, 2002, 07:32 PM
Hi
Your question is not quite clear? Can you please explain as what u ve to achieve specificly, perhaps then i ll be able to answer you. But just looking at .cpp file i dont think u ll be able to make out the dll dependancies of it, perhaps u may have to go thru the code and look for load library function as to which dll it is loading at run time.....Well if you put it in specific words then something can be thought of to resolve ur problem!!
dpthinh
June 2nd, 2002, 10:29 PM
Hello,
Thank you so much for replying. The problem is that i would like to have an little utility that will take in an .cpp file or an .h file as a parameter and print out a list of DLL dependencies. Basically, we have a directory tree that contains .cpp and .h source files and a special text file that contains a list of all the DLLs will be created after the directory tree is compiled.
The utility is run at pre-built phase and suppose to look inside the .cpp or .h file, traverse the direcroty tree, access the special text file to print out a list of DLL that depend on the .cpp file or .h file.
the purposeof the utility is ,before producing a patch, i would like to know which DLLs will be affected if i make change on the source code of an .cpp file or .h file.
I would like to know if is there any clue by just looking at the .cpp code and figure out all DLL that depend on it. I hope that is clear. Any help is greatly appreciated.
Jupiter
June 2nd, 2002, 10:56 PM
Hi
Actually there is no such method to find out the dll dependancy by just looking at .cpp file but dont get nervous as i ll give u few tips which may help u to build a logic around it and perhaps solve ur problem.
1] When u compile project under microsoft environment, u get a .dsp file created which contains all the references to .lib file under the tag # ADD BASE LINK32 ( these lib files are the lib of corresponding dll's ) So if u can parse this dsp file then u can fine out the dlls affected for the same project but not for a specific cpp file.
2] If you are producing flat dlls by compiling all those cpp files in ur dir heirarchy then ur job is quite easy. There is one utility called dumpbin.exe in the path C:\Program Files\Microsoft Visual Studio\VC98\Bin
This magic utility gives u all the functions wrapped in a DLL, so if u give a command like dumpbin abc.dll -export, then it ll give u all the functions inside it. Now programatically if u can run this exe then it ll return u all the function names, take it in a array and compare it will the cpp files u ve, if found in one of the cpp file then that is dependant on this DLL.
3] If u are making a call to flat dlls from .cpp file then u can parse the cpp file for LoadLibrary api and get the dependant dll name passed to this api and ur purpose is done.
Well i have given u many ways and hope this may solve ur purpose. Just build logic around these ways to get ur job done. If u ve any queries regarding this then feel free to write back. Enjoy and have fun...
JMS
June 7th, 2002, 02:04 PM
DLL's are not used for .c code or .h code. One needs to compile .c or .h modules into .obj's and then the linker is the one which resolves the externals with libraries such as .lib's
DLL's are actually associated with .exe's and not .cpps. There is a utility which comes with visual studio in the common\tools directory called depends which will tell you which dll's you exe is using.
The reason one could never make this association with a .cpp file is because the .cpp file doesn't know. The linker and it's paramerters resolve the external dependencies not the compiler.
Get what I'm saying....
To use depends just go to the command line and typ in
"depends my.exe" and you'll see all the dll's needed to run your my.exe program..
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.