As some of you know, in the past few days I have tightened up the use of
libpgport so it is less prone to breakage from code changes.   However,
in the cleanup, I found an unusual problem with linking pg_dump on
Win32.  If I build pg_dump linking in libpgport and libpq, I get a
failure due to a duplicate symbol in both libraries:

	gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes -Wmissing-declarations -O1 -Wall -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wcast-align pg_dump.o common.o pg_dump_sort.o pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o pg_backup_files.o pg_backup_null.o pg_backup_tar.o dumputils.o ../../../src/backend/parser/keywords.o -L../../../src/interfaces/libpq -lpq -L../../../src/port   -O1 -Wall -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wcast-align -lpgport -lwsock32 -lm  -lws2_32 -o pg_dump.exe
	../../../src/port/libpgport.a(pgstrcasecmp.o)(.text+0x2aa):pgstrcasecmp.c: multiple definition of `pg_tolower'
	../../../src/interfaces/libpq/libpq.a(ds00154.o)(.text+0x0): first defined here
	make: *** [pg_dump] Error 1

I have temporarily fixed this by adding a few lines to the pg_dump
makefile that explicitly link in port/exec.o:
	
	# not sure why MinGW needs this but it prevents a link failure
	ifeq ($(PORTNAME), win32)
	EXTRA_OBJS += $(top_builddir)/src/port/exec.o
	endif


port/exec.o was used in previous build but shouldn't be needed anymore
because a client-level build is already in libpgport.

The error report is right that the symbol exists in both libraries, but
psql also uses items from pgstrcasecmp.c (pg_tolower) and exec.c but
builds fine without using exec.o directly on the link line:

	gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes -Wmissing-declarations -O1 -Wall -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wcast-align command.o common.o help.o input.o stringutils.o mainloop.o copy.o startup.o prompt.o variables.o large_obj.o print.o describe.o psqlscan.o tab-complete.o mbprint.o -L../../../src/interfaces/libpq -lpq -L../../../src/port   -O1 -Wall -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wcast-align -lpgport -lwsock32 -lm  -lws2_32 -o psql.exe

Any ideas on why this is happening?  What are the rules for Win32
linkage?  Doesn't it take the first matching library symbol?  Can people
reproduce this failure?  Why is pg_dump different from psql linkage?

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Tue, 5 Oct 2004 12:35:15 -0400 (EDT)
Bruce Momjian <pgman@candle.pha.pa.us>
Problem with Win32 pg_dump linking and symbols