public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* error: template with C linkage
@ 2011-09-17 13:23 Jeffrey Walton
  2011-09-17 13:48 ` Marc Glisse
  2011-09-17 20:21 ` Jonathan Wakely
  0 siblings, 2 replies; 11+ messages in thread
From: Jeffrey Walton @ 2011-09-17 13:23 UTC (permalink / raw)
  To: GCC Users List

Hi All,

I'm working on a OpenBSD 4.9 system, and I've receiving multiple
"error: template with C linkage" errors. OpenBSD uses a 4.2.1
compiler.
$ gcc --version
gcc (GCC) 4.2.1 20070719
Copyright (C) 2007 Free Software Foundation, Inc.

A typical output is:
g++ -g3 -ggdb -O0 -pipe -fsigned-char -fmessage-length=0
-Woverloaded-virtual -Wreorder -Wformat=2 -Wformat-security
-Wno-unused -fvisibility=hidden -fstack-protector -I. -I./esapi
-I./deps -I/usr/local/include -fpic -c src/codecs/HTMLEntityCodec.cpp
-o src/codecs/HTMLEntityCodec.o
In file included from /usr//include/cryptopp/misc.h:4,
                 from ./esapi/crypto/Crypto++Common.h:24,
                 from src/codecs/HTMLEntityCodec.cpp:12:
/usr//include/cryptopp/cryptlib.h:99: error: template with C linkage
/usr//include/cryptopp/cryptlib.h:247: error: template with C linkage
/usr//include/cryptopp/cryptlib.h:254: error: template with C linkage
/usr//include/cryptopp/cryptlib.h:261: error: template with C linkage
/usr//include/cryptopp/cryptlib.h:268: error: template with C linkage
/usr//include/cryptopp/cryptlib.h:293: error: template with C linkage
/usr//include/cryptopp/cryptlib.h:698: error: template with C linkage

The first offending line in cryptlib.h is:

// VC60 workaround: using enums as template parameters causes problems
template <typename ENUM_TYPE, int VALUE>
struct EnumToType
{
	static ENUM_TYPE ToEnum() {return (ENUM_TYPE)VALUE;}
};

I've tried adding '-x c++' to force c++ in the files. I have also
audited Crypto++ and my code for a 'dangling extern "C"'. Crypto++
uses extern "C" about 13 times (a typical usage is below), and I don't
use it.

#ifdef CRYPTOPP_X64_MASM_AVAILABLE
extern "C" {
void Rijndael_Enc_AdvancedProcessBlocks(void *locals, const word32 *k);
}
#endif

I built Crypto++ from sources (it compiled and self-tested OK) and
then installed it via makefile. So I'm surprised to find Crypto++ is
[supposedly] causing problems.

I found a few bug reports relating to a spurious error, but they
appeared to be for platforms other than x86/x64.

Any ideas?

Jeff

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: error: template with C linkage
  2011-09-17 13:23 error: template with C linkage Jeffrey Walton
@ 2011-09-17 13:48 ` Marc Glisse
  2011-09-17 14:58   ` Jeffrey Walton
  2011-09-17 20:21 ` Jonathan Wakely
  1 sibling, 1 reply; 11+ messages in thread
From: Marc Glisse @ 2011-09-17 13:48 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: GCC Users List

On Sat, 17 Sep 2011, Jeffrey Walton wrote:

> Hi All,
>
> I'm working on a OpenBSD 4.9 system, and I've receiving multiple
> "error: template with C linkage" errors. OpenBSD uses a 4.2.1
> compiler.
> $ gcc --version
> gcc (GCC) 4.2.1 20070719
> Copyright (C) 2007 Free Software Foundation, Inc.
>
> A typical output is:
> g++ -g3 -ggdb -O0 -pipe -fsigned-char -fmessage-length=0
> -Woverloaded-virtual -Wreorder -Wformat=2 -Wformat-security
> -Wno-unused -fvisibility=hidden -fstack-protector -I. -I./esapi
> -I./deps -I/usr/local/include -fpic -c src/codecs/HTMLEntityCodec.cpp
> -o src/codecs/HTMLEntityCodec.o
> In file included from /usr//include/cryptopp/misc.h:4,
>                 from ./esapi/crypto/Crypto++Common.h:24,
>                 from src/codecs/HTMLEntityCodec.cpp:12:
> /usr//include/cryptopp/cryptlib.h:99: error: template with C linkage
> /usr//include/cryptopp/cryptlib.h:247: error: template with C linkage
> /usr//include/cryptopp/cryptlib.h:254: error: template with C linkage
> /usr//include/cryptopp/cryptlib.h:261: error: template with C linkage
> /usr//include/cryptopp/cryptlib.h:268: error: template with C linkage
> /usr//include/cryptopp/cryptlib.h:293: error: template with C linkage
> /usr//include/cryptopp/cryptlib.h:698: error: template with C linkage
>
> The first offending line in cryptlib.h is:
>
> // VC60 workaround: using enums as template parameters causes problems
> template <typename ENUM_TYPE, int VALUE>
> struct EnumToType
> {
> 	static ENUM_TYPE ToEnum() {return (ENUM_TYPE)VALUE;}
> };
>
> I've tried adding '-x c++' to force c++ in the files. I have also
> audited Crypto++ and my code for a 'dangling extern "C"'. Crypto++
> uses extern "C" about 13 times (a typical usage is below), and I don't
> use it.
>
> #ifdef CRYPTOPP_X64_MASM_AVAILABLE
> extern "C" {
> void Rijndael_Enc_AdvancedProcessBlocks(void *locals, const word32 *k);
> }
> #endif
>
> I built Crypto++ from sources (it compiled and self-tested OK) and
> then installed it via makefile. So I'm surprised to find Crypto++ is
> [supposedly] causing problems.
>
> I found a few bug reports relating to a spurious error, but they
> appeared to be for platforms other than x86/x64.
>
> Any ideas?

Does it make a difference if you put the crypto++ headers in a non-system 
location and include them from there with -I?

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: error: template with C linkage
  2011-09-17 13:48 ` Marc Glisse
@ 2011-09-17 14:58   ` Jeffrey Walton
  0 siblings, 0 replies; 11+ messages in thread
From: Jeffrey Walton @ 2011-09-17 14:58 UTC (permalink / raw)
  To: GCC Users List

On Sat, Sep 17, 2011 at 9:47 AM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Sat, 17 Sep 2011, Jeffrey Walton wrote:
>
>> Hi All,
>>
>> I'm working on a OpenBSD 4.9 system, and I've receiving multiple
>> "error: template with C linkage" errors. OpenBSD uses a 4.2.1
>> compiler.
>> $ gcc --version
>> gcc (GCC) 4.2.1 20070719
>> Copyright (C) 2007 Free Software Foundation, Inc.
>>
>> A typical output is:
>> g++ -g3 -ggdb -O0 -pipe -fsigned-char -fmessage-length=0
>> -Woverloaded-virtual -Wreorder -Wformat=2 -Wformat-security
>> -Wno-unused -fvisibility=hidden -fstack-protector -I. -I./esapi
>> -I./deps -I/usr/local/include -fpic -c src/codecs/HTMLEntityCodec.cpp
>> -o src/codecs/HTMLEntityCodec.o
>> In file included from /usr//include/cryptopp/misc.h:4,
>>                from ./esapi/crypto/Crypto++Common.h:24,
>>                from src/codecs/HTMLEntityCodec.cpp:12:
>> /usr//include/cryptopp/cryptlib.h:99: error: template with C linkage
>> /usr//include/cryptopp/cryptlib.h:247: error: template with C linkage
>> /usr//include/cryptopp/cryptlib.h:254: error: template with C linkage
>> /usr//include/cryptopp/cryptlib.h:261: error: template with C linkage
>> /usr//include/cryptopp/cryptlib.h:268: error: template with C linkage
>> /usr//include/cryptopp/cryptlib.h:293: error: template with C linkage
>> /usr//include/cryptopp/cryptlib.h:698: error: template with C linkage
>>
>> The first offending line in cryptlib.h is:
>>
>> // VC60 workaround: using enums as template parameters causes problems
>> template <typename ENUM_TYPE, int VALUE>
>> struct EnumToType
>> {
>>        static ENUM_TYPE ToEnum() {return (ENUM_TYPE)VALUE;}
>> };
>>
>> I've tried adding '-x c++' to force c++ in the files. I have also
>> audited Crypto++ and my code for a 'dangling extern "C"'. Crypto++
>> uses extern "C" about 13 times (a typical usage is below), and I don't
>> use it.
>>
>> #ifdef CRYPTOPP_X64_MASM_AVAILABLE
>> extern "C" {
>> void Rijndael_Enc_AdvancedProcessBlocks(void *locals, const word32 *k);
>> }
>> #endif
>>
>> I built Crypto++ from sources (it compiled and self-tested OK) and
>> then installed it via makefile. So I'm surprised to find Crypto++ is
>> [supposedly] causing problems.
>>
>> I found a few bug reports relating to a spurious error, but they
>> appeared to be for platforms other than x86/x64.
>
> Does it make a difference if you put the crypto++ headers in a non-system
> location and include them from there with -I?
Thanks Marc. Changing PREFIX to /usr/local did the trick.

Jeff

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: error: template with C linkage
  2011-09-17 13:23 error: template with C linkage Jeffrey Walton
  2011-09-17 13:48 ` Marc Glisse
@ 2011-09-17 20:21 ` Jonathan Wakely
  2011-09-19  1:56   ` Jeffrey Walton
  1 sibling, 1 reply; 11+ messages in thread
From: Jonathan Wakely @ 2011-09-17 20:21 UTC (permalink / raw)
  To: noloader; +Cc: GCC Users List

On 17 September 2011 14:23, Jeffrey Walton wrote:
> /usr//include/cryptopp/cryptlib.h:99: error: template with C linkage
...
> I've tried adding '-x c++' to force c++ in the files.

That's obviously not going to help.

If the compiler complains about a template, it's not compiling C,
because there's no such thing in C.  Ditto for C linkage; everything
in C has C linkage, so there's no concept of any other kind of
language linkage, so no reason a C compiler would ever mention "C
linkage".  So the compiler was already treating the files as
containing C++ (just apparently assuming that everything in a system
directory gets an implicit extern "C" around it.)

Contrary to what some people seem to believe, extern "C" does NOT mean
the compiler is compiling "in C mode" or treating the source code as C
code, it means it's compiling C++ code with C language linkage i.e.
the symbols will be named such that they can be easily called from C
programs because the symbols names will not be mangled.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: error: template with C linkage
  2011-09-17 20:21 ` Jonathan Wakely
@ 2011-09-19  1:56   ` Jeffrey Walton
  2011-09-19  5:47     ` Marc Glisse
  0 siblings, 1 reply; 11+ messages in thread
From: Jeffrey Walton @ 2011-09-19  1:56 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: GCC Users List

On Sat, Sep 17, 2011 at 4:21 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 17 September 2011 14:23, Jeffrey Walton wrote:
>> /usr//include/cryptopp/cryptlib.h:99: error: template with C linkage
> ...
>> I've tried adding '-x c++' to force c++ in the files.
>
> That's obviously not going to help.
>
> If the compiler complains about a template, it's not compiling C,
> because there's no such thing in C.  Ditto for C linkage; everything
> in C has C linkage, so there's no concept of any other kind of
> language linkage, so no reason a C compiler would ever mention "C
> linkage".  So the compiler was already treating the files as
> containing C++ (just apparently assuming that everything in a system
> directory gets an implicit extern "C" around it.)
OK, thanks. I'm not sure what the implications of "system compiler"
are, but OpenBSD's configuration did not like those files in
/usr/include.

$ g++ -v
Reading specs from /usr/bin/../lib/gcc-lib/i386-unknown-openbsd4.9/4.2.1/specs
Target: i386-unknown-openbsd4.9
Configured with: OpenBSD/i386 system compiler
Thread model: posix
gcc version 4.2.1 20070719
$

Do you have any ideas why a location would make a difference?

Jeff

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: error: template with C linkage
  2011-09-19  1:56   ` Jeffrey Walton
@ 2011-09-19  5:47     ` Marc Glisse
  2011-09-19 19:20       ` Ian Lance Taylor
  2011-09-20  7:19       ` Miles Bader
  0 siblings, 2 replies; 11+ messages in thread
From: Marc Glisse @ 2011-09-19  5:47 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: GCC Users List

On Sun, 18 Sep 2011, Jeffrey Walton wrote:

> On Sat, Sep 17, 2011 at 4:21 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>> On 17 September 2011 14:23, Jeffrey Walton wrote:
>>> /usr//include/cryptopp/cryptlib.h:99: error: template with C linkage
>> ...
>>> I've tried adding '-x c++' to force c++ in the files.
>>
>> That's obviously not going to help.
>>
>> If the compiler complains about a template, it's not compiling C,
>> because there's no such thing in C.  Ditto for C linkage; everything
>> in C has C linkage, so there's no concept of any other kind of
>> language linkage, so no reason a C compiler would ever mention "C
>> linkage".  So the compiler was already treating the files as
>> containing C++ (just apparently assuming that everything in a system
>> directory gets an implicit extern "C" around it.)
> OK, thanks. I'm not sure what the implications of "system compiler"
> are, but OpenBSD's configuration did not like those files in
> /usr/include.
>
> $ g++ -v
> Reading specs from /usr/bin/../lib/gcc-lib/i386-unknown-openbsd4.9/4.2.1/specs
> Target: i386-unknown-openbsd4.9
> Configured with: OpenBSD/i386 system compiler
> Thread model: posix
> gcc version 4.2.1 20070719
> $
>
> Do you have any ideas why a location would make a difference?

Antique platforms have system headers that don't know about C++, so g++ 
implicitly adds extern "C" around them. And being a system header is a 
property that depends on the directory the file is in.

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: error: template with C linkage
  2011-09-19  5:47     ` Marc Glisse
@ 2011-09-19 19:20       ` Ian Lance Taylor
  2011-09-19 22:38         ` Kevin P. Fleming
  2011-09-20  7:19       ` Miles Bader
  1 sibling, 1 reply; 11+ messages in thread
From: Ian Lance Taylor @ 2011-09-19 19:20 UTC (permalink / raw)
  To: GCC Users List; +Cc: Jeffrey Walton

Marc Glisse <marc.glisse@inria.fr> writes:

> On Sun, 18 Sep 2011, Jeffrey Walton wrote:
>
>> On Sat, Sep 17, 2011 at 4:21 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>>> On 17 September 2011 14:23, Jeffrey Walton wrote:
>>>> /usr//include/cryptopp/cryptlib.h:99: error: template with C linkage
>>> ...
>>>> I've tried adding '-x c++' to force c++ in the files.
>>>
>>> That's obviously not going to help.
>>>
>>> If the compiler complains about a template, it's not compiling C,
>>> because there's no such thing in C.  Ditto for C linkage; everything
>>> in C has C linkage, so there's no concept of any other kind of
>>> language linkage, so no reason a C compiler would ever mention "C
>>> linkage".  So the compiler was already treating the files as
>>> containing C++ (just apparently assuming that everything in a system
>>> directory gets an implicit extern "C" around it.)
>> OK, thanks. I'm not sure what the implications of "system compiler"
>> are, but OpenBSD's configuration did not like those files in
>> /usr/include.
>>
>> $ g++ -v
>> Reading specs from /usr/bin/../lib/gcc-lib/i386-unknown-openbsd4.9/4.2.1/specs
>> Target: i386-unknown-openbsd4.9
>> Configured with: OpenBSD/i386 system compiler
>> Thread model: posix
>> gcc version 4.2.1 20070719
>> $
>>
>> Do you have any ideas why a location would make a difference?
>
> Antique platforms have system headers that don't know about C++, so
> g++ implicitly adds extern "C" around them. And being a system header
> is a property that depends on the directory the file is in.

This approach is controlled on a target-by-target basis, by the way.  If
OpenBSD's header files are C++ ready, gcc's OpenBSD target configuration
should be changed to define NO_IMPLICIT_EXTERN_C.

Ian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: error: template with C linkage
  2011-09-19 19:20       ` Ian Lance Taylor
@ 2011-09-19 22:38         ` Kevin P. Fleming
  2011-09-19 23:01           ` Ian Lance Taylor
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin P. Fleming @ 2011-09-19 22:38 UTC (permalink / raw)
  To: gcc-help

On 09/19/2011 02:19 PM, Ian Lance Taylor wrote:
> Marc Glisse<marc.glisse@inria.fr>  writes:
>
>> On Sun, 18 Sep 2011, Jeffrey Walton wrote:
>>
>>> On Sat, Sep 17, 2011 at 4:21 PM, Jonathan Wakely<jwakely.gcc@gmail.com>  wrote:
>>>> On 17 September 2011 14:23, Jeffrey Walton wrote:
>>>>> /usr//include/cryptopp/cryptlib.h:99: error: template with C linkage
>>>> ...
>>>>> I've tried adding '-x c++' to force c++ in the files.
>>>>
>>>> That's obviously not going to help.
>>>>
>>>> If the compiler complains about a template, it's not compiling C,
>>>> because there's no such thing in C.  Ditto for C linkage; everything
>>>> in C has C linkage, so there's no concept of any other kind of
>>>> language linkage, so no reason a C compiler would ever mention "C
>>>> linkage".  So the compiler was already treating the files as
>>>> containing C++ (just apparently assuming that everything in a system
>>>> directory gets an implicit extern "C" around it.)
>>> OK, thanks. I'm not sure what the implications of "system compiler"
>>> are, but OpenBSD's configuration did not like those files in
>>> /usr/include.
>>>
>>> $ g++ -v
>>> Reading specs from /usr/bin/../lib/gcc-lib/i386-unknown-openbsd4.9/4.2.1/specs
>>> Target: i386-unknown-openbsd4.9
>>> Configured with: OpenBSD/i386 system compiler
>>> Thread model: posix
>>> gcc version 4.2.1 20070719
>>> $
>>>
>>> Do you have any ideas why a location would make a difference?
>>
>> Antique platforms have system headers that don't know about C++, so
>> g++ implicitly adds extern "C" around them. And being a system header
>> is a property that depends on the directory the file is in.
>
> This approach is controlled on a target-by-target basis, by the way.  If
> OpenBSD's header files are C++ ready, gcc's OpenBSD target configuration
> should be changed to define NO_IMPLICIT_EXTERN_C.

Does '-isystem' factor into this in any way? I would hope that using 
'-isystem' to specify an additional directory of 'system' header files 
would not also turn on implicit 'extern "C"' mode.

If you are curious, we use '-isystem' to have GCC relax our 
warning/error modes on header files that are nominally part of our 
project but are installed into 'system' locations (like 
/opt/<package>/include).

-- 
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
Jabber: kfleming@digium.com | SIP: kpfleming@digium.com | Skype: kpfleming
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at www.digium.com & www.asterisk.org

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: error: template with C linkage
  2011-09-19 22:38         ` Kevin P. Fleming
@ 2011-09-19 23:01           ` Ian Lance Taylor
  0 siblings, 0 replies; 11+ messages in thread
From: Ian Lance Taylor @ 2011-09-19 23:01 UTC (permalink / raw)
  To: Kevin P. Fleming; +Cc: gcc-help

"Kevin P. Fleming" <kpfleming@digium.com> writes:

>> This approach is controlled on a target-by-target basis, by the way.  If
>> OpenBSD's header files are C++ ready, gcc's OpenBSD target configuration
>> should be changed to define NO_IMPLICIT_EXTERN_C.
>
> Does '-isystem' factor into this in any way? I would hope that using
> -isystem' to specify an additional directory of 'system' header files
> would not also turn on implicit 'extern "C"' mode.
>
> If you are curious, we use '-isystem' to have GCC relax our
> warning/error modes on header files that are nominally part of our
> project but are installed into 'system' locations (like
> /opt/<package>/include).

Using -isystem causes the directory to be treated as a standard system
directory, which does indeed include implicit wrapping in extern "C" if
that is customary for the target.

Of course most targets these days do define NO_IMPLICIT_EXTERN_C,
OpenBSD seems to be a bit of an outlier in that regard, and that may
simply be a bug in gcc's OpenBSD support.

Ian

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: error: template with C linkage
  2011-09-19  5:47     ` Marc Glisse
  2011-09-19 19:20       ` Ian Lance Taylor
@ 2011-09-20  7:19       ` Miles Bader
  2011-09-20 13:32         ` Ian Lance Taylor
  1 sibling, 1 reply; 11+ messages in thread
From: Miles Bader @ 2011-09-20  7:19 UTC (permalink / raw)
  To: GCC Users List; +Cc: Jeffrey Walton

Marc Glisse <marc.glisse@inria.fr> writes:
> And being a system header is a property that depends on the directory
> the file is in.

Do you know how gcc define's "system header" ?

I've noticed that I sometimes get compiler warnings for library header
files, even though they're located in subdirectories of /usr/include and
-Wno-system-headers is turned on...

So I guess the test isn't just a simple prefix comparison with
"/usr/include/" ...

-Miles

-- 
We live, as we dream -- alone....

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: error: template with C linkage
  2011-09-20  7:19       ` Miles Bader
@ 2011-09-20 13:32         ` Ian Lance Taylor
  0 siblings, 0 replies; 11+ messages in thread
From: Ian Lance Taylor @ 2011-09-20 13:32 UTC (permalink / raw)
  To: Miles Bader; +Cc: GCC Users List, Jeffrey Walton

Miles Bader <miles@gnu.org> writes:

> Marc Glisse <marc.glisse@inria.fr> writes:
>> And being a system header is a property that depends on the directory
>> the file is in.
>
> Do you know how gcc define's "system header" ?
>
> I've noticed that I sometimes get compiler warnings for library header
> files, even though they're located in subdirectories of /usr/include and
> -Wno-system-headers is turned on...
>
> So I guess the test isn't just a simple prefix comparison with
> "/usr/include/" ...

You can see the set of system directories for your system by compiling a
file with the -v option.  They are the ones that come after

#include <...> search starts here:

Normally it's /usr/include, /usr/local/include, and a couple of target-
and version- specific directories.

If a file in /usr/include/X is #included as <X/a.h> then it will be a
system directory.  But if you are using an explicit -I then it will not.
You can make it a system directory by using -isystem rather than -I.

Ian

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-09-20 13:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-17 13:23 error: template with C linkage Jeffrey Walton
2011-09-17 13:48 ` Marc Glisse
2011-09-17 14:58   ` Jeffrey Walton
2011-09-17 20:21 ` Jonathan Wakely
2011-09-19  1:56   ` Jeffrey Walton
2011-09-19  5:47     ` Marc Glisse
2011-09-19 19:20       ` Ian Lance Taylor
2011-09-19 22:38         ` Kevin P. Fleming
2011-09-19 23:01           ` Ian Lance Taylor
2011-09-20  7:19       ` Miles Bader
2011-09-20 13:32         ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).