I am building using zlib.h which I have a local copy to v1.2.5, but in /usr/include/zlib.h there is v1.2.1.2.
我正在使用zlib构建。我有一个本地副本到v1.2.5,但是在/usr/include/zlib中。h v1.2.1.2。
If I omit adding -I/my/path/to/zlib to my make I get error from using old version which doesn't have Z_FIXED:
如果我省略添加-I/my/path/to/zlib到我的make,我就会从使用没有Z_FIXED的旧版本中得到错误:
g++ -g -Werror -Wredundant-decls -D_FILE_OFFSET_BITS=64 -c -o ARCH.linux_26_i86/debug/sysParam.o sysParam.cpp
sysParam.cpp: In member function `std::string CSysParamAccess::getCompressionStrategyName() const':
sysParam.cpp:1816: error: `Z_FIXED' was not declared in this scope
sysParam.cpp: In member function `bool CSysParamAccess::setCompressionStrategy(const std::string&, paramSource)':
sysParam.cpp:1849: error: `Z_FIXED' was not declared in this scope
Alternatively, if I add the include path to the zlib z1.2.5 I am using, I get double defines, it seems as if the zlib.h is included twice with two different sets of -D values, but I don't see how that is happening:
或者,如果我将include路径添加到zlib z1.2.5中,我得到了双重定义,似乎是zlib。h包含两组不同的-D值,但我不知道这是怎么发生的:
g++ -g -Werror -Wredundant-decls -I../../src/zlib-1.2.5 -D_FILE_OFFSET_BITS=64 -c -o ARCH.linux_26_i86/debug/sysParam.o sysParam.cpp
In file included from sysParam.cpp:24:
../../src/zlib-1.2.5/zlib.h:1582: warning: redundant redeclaration of `void* gzopen64(const char*, const char*)' in same scope
../../src/zlib-1.2.5/zlib.h:1566: warning: previous declaration of `void* gzopen64(const char*, const char*)'
../../src/zlib-1.2.5/zlib.h:1583: warning: redundant redeclaration of `long long int gzseek64(void*, long long int, int)' in same scope
../../src/zlib-1.2.5/zlib.h:1567: warning: previous declaration of `off64_t gzseek64(void*, off64_t, int)'
../../src/zlib-1.2.5/zlib.h:1584: warning: redundant redeclaration of `long long int gztell64(void*)' in same scope
../../src/zlib-1.2.5/zlib.h:1568: warning: previous declaration of `off64_t gztell64(void*)'
../../src/zlib-1.2.5/zlib.h:1585: warning: redundant redeclaration of `long long int gzoffset64(void*)' in same scope
../../src/zlib-1.2.5/zlib.h:1569: warning: previous declaration of `off64_t gzoffset64(void*)'
../../src/zlib-1.2.5/zlib.h:1586: warning: redundant redeclaration of `uLong adler32_combine64(uLong, uLong, long long int)' in same scope
../../src/zlib-1.2.5/zlib.h:1570: warning: previous declaration of `uLong adler32_combine64(uLong, uLong, off64_t)'
../../src/zlib-1.2.5/zlib.h:1587: warning: redundant redeclaration of `uLong crc32_combine64(uLong, uLong, long long int)' in same scope
../../src/zlib-1.2.5/zlib.h:1571: warning: previous declaration of `uLong crc32_combine64(uLong, uLong, off64_t)'
Here some of the relavent lines from zlib.h referred to above:
这里是zlib的一些中继线路。上面所提及的h:
// This would be line 1558 of zlib.h
/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
* change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
* both are true, the application gets the *64 functions, and the regular
* functions are changed to 64 bits) -- in case these are set on systems
* without large file support, _LFS64_LARGEFILE must also be true
*/
#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
#endif
#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0
# define gzopen gzopen64
# define gzseek gzseek64
# define gztell gztell64
# define gzoffset gzoffset64
# define adler32_combine adler32_combine64
# define crc32_combine crc32_combine64
# ifdef _LARGEFILE64_SOURCE
ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
# endif
#else
ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
#endif
// This would be line 1597 of zlib.h
I'm not sure how to track this down further. I tried moving the include of zlib.h to the top and bottom of the includes list of the cpp file, but it made no difference.
我不知道该如何进一步追查下去。我试着移动zlib的include。h的顶部和底部的包括cpp文件,但它没有区别。
An excerpt of passing -E to g++ shows in part:
一段通过-E到g++的片段:
extern int inflateInit2_ (z_streamp strm, int windowBits, const char *version, int stream_size);
extern int inflateBackInit_ (z_streamp strm, int windowBits, unsigned char *window, const char *version, int stream_size);
# 1566 "../../src/zlib-1.2.5/zlib.h"
extern gzFile gzopen64 (const char *, const char *);
extern off64_t gzseek64 (gzFile, off64_t, int);
extern off64_t gztell64 (gzFile);
extern off64_t gzoffset64 (gzFile);
extern uLong adler32_combine64 (uLong, uLong, off64_t);
extern uLong crc32_combine64 (uLong, uLong, off64_t);
# 1582 "../../src/zlib-1.2.5/zlib.h"
extern gzFile gzopen64 (const char *, const char *);
extern long long gzseek64 (gzFile, long long, int);
extern long long gztell64 (gzFile);
extern long long gzoffset64 (gzFile);
extern uLong adler32_combine64 (uLong, uLong, long long);
extern uLong crc32_combine64 (uLong, uLong, long long);
# 1600 "../../src/zlib-1.2.5/zlib.h"
struct internal_state {int dummy;};
Not sure why lines 1566 and 1582 are coming out together in the CPP output, but hence the warning about duplicate declarations.
不确定为什么第1566和1582行在CPP输出中一起出现,但是因此警告重复声明。
3 个解决方案
#1
2
-nostdinc
answers the question in your Q's title -- quoting this manpage, it means:
- dinc回答你Q的标题中的问题——引用这个手册,它的意思是:
Do not search the standard system directories for header files. Only the directories you have specified with -I options (and the directory of the current file, if appropriate) are searched.
不要搜索头文件的标准系统目录。只有您指定的目录i - options(以及当前文件的目录,如果合适)被搜索。
However, I don't think it will solve your actual problem, which seems to be due to two mutually incompatible parts of the same non-system header file getting included -- that feels more likely to be due to some needed -D
being missing, but I can't say exactly what since I'm not familiar with that specific header file.
然而,我不认为这将解决你的实际问题,这似乎是由于两个互不相容的部分相同的非系统的头文件要包括,感觉更可能由于一些需要- d是失踪,但我不能说什么,因为我不熟悉特定头文件。
#2
0
My guess is that in some instances you have:
我的猜测是,在某些情况下
#include <zlib.h>
# include < zlib.h >
and in others you have
而在其他人身上。
#include "zlib.h"
# include“zlib.h”
You will find the old (system) zlib.h in the first case and the new (user) zlib.h in the second case.
您将找到旧的(系统)zlib。h在第一种情况下,新的(用户)zlib。h在第二种情况下。
The fix for this is to use -isystem
instead of -I
for your new zlib includes, i.e. -isystem /my/path/to/zlib/includes
instead of -I /my/path/to/zlib/includes
.
解决这个问题的方法是使用-isystem而不是-I为您的新zlib包括,即-isystem /my/path/to/zlib/include而不是-I /my/path/to/zlib/include。
#3
0
I got a similar error when compiling leptonica on Solaris 5.10 (64-bit SPARC), and I agree with Alex: some necessary define is missing or something. On a whim, I added _FILE_OFFSET_BITS=64 (./configure CPPFLAGS='-D_FILE_OFFSET_BITS=64'), which "worked" (it compiled). This is a bit of cargo-cult programming of course, 'cause I don't know why I should have had to do that. I haven't actually tried to use leptonica yet, so it might core or something 'cause I added that define when I built it.
在Solaris 5.10(64位SPARC)上编译leptonica时,我也犯了类似的错误,我同意Alex的观点:一些必要的定义丢失了或者什么。在突发奇想中,我添加了_FILE_OFFSET_BITS=64(。/配置CPPFLAGS='-D_FILE_OFFSET_BITS=64'),它"工作"(编译)。这当然是一种卡式的编程,因为我不知道为什么我要这么做。我还没有尝试过使用leptonica,所以它可能是core或者什么的因为我添加了这个定义当我构建它的时候。
#1
2
-nostdinc
answers the question in your Q's title -- quoting this manpage, it means:
- dinc回答你Q的标题中的问题——引用这个手册,它的意思是:
Do not search the standard system directories for header files. Only the directories you have specified with -I options (and the directory of the current file, if appropriate) are searched.
不要搜索头文件的标准系统目录。只有您指定的目录i - options(以及当前文件的目录,如果合适)被搜索。
However, I don't think it will solve your actual problem, which seems to be due to two mutually incompatible parts of the same non-system header file getting included -- that feels more likely to be due to some needed -D
being missing, but I can't say exactly what since I'm not familiar with that specific header file.
然而,我不认为这将解决你的实际问题,这似乎是由于两个互不相容的部分相同的非系统的头文件要包括,感觉更可能由于一些需要- d是失踪,但我不能说什么,因为我不熟悉特定头文件。
#2
0
My guess is that in some instances you have:
我的猜测是,在某些情况下
#include <zlib.h>
# include < zlib.h >
and in others you have
而在其他人身上。
#include "zlib.h"
# include“zlib.h”
You will find the old (system) zlib.h in the first case and the new (user) zlib.h in the second case.
您将找到旧的(系统)zlib。h在第一种情况下,新的(用户)zlib。h在第二种情况下。
The fix for this is to use -isystem
instead of -I
for your new zlib includes, i.e. -isystem /my/path/to/zlib/includes
instead of -I /my/path/to/zlib/includes
.
解决这个问题的方法是使用-isystem而不是-I为您的新zlib包括,即-isystem /my/path/to/zlib/include而不是-I /my/path/to/zlib/include。
#3
0
I got a similar error when compiling leptonica on Solaris 5.10 (64-bit SPARC), and I agree with Alex: some necessary define is missing or something. On a whim, I added _FILE_OFFSET_BITS=64 (./configure CPPFLAGS='-D_FILE_OFFSET_BITS=64'), which "worked" (it compiled). This is a bit of cargo-cult programming of course, 'cause I don't know why I should have had to do that. I haven't actually tried to use leptonica yet, so it might core or something 'cause I added that define when I built it.
在Solaris 5.10(64位SPARC)上编译leptonica时,我也犯了类似的错误,我同意Alex的观点:一些必要的定义丢失了或者什么。在突发奇想中,我添加了_FILE_OFFSET_BITS=64(。/配置CPPFLAGS='-D_FILE_OFFSET_BITS=64'),它"工作"(编译)。这当然是一种卡式的编程,因为我不知道为什么我要这么做。我还没有尝试过使用leptonica,所以它可能是core或者什么的因为我添加了这个定义当我构建它的时候。