Bug 5305 - ld does not alias with .lib files
Summary: ld does not alias with .lib files
Status: RESOLVED OBSOLETE
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.15
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-09 21:20 UTC by Michiel de Bondt
Modified: 2022-08-25 00:25 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michiel de Bondt 2007-11-09 21:20:17 UTC
ld does not alias with .lib files. Of course, you can use .a files instead, if
you are able to generate them. Below is a makefile that generates an error. The
makefile requires components of VC Express to generate a .lib, namely lib.exe,
link.exe and mspdb80.dll.

The makefile generates two variants of a small application: one by using a .lib
file and one by using a .a file. The first variant does not work, because it
does not alias. But the "real-life application" by which I signaled the problem
does only not work when a .dll is generated with the .lib file (say,
foo_test_lib.dll). I have not been able yet to isolate the reason for that.


all:	foo_test_a.exe foo_test_lib.exe

clean:
	del foo*.* 

foo.cpp:
	echo extern "C" __declspec(dllexport) int foo() > 1.tmp
	echo { return 3840; } > 2.tmp
	copy /b 1.tmp+2.tmp foo.cpp
	del ?.tmp

foo.def:
	echo LIBRARY foo > 1.tmp
	echo EXPORTS > 2.tmp
	echo foo > 3.tmp
	echo bar = foo > 4.tmp
	copy /b 1.tmp+2.tmp+3.tmp+4.tmp foo.def
	del ?.tmp

foo.dll: foo.cpp
	g++ -shared foo.cpp -o foo.dll

foo.lib: foo.def
	lib /def:foo.def
	del foo.exp

foo.a: foo.def
	dlltool -d foo.def -l foo.a

foo_test.cpp:
	echo #include "stdio.h" > 1.tmp
	echo extern "C" __declspec(dllimport) int bar(); > 2.tmp
	echo main() { printf("%%x\n", bar()); } > 3.tmp
	copy /b 1.tmp+2.tmp+3.tmp foo_test.cpp
	del ?.tmp

foo_test.o: foo_test.cpp
	g++ -c foo_test.cpp -o foo_test.o

foo_test_a.exe: foo_test.o foo.a foo.dll
	g++ foo_test.o -o foo_test_a.exe -Wl,foo.a

foo_test_lib.exe: foo_test.cpp foo.lib foo.dll
	g++ foo_test.o -o foo_test_lib.exe -Wl,foo.lib
Comment 1 Danny Smith 2007-11-10 03:34:35 UTC
I believe the problem is that in the old version of ld you are using  the *.lib
name was not recognized as a dynamic lib so ld used direct linking to foo.dll in
preference to linking against the "static" foo.lib   This is fixed in recent
binutils (2.18).  Can you try that?

As a work-around you could try renaming the LIB.EXE generated foo.lib to libfoo.a

Danny
Comment 2 Alan Modra 2022-08-25 00:25:03 UTC
As per comment #1, probably fixed a long time ago.