发新话题
打印

【求助】程序迁移中关于fpos_t的问题

【求助】程序迁移中关于fpos_t的问题

原来程序是可以在unix和windows下跑的,在原来的平台上fpos_t是和off_t或者long int等价的,所以下面的语句可以: % x1 S8 m8 Z! S1 p/ d  ~
       fpos_t m_nContentSize = 0
6 v/ x- J' {/ t" o+ q* d) I 但是在ubuntu下编译时上面的语句出错:
+ e0 @# g) n- y! P: ^/ s+ b6 b 错误: no match 为 ‘operator=’ 在 ‘((CFileFlow*)this)->CFileFlow::m_nContentSize = 0’ 中 4 /usr/include/_G_config.h:30: 附注: 备选为: _G_fpos_t& _G_fpos_t:: operator=(const _G_fpos_t&) $ x+ q  d/ r4 O
  ) ]3 l  G: r# u$ Q# Q1 z$ R# f' s$ s
stdio.h中:
& X+ V& l4 X  I4 j       typedef _G_fpos_t fpos_t
3 e1 {9 J7 u+ ` _G_config.h中: 7 X7 s6 a3 b" A! _
       typedef struct
# M, X. F3 D$ i       {
- F( _5 i4 ~: h6 C! i# T' c         __off_t __pos; % V! O3 V. b5 i# R* |
         __mbstate_t __state;
' z, T8 V, O. ~# L% D       } _G_fpos_t; , a* o2 G2 G+ m# `7 s" h( _
  
& N$ Q& h" @* D) _# j' m 官方的Manual也是这么说的: . K  ~0 ?0 E: j6 s) {% A
This is the type of an object that can encode information about the file position of a stream, for use by the functions fgetpos and fsetpos.
/ |) A6 Y- [" W3 y/ o1 L  
. V4 y$ ]2 Y  @ In the GNU system, fpos_t is an opaque data structure that contains internal data to represent file offset and conversion state information. In other systems, it might have a different internal representation.  
8 v7 y) E6 P* ]' Y; j9 @% y1 J7 Z  
3 |' j  x/ p9 D2 v# } 想请问我的程序怎么样才能移植到Ubuntu上来呢?
9 w4 a4 I1 y2 y8 ]3 f! I先谢了。      

TOP

typedef struct 3 x2 a! R0 C' Z8 O$ w5 g1 C& E* N: b, \. I
{ 6 W- _: j2 C7 A2 y6 R0 T! ^8 V( H" Y* g
__off_t __pos; ( Q: F$ y6 T; c/ G% p' Z+ A0 a
__mbstate_t __state;
5 ]1 s* d  s. W5 T# }$ D- f" u; K} _G_fpos_t;
5 [: C, S0 V3 L* L. v1 A这可不是你想的long int哦。要么就重新typedef fpos_t,不过怎么会扯到_G_config.h上呢?仔细研究研究所有关联的定义,找出重复的和错误的,就是这样。      
上帝说,有问题,找GOOGLE 写程序是很神圣的事情!同样只是装系统,卖菜的大娘会的事情不见得就跟卖菜一样了。

TOP

[QUOTE=flag]typedef struct
: B" j4 W& ]9 n8 p" k' V8 C {
/ k6 N0 e! G5 r8 x __off_t __pos;
; Q7 u" a- v, w7 N8 ^  l. A __mbstate_t __state; ( H# |0 Y- N6 f& {& _( y) M
} _G_fpos_t;
( [3 X1 D: o' y1 E, g. ` 这可不是你想的long int哦。要么就重新typedef fpos_t,不过怎么会扯到_G_config.h上呢?仔细研究研究所有关联的定义,找出重复的和错误的,就是这样。[/QUOTE]我的程序是必须#include <stdio.h>的,因为要用许多库函数,
2 v" C' v3 s) Z而stdio.h里面是这样定义fpos_t的:
: d7 z- ^& y4 G2 r- ]& g#include <_G_config.h>
: C# Y& m3 g5 e9 E, S" q" y...
  n+ `, G7 e0 J2 Jtypedef  _G_fpos_t  fpos_t;
1 j/ t5 i+ d* x) \: s( }: A$ N9 K! _5 a
所以fpos_t实际上是被定义成_G_fpos_t的.
, M' [4 G" j, i8 Z& K
1 j) l6 _! S+ M5 K% `/ M' D& K: K如果我在自己的代码中typedef off_t fpos_t,编译自然就说“两次冲突的fpos_t定义”。
2 v3 H4 }& V7 h* l% X如果强行吧stdio.h中的`typedef _G_fpos_t  fpos_t' 改成 `typedef off_t fpos_t',那所有使用stdio.h的代码都被改了,天知道会出现什么情况。8 f, F/ y3 M. @0 v& p1 g7 ~

' F  H; {# f! g2 I7 Q& p真是头痛啊。9 ?# y! @' O6 I8 h$ K
为什么GNU的fpos_t要这么奇怪呢。。。      

TOP

移植的问题就是这样,所以要针对不同的编译环境作处理,用那些预编译指令来作判断。      
上帝说,有问题,找GOOGLE 写程序是很神圣的事情!同样只是装系统,卖菜的大娘会的事情不见得就跟卖菜一样了。

TOP

发新话题