From owner-freebsd-hackers@FreeBSD.ORG  Sun Apr 22 23:14:02 2007
Return-Path: <owner-freebsd-hackers@FreeBSD.ORG>
X-Original-To: hackers@FreeBSD.org
Delivered-To: freebsd-hackers@FreeBSD.ORG
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id D47C816A401;
	Sun, 22 Apr 2007 23:14:02 +0000 (UTC) (envelope-from dds@aueb.gr)
Received: from mx-out-04.forthnet.gr (mx-out.forthnet.gr [193.92.150.103])
	by mx1.freebsd.org (Postfix) with ESMTP id 3B2DC13C45A;
	Sun, 22 Apr 2007 23:14:01 +0000 (UTC) (envelope-from dds@aueb.gr)
Received: from mx-av-03.forthnet.gr (mx-av.forthnet.gr [193.92.150.27])
	by mx-out-04.forthnet.gr (8.13.8/8.13.8) with ESMTP id l3MNE0Y5006304; 
	Mon, 23 Apr 2007 02:14:00 +0300
Received: from MX-IN-02.forthnet.gr (mx-in-02.forthnet.gr [193.92.150.185])
	by mx-av-03.forthnet.gr (8.14.1/8.14.1) with ESMTP id l3MNE0LB009913;
	Mon, 23 Apr 2007 02:14:00 +0300
Received: from [192.168.136.22] (ppp122-171.adsl.forthnet.gr [193.92.229.171])
	by MX-IN-02.forthnet.gr (8.14.1/8.14.1) with ESMTP id l3MNDpPD001947;
	Mon, 23 Apr 2007 02:13:53 +0300
Authentication-Results: MX-IN-02.forthnet.gr from=dds@aueb.gr;
	sender-id=neutral; spf=neutral
Message-ID: <462BEC2B.5090508@aueb.gr>
Date: Mon, 23 Apr 2007 02:13:47 +0300
From: Diomidis Spinellis <dds@aueb.gr>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
	rv:1.8.0.9) Gecko/20061211 SeaMonkey/1.0.7
MIME-Version: 1.0
To: Andrew Pantyukhin <infofarmer@FreeBSD.org>
References: <cb5206420704221454v60a957b9qac74dc5f4f4b674a@mail.gmail.com>
In-Reply-To: <cb5206420704221454v60a957b9qac74dc5f4f4b674a@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Virus-Scanned: ClamAV 0.90.2/3147/Sun Apr 22 18:09:35 2007 on
	mx-av-03.forthnet.gr
X-Virus-Status: Clean
Cc: hackers@FreeBSD.org
Subject: Re: extern "C" and undefined reference
X-BeenThere: freebsd-hackers@freebsd.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Technical Discussions relating to FreeBSD
	<freebsd-hackers.freebsd.org>
List-Unsubscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-hackers>, 
	<mailto:freebsd-hackers-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-hackers>
List-Post: <mailto:freebsd-hackers@freebsd.org>
List-Help: <mailto:freebsd-hackers-request@freebsd.org?subject=help>
List-Subscribe: <http://lists.freebsd.org/mailman/listinfo/freebsd-hackers>,
	<mailto:freebsd-hackers-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Sun, 22 Apr 2007 23:14:02 -0000

Andrew Pantyukhin wrote:
> 7zip developers converted some code from C++ to C,
> while leaving the main stand-alone lzma app in C++.
> They use 'extern "C" { }' blocks around #include's
> referencing C headers.
> 
> Everything compiles fine, but "undefined reference"
> errors appear at linkage. The undefined references
> are to the C functions included from withing those
> 'extern "C"' wrappers. I tried to remove the
> wrappers from some files and the amount of errors
> decreased a bit. Is there a better workaround?
> 
> Google came up with two results: remove the wrappers
> or use c++ instead of cc. I'm already using c++.

Many of the C headers are available in a different form for C++ 
programs.  For example, in a C++ program you can #include <cstdio> 
instead of <stdio.h>.

You can use nm(1) on the .o files to see where the problem comes from.

Diomidis