【问题标题】:liboss static declaration of ‘ioctl’ follows non-static declaration“ioctl”的 liboss 静态声明遵循非静态声明
【发布时间】:2012-11-27 23:13:10
【问题描述】:

我正在尝试编译一个包含 libboss 文件的程序,但是当我编译时出现以下错误。

In file included from test.c:1:
/opt/local/include/liboss/soundcard.h:342: error: static declaration of ‘ioctl’ follows non-static declaration
/usr/include/sys/ioctl.h:97: error: previous declaration of ‘ioctl’ was here
/opt/local/include/liboss/soundcard.h:353: error: static declaration of ‘open’ follows non-static declaration
/usr/include/sys/fcntl.h:464: error: previous declaration of ‘open’ was here
/opt/local/include/liboss/soundcard.h:363: error: static declaration of ‘close’ follows non-static declaration
/usr/include/unistd.h:476: error: previous declaration of ‘close’ was here
/opt/local/include/liboss/soundcard.h:366: error: conflicting types for ‘write’
/usr/include/unistd.h:535: error: previous declaration of ‘write’ was here

第一个错误发生的行就是这个。

@声卡.h

static inline int LIBOSS_IOCTL (int x, unsigned long y,...)
{
    int result;

    va_list l;
    va_start(l,y);
    result = liboss_ioctl(x,y,l);
    va_end (l);
    return result;
}

@ioctl.h

__BEGIN_DECLS
int ioctl(int, unsigned long, ...);
__END_DECLS

有什么方法可以给 soundcard.h 打猴子补丁,这样就不会出现问题了?

谢谢! A.

规格:Mac OSX 10.7.4,gcc i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1

【问题讨论】:

    标签: c macos gcc compilation compiler-errors


    【解决方案1】:

    听起来liboss 试图通过重新定义ioctl 函数来提供OSS ioctl 操作,而内核不支持它们,从而在非本机系统上提供与oss 兼容的声卡接口。如果是这种情况,您需要确保sys/ioctl.h(或任何可能包含它的标头)不会包含在使用soundcard.h 的相同源文件中。

    【讨论】:

    • 试过了,现在它只跳到以下错误(见问题)。在 soundcard.h 的下方有一个 #undef 指令。那不就行了吗?为什么它不起作用?
    【解决方案2】:

    只需将static 添加到/usr/include/sys/ioctl.h:97/usr/include/sys/fcntl.h:464/usr/include/unistd.h:476/usr/include/unistd.h:535(并在编译后再次撤消这些更改)。

    /opt/local/include/liboss/soundcard.h:366 中,将int 替换为ssize_t

    # add static
    sudo nano +97 /usr/include/sys/ioctl.h
    - int  ioctl(int, unsigned long, ...);
    + static int  ioctl(int, unsigned long, ...);
    
    # replace int by ssize_t
    sudo nano +366 /opt/local/include/liboss/soundcard.h
    - static inline int LIBOSS_WRITE (int x, const void *y, size_t l)
    + static inline ssize_t LIBOSS_WRITE (int x, const void *y, size_t l)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      • 2018-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多