From cbond@muscle.twistedcircus.org  Wed Mar 21 23:21:07 2001
Return-Path: <cbond@muscle.twistedcircus.org>
Received: from muscle.twistedcircus.org (cr171252-a.poco1.bc.wave.home.com [24.113.93.54])
	by hub.freebsd.org (Postfix) with ESMTP id 5AC9D37B71F
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 21 Mar 2001 23:21:07 -0800 (PST)
	(envelope-from cbond@muscle.twistedcircus.org)
Received: (from cbond@localhost)
	by muscle.twistedcircus.org (8.11.2/8.11.2) id f2M7Lp903660;
	Wed, 21 Mar 2001 23:21:51 -0800 (PST)
	(envelope-from cbond)
Message-Id: <200103220721.f2M7Lp903660@muscle.twistedcircus.org>
Date: Wed, 21 Mar 2001 23:21:51 -0800 (PST)
From: cbond@twistedcircus.org
Reply-To: cbond@twistedcircus.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: bsd.prog.mk doesn't link C++ programs properly
X-Send-Pr-Version: 3.2

>Number:         25984
>Category:       misc
>Synopsis:       bsd.prog.mk doesn't link C++ programs properly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ru
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Mar 21 23:30:02 PST 2001
>Closed-Date:    Tue Aug 20 02:47:41 PDT 2002
>Last-Modified:  Tue Aug 20 02:47:41 PDT 2002
>Originator:     Chris L. Bond
>Release:        FreeBSD 4.3-BETA i386
>Organization:
None
>Environment:
>Description:

bsd.prog.mk from /usr/share/mk/ doesn't properly link programs with C++ source
files against -lstdc++ as it should.  The majority of C++ programs hence fail to
build.

>How-To-Repeat:

Construct a Makefile in the standard bsd.prog.mk format and include C++ files in
the $SRCS variable (.cc, .C, .cxx, etc.).  Be sure to use a piece of the
C++ standard library in your code (e.g., iostreams).

>Fix:

--- /usr/src/share/mk/bsd.prog.mk.orig	Wed Mar 21 22:30:10 2001
+++ /usr/src/share/mk/bsd.prog.mk	Wed Mar 21 23:18:52 2001
@@ -27,10 +27,14 @@
 .if defined(PROG)
 .if defined(SRCS)
 
-# If there are Objective C sources, link with Objective C libraries.
+# If there are Objective C or C++ sources, link with appropriate libraries.
 .if ${SRCS:M*.m} != ""
 OBJCLIBS?= -lobjc
 LDADD+=	${OBJCLIBS}
+.endif
+.if ${SRCS:C/\.(cc\$|C\$|cxx\$|cpp\$)//} != ${SRCS}
+CXXLIBS?= -lstdc++
+LDADD+=	${CXXLIBS}
 .endif
 
 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->ru 
Responsible-Changed-By: johan 
Responsible-Changed-When: Mon Aug 19 11:45:39 PDT 2002 
Responsible-Changed-Why:  
Over to bsd.*.mk maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=25984 
State-Changed-From-To: open->closed 
State-Changed-By: ru 
State-Changed-When: Tue Aug 20 02:41:54 PDT 2002 
State-Changed-Why:  
The correct way of linking C++ programs is to use c++(1) 
which adds -lstdc++ automatically.  This has been fixed 
in FreeBSD 4.6-STABLE, in bsd.prog.mk,v 1.86.2.14 by 
providing a new PROG_CXX knob as an alternative to PROG. 
bsd.README has been updated accordingly. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=25984 
>Unformatted:
