Compiling STk v 2.2.0 with g++ 2.7
Hello everyone,
I've recently switched from using Tcl/Tk to STk. My target machines
are HP9000/7xx, and I'm using a newly installed g++ version 2.7.
When compiling my application, written in C++, g++ gave me many
errors, provided below. The problem seems to be with stk.h and the
nested include statements. The large 'extern "C" { ... }' is wrapped
around standard include files, which causes conflicts because they are
interpreted differently. On any decent system, any standard C include
should be shadowed by the C++ compiler and you need not, in fact,
should not make the declaration external. It will do the correct
thing.
I don't have time at the moment to verify this against the C++
standard, but I believe it to be true and it always works for me.
I solved it by moving the 'extern "C" {' down to below the include
files. Everything works fine. Here are the diffs:
$ diff -c stk.h ../STk-2.2.0/Src/stk.h
*** stk.h Fri Jul 28 15:20:14 1995
--- ../STk-2.2.0/Src/stk.h Thu Jul 13 04:27:07 1995
***************
*** 26,31 ****
--- 26,34 ----
#ifndef _STK_H
#define _STK_H
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
#include <stdio.h>
#include <setjmp.h>
***************
*** 48,56 ****
*/
#include <tcl.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
/* ------------------------------------------------------------------------------ */
#define COMPACT_SMALL_CST /* compact coding for small const */
--- 51,56 ----
$
****************************************************************
Here are the errors generated by g++, so you can recognize the symptoms.
/usr/local/ngnu/lib/gcc-lib/hppa1.1-hp-hpux9.01/2.7.0/include/math.h: In function `double pow(double, int)':
In file included from /usr/local/lib/stk/2.2/include/stk.h:36,
from nvision.cc:1:
/usr/local/ngnu/lib/gcc-lib/hppa1.1-hp-hpux9.01/2.7.0/include/math.h:71: declaration of C function `double pow(double, int)' conflicts with
/usr/local/ngnu/lib/gcc-lib/hppa1.1-hp-hpux9.01/2.7.0/include/math.h:68: previous declaration `double pow(double, double)' here
/usr/local/ngnu/lib/gcc-lib/hppa1.1-hp-hpux9.01/2.7.0/include/math.h: In function `double pow(double, int)':
/usr/local/ngnu/lib/gcc-lib/hppa1.1-hp-hpux9.01/2.7.0/include/math.h:72: warning: `double' used for argument 2 of `pow(double, int)'
/usr/local/ngnu/lib/g++-include/std/cstring.h: In function `char * strchr(char *, int)':
In file included from /usr/local/ngnu/lib/g++-include/cstring:5,
from /usr/local/ngnu/lib/g++-include/string.h:5,
from /usr/local/lib/stk/2.2/include/stk.h:39,
from nvision.cc:1:
/usr/local/ngnu/lib/g++-include/std/cstring.h:33: declaration of C function `char * strchr(char *, int)' conflicts with
/usr/local/ngnu/lib/g++-include/std/cstring.h:30: previous declaration `const char * strchr(const char *, int)' here
/usr/local/ngnu/lib/g++-include/std/cstring.h: In function `char * strchr(char *, int)':
/usr/local/ngnu/lib/g++-include/std/cstring.h:34: warning: passing `const char *' as argument 1 of `strchr(char *, int)' discards const
/usr/local/ngnu/lib/g++-include/std/cstring.h: In function `char * strpbrk(char *, const char *)':
/usr/local/ngnu/lib/g++-include/std/cstring.h:40: declaration of C function `char * strpbrk(char *, const char *)' conflicts with
/usr/local/ngnu/lib/g++-include/std/cstring.h:37: previous declaration `const char * strpbrk(const char *, const char *)' here
/usr/local/ngnu/lib/g++-include/std/cstring.h: In function `char * strpbrk(char *, const char *)':
/usr/local/ngnu/lib/g++-include/std/cstring.h:41: warning: passing `const char *' as argument 1 of `strpbrk(char *, const char *)' discards const
/usr/local/ngnu/lib/g++-include/std/cstring.h: In function `char * strrchr(char *, int)':
/usr/local/ngnu/lib/g++-include/std/cstring.h:47: declaration of C function `char * strrchr(char *, int)' conflicts with
/usr/local/ngnu/lib/g++-include/std/cstring.h:44: previous declaration `const char * strrchr(const char *, int)' here
/usr/local/ngnu/lib/g++-include/std/cstring.h: In function `char * strrchr(char *, int)':
/usr/local/ngnu/lib/g++-include/std/cstring.h:48: warning: passing `const char *' as argument 1 of `strrchr(char *, int)' discards const
/usr/local/ngnu/lib/g++-include/std/cstring.h: In function `char * strstr(char *, const char *)':
/usr/local/ngnu/lib/g++-include/std/cstring.h:54: declaration of C function `char * strstr(char *, const char *)' conflicts with
/usr/local/ngnu/lib/g++-include/std/cstring.h:51: previous declaration `const char * strstr(const char *, const char *)' here
/usr/local/ngnu/lib/g++-include/std/cstring.h: In function `char * strstr(char *, const char *)':
/usr/local/ngnu/lib/g++-include/std/cstring.h:55: warning: passing `const char *' as argument 1 of `strstr(char *, const char *)' discards const
/usr/local/ngnu/lib/g++-include/std/cstring.h: In function `void * memchr(void *, int, unsigned int)':
/usr/local/ngnu/lib/g++-include/std/cstring.h:61: declaration of C function `void * memchr(void *, int, unsigned int)' conflicts with
/usr/local/ngnu/lib/g++-include/std/cstring.h:58: previous declaration `const void * memchr(const void *, int, unsigned int)' here
/usr/local/ngnu/lib/g++-include/std/cstring.h: In function `void * memchr(void *, int, unsigned int)':
/usr/local/ngnu/lib/g++-include/std/cstring.h:62: warning: passing `const void *' as argument 1 of `memchr(void *, int, unsigned int)' discards const
make: *** [nvision.o] Error 1
Received on Mon Jul 31 1995 - 19:23:55 CEST
This archive was generated by hypermail 2.3.0
: Mon Jul 21 2014 - 19:38:59 CEST