|
From: Keith M. <kei...@us...> - 2010-12-04 08:12:30
|
On Saturday 04 December 2010 06:31:19 yuan zheng wrote: > I find that there are two libraries named libkernel32.lib and > libmsvcrt.lib in MinGW/lib/ ... There should not be; these should be libkernel32.a and libmsvcrt.a respectively. > meanwhile, there are two libraries named kernel32.dll and msvcrt.dll > in win32(windows/system32). Correct. > When I link libraries with "-lkernel32 -lmsvcrt", it will link the > win32 libraries because the shared libraries' priority is higher. No, it will not; the win32 system DLL path is not (normally) included in the linker's search path. What the linker will use is the above named pair of *import* libraries -- the .a variants -- which cause dynamic linking to the system DLLs, at run time. BTW, if you really do have libkernel32.lib and libmsvcrt.lib, the use of -lkernel32 and -lmsvcrt will *not* cause them to be linked anyway, because they are inappropriately named; see the binutils documentation for ld, for the actual naming conventions which are applicable. Furthermore, if you are using gcc/g++ and friends correctly, rather than misusing ld directly for linking, then *you* don't need to specify the -lkernel32 or -lmsvcrt; they are automatically specified by the linker driver itself. > But actually, I want to link libkernel32.lib and libmsvcrt.lib. Why? If they are the .a import libraries we provide, then they link dynamically to the system DLLs anyway. If they are anything else, then they are likely not compatible with MinGW in any case. > And in my link options there are some shared libraries, so I can't use > the "-static" link option. If you really must override dynamic linking for a subset of libraries, refer to the ld documentation for the -Bdynamic and -Bstatic options, (specified through GCC as -Wl,-Bdynamic and -Wl,-Bstatic). -- Regards, Keith. |