views:

715

answers:

1

Hello everyone,

I have a static library (.lib file) on Windows platform, I want to know the dependent version of CRT library when the lib is built. I have no source code of the .lib file, any ideas?

thanks in advance, George

+4  A: 

Static libraries don't have those kinds of dependencies. When the library is built it is not linked with the run-time in any way, all it knows about are function declarations in the implementation header files, which don't provide any version information.

However, assuming the library is in MS format, you should be able see what flags the library was built with by opening it in a text editor (make a backup before you do this). You are looking for a line like this:

cl.exe cmd -nologo -MTd -W3 -Gm -GX -ZI -DWIN32 -D_DEBUG  (more stuff)

The -MTd flag tells you that the library was compiled with Multi-Threaded Debug support. .

anon
I met with the following error when static linking with foo.lib, the error message is -- warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library, any ideas what is the root cause?
George2
Yes, one of the libraries and/or applications was built with multi-threaded supportt, the other was not. You need to build all libraries and apps with the same threading model.
anon
I am confused, you just mentioned static lib has nothing to do with runtime library (debug/release/single threaded/multi threaded), why linker thinks the static lib depends on a different kind of threading model runtime, and reports this error? Any methods to see which kind of runtime library the static lib is built-on?
George2
Thanks for your answer, 1. so the root cause is, the static lib is compiled with some versions of runtime library which conflicts with other parts of runtime library, so using which version of runtime library is decided and performed during compiing process, other than link process, correct? 2. How to check which runtime library version the static library is compiled with?
George2
BTW: I have opened the static library file with binary editor in VSTS 2008, I searched for cl.exe, but find nothing. Any ideas? :-(
George2
Your problem has nothing to do with the runtime library - please get that out of your head. Your problem appears to be, as I said, that your libraries build flags conflict in some way with the build flags of your application. This is NOT a version issue. I suggest you look at the project settings and change the C++ code generation options to be the reverse of whatever they currently are with regard to multi-threading.
anon
Thanks, 1. "that your libraries build flags conflict in some way with the build flags of your application" -- build here you mean compile other than link correct? 2. Flags you mean "-MTd"? 3. I think during compile process, we only need to know function declaration, and function declaration is defined in .h file, and I am confused about why flags such as -MTd will impact?
George2
Using the /MT flags has a number of effects on the compilation process, particularly in selecting which declarations get seen by the compiler.
anon
1. Could you show me a sample please? I very interested how flags like MT will impact compile process. 2. I still do not know how to check which compile flag is used when the static foo.lib is built. Any ideas to check the flag which is used to build?
George2
1. Search for _MT in the VS header files. 2. If you can't find the string I mentioned, I have no idea - are you sure it really is a static library? Where did you get it from?
anon
@Neil, it is a static library and from legacy code. I am using open with binary editor mode of VSTS to open the library file, and search for "cl.exe". Maybe this way is wrong or some other tool should be used?
George2
My example was for VC++ 6..0 - the name of the comopiler/linker driver may have changed - search for WIN32 instead - that should not have changed. Or the library format may have changed, for all I know.
anon
There are some hits for "win32", for example, this one -- "/DEFAULTLIB:"msvcprt" /manifestdependency:"type='win32' name='Microsoft.VC80.CRT' version='8.0.50608.0' processorArchitecture='amd64' ", BTW: there is no easy way to know whether a lib is static library?
George2
The library format has indeed changed, it seems. I no longer use VS, so I'm afraid I can't help any further. You may want to post another question, but if you haven't got the library source I think you are screwed.
anon
Thanks Neil! I think I am asking my question in a wrong way, other than finding the root cause (there are too many Microsoft hidden things...), we need to find solution. In my question, I think the solution should be change my application compile setting to be the same as the static library (using MT flag for both my app and the static lib), correct?
George2
That's what I suggested earlier.
anon
Thanks Neil, it could build! Thanks! I will start another thread to discuss how to check whether a lib is a static lib or not. :-)
George2
I posted my question here, appreciated if you could continue to discuss and share your great ideas.http://stackoverflow.com/questions/811534/static-library-on-windows-platform-issueFor this question, I have marked it as answered. :-)
George2