Chinaunix首页 | 论坛 | 博客
  • 博客访问: 607133
  • 博文数量: 353
  • 博客积分: 1104
  • 博客等级: 少尉
  • 技术积分: 1457
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-23 23:02
个人简介

1、刚工作时做Linux 流控;后来做安全操作系统;再后来做操作系统加固;现在做TCP 加速。唉!没离开过类Unix!!!但是水平有限。。

文章存档

2015年(80)

2013年(4)

2012年(90)

2011年(177)

2010年(1)

2009年(1)

分类: LINUX

2011-10-24 17:38:17

Hello everyone,


I get a strange compile error when compile such simple program. Any ideas?

foo.c: In function `main':
foo.c:5: error: storage size of 'var' isn't known

foo.c

Expand|Select|Wrap|Line Numbers
  1. #include "goo.h"
  2.  
  3. int main (int argc, char** argv)
  4. {
  5. t_st var;
  6. var.member = 100;
  7. return 0;
  8. }
  9.  
goo.c

Expand|Select|Wrap|Line Numbers
  1. struct st {
  2.  
  3. int member;
  4.  
  5. };
  6.  
  7.  
goo.h

Expand|Select|Wrap|Line Numbers
  1. typedef struct st t_st;
  2.  

thanks in advance,
George
========================================================
George wrote:
:: Hello everyone,
::
::
:: I get a strange compile error when compile such simple program. Any
:: ideas?
::
:: foo.c: In function `main':
:: foo.c:5: error: storage size of 'var' isn't known

The compiler can figure out that 'var' is of type 't_st', which is another
name for a struct named 'st'. However, it cannot see what 'st' is, as it is
hidden in another translation unit.

You can have a pointer to st without knowing exactly what it is, but you
cannot have a variable of type st without seeing the full definition.


Bo Persson

::
:: foo.c
::
::
Expand|Select|Wrap|Line Numbers
  1. :: #include "goo.h"
  2. ::
  3. :: int main (int argc, char** argv)
  4. :: {
  5. ::    t_st var;
  6. ::    var.member = 100;
  7. ::    return 0;
  8. :: }
  9. :: 
::
:: goo.c
::
::
Expand|Select|Wrap|Line Numbers
  1. :: struct st {
  2. ::
  3. :: int member;
  4. ::
  5. :: };
  6. ::
  7. :: 
::
:: goo.h
::
::
Expand|Select|Wrap|Line Numbers
  1. :: typedef struct st t_st;
  2. :: 
::
::
:: thanks in advance,
:: George

======================================================

I want to confirm that, if I define a struct in .c file, I can only use the
struct in the same .c file, and have no walk-around to utilize the struct in
other .c file.

If I want to use the struct in multiple .c files, I have to define it in .h
file?


regards,
George

"Bo Persson" wrote:
George wrote:
:: Hello everyone,
::
::
:: I get a strange compile error when compile such simple program. Any
:: ideas?
::
:: foo.c: In function `main':
:: foo.c:5: error: storage size of 'var' isn't known
>
The compiler can figure out that 'var' is of type 't_st', which is another
name for a struct named 'st'. However, it cannot see what 'st' is, as it is
hidden in another translation unit.
>
You can have a pointer to st without knowing exactly what it is, but you
cannot have a variable of type st without seeing the full definition.
>
>
Bo Persson
>
::
:: foo.c
::
::
Expand|Select|Wrap|Line Numbers
  1. :: #include "goo.h"
  2. ::
  3. :: int main (int argc, char** argv)
  4. :: {
  5. ::    t_st var;
  6. ::    var.member = 100;
  7. ::    return 0;
  8. :: }
  9. :: 
::
:: goo.c
::
::
Expand|Select|Wrap|Line Numbers
  1. :: struct st {
  2. ::
  3. :: int member;
  4. ::
  5. :: };
  6. ::
  7. :: 
::
:: goo.h
::
::
Expand|Select|Wrap|Line Numbers
  1. :: typedef struct st t_st;
  2. :: 
::
::
:: thanks in advance,
:: George
>
>
>
>
========================================================================
George wrote:
:: Thanks Bo Persson!
::
::
:: I want to confirm that, if I define a struct in .c file, I can only
:: use the struct in the same .c file, and have no walk-around to
:: utilize the struct in other .c file.

The "work-around" is to define the struct identically in both .c files. That
in effect simulates what happens when you include a .h file in both .c
files.

Not recommended! :-)

::
:: If I want to use the struct in multiple .c files, I have to define
:: it in .h file?

This is the reason for having .h files in the first place. It lets you share
declarations between several implementation files.


Bo Persson
======================================
补充另一个案例处理:
=======================================
masterbuilder wrote:
Just open /usr/include/linux/ethtool.h file and add #include before the struct declaration.


Wow! This actually made it work. Anyone else who has this problem should do this too. 

Thanks masterbuilder!

-----------------------------------------------
rying to emerge "libstatgrab" I get the following output: 

Code:

if /bin/sh ../../libtool --tag=CC --mode=compile i686-pc-linux-gnu-gcc -DHAVE_CO 
NFIG_H -I. -I. -I../..     -O3 -march=pentium4 -fomit-frame-pointer -fprefetch-l 
oop-arrays -ffast-math -fforce-addr -falign-functions=4 -funroll-loops -pipe -MT 
 page_stats.lo -MD -MP -MF ".deps/page_stats.Tpo" -c -o page_stats.lo page_stats 
.c; \ 
then mv -f ".deps/page_stats.Tpo" ".deps/page_stats.Plo"; else rm -f ".deps/page 
_stats.Tpo"; exit 1; fi 
In file included from network_stats.c:59: 
/usr/include/linux/ethtool.h:18: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:20: error: parse error before "advertising" 
/usr/include/linux/ethtool.h:21: error: parse error before "speed" 
/usr/include/linux/ethtool.h:22: error: parse error before "duplex" 
/usr/include/linux/ethtool.h:23: error: parse error before "port" 
/usr/include/linux/ethtool.h:24: error: parse error before "phy_address" 
/usr/include/linux/ethtool.h:25: error: parse error before "transceiver" 
/usr/include/linux/ethtool.h:26: error: parse error before "autoneg" 
/usr/include/linux/ethtool.h:27: error: parse error before "maxtxpkt" 
/usr/include/linux/ethtool.h:28: error: parse error before "maxrxpkt" 
/usr/include/linux/ethtool.h:29: error: parse error before "reserved" 
/usr/include/linux/ethtool.h:30: error: parse error before '}' token 
/usr/include/linux/ethtool.h:35: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:43: error: parse error before "n_stats" 
/usr/include/linux/ethtool.h:44: error: parse error before "testinfo_len" 
/usr/include/linux/ethtool.h:45: error: parse error before "eedump_len" 
/usr/include/linux/ethtool.h:46: error: parse error before "regdump_len" 
/usr/include/linux/ethtool.h:52: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:54: error: parse error before "wolopts" 
/usr/include/linux/ethtool.h:55: error: parse error before "sopass" 
/usr/include/linux/ethtool.h:56: error: parse error before '}' token 
/usr/include/linux/ethtool.h:60: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:66: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:67: error: conflicting types for 'version' 
/usr/include/linux/ethtool.h:37: error: previous declaration of 'version' was he 
re/usr/include/linux/ethtool.h:68: error: parse error before "len" 
/usr/include/linux/ethtool.h:69: error: parse error before "data" 
/usr/include/linux/ethtool.h:69: error: conflicting types for 'data' 
/usr/include/linux/ethtool.h:61: error: previous declaration of 'data' was here 
/usr/include/linux/ethtool.h:70: error: parse error before '}' token 
/usr/include/linux/ethtool.h:74: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:76: error: parse error before "offset" 
/usr/include/linux/ethtool.h:77: error: parse error before "len" 
/usr/include/linux/ethtool.h:78: error: parse error before "data" 
/usr/include/linux/ethtool.h:79: error: parse error before '}' token 
/usr/include/linux/ethtool.h:83: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:97: error: parse error before "rx_max_coalesced_fra 
mes" 
/usr/include/linux/ethtool.h:104: error: parse error before "rx_coalesce_usecs_i 
rq" 
/usr/include/linux/ethtool.h:105: error: parse error before "rx_max_coalesced_fr 
ames_irq" 
/usr/include/linux/ethtool.h:111: error: parse error before "tx_coalesce_usecs" 
/usr/include/linux/ethtool.h:119: error: parse error before "tx_max_coalesced_fr 
ames" 
/usr/include/linux/ethtool.h:126: error: parse error before "tx_coalesce_usecs_i 
rq" 
/usr/include/linux/ethtool.h:127: error: parse error before "tx_max_coalesced_fr 
ames_irq" 
/usr/include/linux/ethtool.h:134: error: parse error before "stats_block_coalesc 
e_usecs" 
/usr/include/linux/ethtool.h:143: error: parse error before "use_adaptive_rx_coa 
lesce" 
/usr/include/linux/ethtool.h:144: error: parse error before "use_adaptive_tx_coa 
lesce" 
/usr/include/linux/ethtool.h:150: error: parse error before "pkt_rate_low" 
/usr/include/linux/ethtool.h:151: error: parse error before "rx_coalesce_usecs_l 
ow" 
/usr/include/linux/ethtool.h:152: error: parse error before "rx_max_coalesced_fr 
ames_low" 
/usr/include/linux/ethtool.h:153: error: parse error before "tx_coalesce_usecs_l 
ow" 
/usr/include/linux/ethtool.h:154: error: parse error before "tx_max_coalesced_fr 
ames_low" 
/usr/include/linux/ethtool.h:165: error: parse error before "pkt_rate_high" 
/usr/include/linux/ethtool.h:166: error: parse error before "rx_coalesce_usecs_h 
igh" 
/usr/include/linux/ethtool.h:167: error: parse error before "rx_max_coalesced_fr 
ames_high" 
/usr/include/linux/ethtool.h:168: error: parse error before "tx_coalesce_usecs_h 
igh" 
/usr/include/linux/ethtool.h:169: error: parse error before "tx_max_coalesced_fr 
ames_high" 
/usr/include/linux/ethtool.h:174: error: parse error before "rate_sample_interva 
l" 
/usr/include/linux/ethtool.h:179: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:186: error: parse error before "rx_mini_max_pending 

/usr/include/linux/ethtool.h:187: error: parse error before "rx_jumbo_max_pendin 
g" 
/usr/include/linux/ethtool.h:188: error: parse error before "tx_max_pending" 
/usr/include/linux/ethtool.h:193: error: parse error before "rx_pending" 
/usr/include/linux/ethtool.h:194: error: parse error before "rx_mini_pending" 
/usr/include/linux/ethtool.h:195: error: parse error before "rx_jumbo_pending" 
/usr/include/linux/ethtool.h:196: error: parse error before "tx_pending" 
/usr/include/linux/ethtool.h:201: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:214: error: parse error before "rx_pause" 
/usr/include/linux/ethtool.h:215: error: parse error before "tx_pause" 
/usr/include/linux/ethtool.h:226: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:228: error: parse error before "len" 
/usr/include/linux/ethtool.h:229: error: parse error before "data" 
/usr/include/linux/ethtool.h:230: error: parse error before '}' token 
/usr/include/linux/ethtool.h:239: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:241: error: parse error before "reserved" 
/usr/include/linux/ethtool.h:241: error: conflicting types for 'reserved' 
/usr/include/linux/ethtool.h:29: error: previous declaration of 'reserved' was h 
ere 
/usr/include/linux/ethtool.h:242: error: parse error before "len" 
/usr/include/linux/ethtool.h:243: error: parse error before "data" 
/usr/include/linux/ethtool.h:244: error: parse error before '}' token 
/usr/include/linux/ethtool.h:248: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:250: error: parse error before "data" 
/usr/include/linux/ethtool.h:251: error: parse error before '}' token 
/usr/include/linux/ethtool.h:258: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:260: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:262: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:327: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:330: error: parse error before '*' token 
/usr/include/linux/ethtool.h:330: error: `__u32' declared as function returning 
a function 
/usr/include/linux/ethtool.h:332: error: parse error before "__u8" 
/usr/include/linux/ethtool.h:333: error: parse error before "__u8" 
/usr/include/linux/ethtool.h:340: error: parse error before '*' token 
/usr/include/linux/ethtool.h:340: error: `__u32' declared as function returning 
a function 
/usr/include/linux/ethtool.h:342: error: parse error before '*' token 
/usr/include/linux/ethtool.h:342: error: `__u32' declared as function returning 
a function 
/usr/include/linux/ethtool.h:344: error: parse error before '*' token 
/usr/include/linux/ethtool.h:344: error: `__u32' declared as function returning 
a function 
/usr/include/linux/ethtool.h:346: error: parse error before '*' token 
/usr/include/linux/ethtool.h:346: error: `__u32' declared as function returning 
a function 
/usr/include/linux/ethtool.h:349: error: parse error before "__u64" 
/usr/include/linux/ethtool.h:350: error: parse error before "__u32" 
/usr/include/linux/ethtool.h:353: error: parse error before "__u64" 
/usr/include/linux/ethtool.h:356: error: parse error before '}' token 
 i686-pc-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I. -I../.. -O3 -march=pentium4 -fomi 
t-frame-pointer -fprefetch-loop-arrays -ffast-math -fforce-addr -falign-function 
s=4 -funroll-loops -pipe -MT page_stats.lo -MD -MP -MF .deps/page_stats.Tpo -c p 
age_stats.c  -fPIC -DPIC -o .libs/page_stats.o 
network_stats.c: In function `sg_get_network_iface_stats': 
network_stats.c:634: error: storage size of 'ethcmd' isn't known 
{standard input}: Assembler messages: 
{standard input}:66: Warning: size of "version" is already 32; not changing to 4 
{standard input}:68: Warning: size of "data" is already 4; not changing to 0 
{standard input}:105: Warning: size of "reserved" is already 16; not changing to 
 4 
make[3]: *** [network_stats.lo] Error 1 
make[3]: *** Waiting for unfinished jobs.... 
 i686-pc-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I. -I../.. -O3 -march=pentium4 -fomi 
t-frame-pointer -fprefetch-loop-arrays -ffast-math -fforce-addr -falign-function 
s=4 -funroll-loops -pipe -MT page_stats.lo -MD -MP -MF .deps/page_stats.Tpo -c p 
age_stats.c -o page_stats.o >/dev/null 2>&1 
make[3]: Leaving directory `/var/tmp/portage/libstatgrab-0.11/work/libstatgrab-0 
.11/src/libstatgrab' 
make[2]: *** [all-recursive] Error 1 
make[2]: Leaving directory `/var/tmp/portage/libstatgrab-0.11/work/libstatgrab-0 
.11/src' 
make[1]: *** [all-recursive] Error 1 
make[1]: Leaving directory `/var/tmp/portage/libstatgrab-0.11/work/libstatgrab-0 
.11' 
make: *** [all] Error 2 

!!! ERROR: sys-libs/libstatgrab-0.11 failed. 
!!! Function src_compile, Line 25, Exitcode 2 
!!! emake failed 
!!! If you need support, post the topmost build error, NOT this status message. 


I already tried to emerge an older version and downgrade my CFLAGS, with no success.. 

here is my emerge --info: 
Code:

Portage 2.0.51.19 (default-linux/x86/2004.3, gcc-3.4.3-20050110, glibc-2.3.4.20050125-r1, 2.6.12-rc1 i686) 
================================================================= 
System uname: 2.6.12-rc1 i686 Intel(R) Pentium(R) 4 Mobile CPU 1.80GHz 
Gentoo Base System version 1.6.10 
Python:              dev-lang/python-2.3.5 [2.3.5 (#1, Feb 18 2005, 11:18:24)] 
dev-lang/python:     2.3.5 
sys-devel/autoconf:  2.59-r6, 2.13 
sys-devel/automake:  1.8.5-r3, 1.6.3, 1.9.5, 1.5, 1.7.9-r1, 1.4_p6 
sys-devel/binutils:  2.15.92.0.2-r7 
sys-devel/libtool:   1.5.14 
virtual/os-headers:  2.6.8.1-r4 
ACCEPT_KEYWORDS="x86 ~x86" 
AUTOCLEAN="yes" 
CFLAGS="-O3 -march=pentium4 -fomit-frame-pointer -fprefetch-loop-arrays -ffast-math -fforce-addr -falign-functions=4 -funroll-loops -pipe" 
CHOST="i686-pc-linux-gnu" 
CONFIG_PROTECT="/usr/kde/3.4/env /usr/kde/3.4/share/config /usr/kde/3.4/shutdown /usr/lib/X11/xkb /usr/share/config" 
CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d" 
CXXFLAGS="-O3 -march=pentium4 -fomit-frame-pointer -fprefetch-loop-arrays -ffast-math -fforce-addr -falign-functions=4 -funroll-loops -pipe" 
DISTDIR="/usr/portage/distfiles" 
FEATURES="autoaddcvs autoconfig ccache distlocks sandbox sfperms" 
GENTOO_MIRRORS="ftp://ftp.gentoo.mesh-solutions.com/gentoo/" 
MAKEOPTS="-j2" 
PKGDIR="/usr/portage/packages" 
PORTAGE_TMPDIR="/var/tmp" 
PORTDIR="/usr/portage" 
PORTDIR_OVERLAY="/usr/local/portage" 
SYNC="rsync://rsync.gentoo.org/gentoo-portage" 
USE="x86 16bit 3dnow 3dnowex X acpi acpi4linux alsa arts avi berkdb bitmap-fonts bluetooth ccache cddb cdparanoia cdr chroot clamav codecs crypt cups curl devfs26 divx4linux dvd emboss encode esd fam fbcon font-server foomaticdb fortran gdbm gif gimp gimpprint gnuplot gpm gtk gtk2 icq imagemagick imlib imlib2 insecure-drivers ipv6 irda java jikes jpeg junit lcd libclamav libg++ libwww lirc live mad mikmod mmx mmx2 mmxext motif mozsvg mp3 mpeg mpeg4 mplayer ncurses nls no-old-linux nptl nvidia oav ogg oggvorbis opengl openssh oss pam pcmcia pdf pdflib perl plotutils png pnp python qt quicktime readline samba sdl slang sox speedo spell sse sse2 ssl svga symlink sysfs tcltk tcpd tiff transcode truetype truetype-fonts trusted type1-fonts unicode usb virus-scan wifi xfs xml2 xmms xv xvid zlib" 
Unset:  ASFLAGS, CBUILD, CTARGET, LANG, LC_ALL, LDFLAGS 


Thanks for any help!


阅读(3778) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~