Date: Sun, 18 Sep 2005 15:15:25 -0400 (EDT) From: Craig Rodrigues <rodrigc@crodrigues.org> To: FreeBSD-gnats-submit@FreeBSD.org Subject: ports/86304: [PATCH] graphics/jpeg does not have 'extern "C"' for C++ Message-ID: <200509181915.j8IJFPoQ037999@c-66-30-112-193.hsd1.ma.comcast.net> Resent-Message-ID: <200509181920.j8IJK3f9098304@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 86304 >Category: ports >Synopsis: [PATCH] graphics/jpeg does not have 'extern "C"' for C++ >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Sep 18 19:20:03 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Craig Rodrigues >Release: FreeBSD 7.0-CURRENT i386 >Organization: >Environment: System: FreeBSD dibbler.crodrigues.org 7.0-CURRENT FreeBSD 7.0-CURRENT #21: Sat Sep 10 19:15:12 EDT 2005 rodrigc@dibbler.crodrigues.org:/usr/obj/usr/src/sys/MYKERNEL1 i386 >Description: If jpeglib.h is included in a C++ program, the functions in libjpeg cannot be linked against, because the function prototypes are not decorated with 'extern "C"' >How-To-Repeat: If you put the following code snippet: #include <stdio.h> #include "jpeglib.h" int main(int argc, char *argv[]) { jpeg_std_error(NULL); } in a C file (test.c), and compile with: gcc -I/usr/local/include test.c -L/usr/local/lib -ljpeg it will compile and link fine. If you rename the file to test.cpp, and compile with: g++ -I/usr/local/include test.cpp -L/usr/local/lib -ljpeg You will get a link error: : undefined reference to `jpeg_std_error(jpeg_error_mgr*)' >Fix: The fix is to re define the EXTERN macro if you are compiling with a C++ compiler. Index: patch-jmorecfg.h =================================================================== RCS file: patch-jmorecfg.h diff -N patch-jmorecfg.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patch-jmorecfg.h 18 Sep 2005 19:01:01 -0000 @@ -0,0 +1,15 @@ +--- jmorecfg.h.orig Sun Sep 18 14:53:48 2005 ++++ jmorecfg.h Sun Sep 18 14:54:27 2005 +@@ -187,8 +187,11 @@ + /* a function referenced thru EXTERNs: */ + #define GLOBAL(type) type + /* a reference to a GLOBAL function: */ ++#ifdef __cplusplus ++#define EXTERN(type) extern "C" type ++#else + #define EXTERN(type) extern type +- ++#endif + + /* This macro is used to declare a "method", that is, a function pointer. + * We want to supply prototype parameters if the compiler can cope. >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200509181915.j8IJFPoQ037999>