首页 > 解决方案 > 使用 vlc 库示例时函数“睡眠”的隐式声明

问题描述

我正在测试 vlc 库,以便能够制作 mp3 播放器。我找到了这个例子:

#include <stdio.h>
 #include <stdlib.h>
 #include <vlc/vlc.h>
 
 int main(int argc, char* argv[])
 {
     libvlc_instance_t * inst;
     libvlc_media_player_t *mp;
     libvlc_media_t *m;
     
     /* Load the VLC engine */
     inst = libvlc_new (0, NULL);
  
     /* Create a new item */
     m = libvlc_media_new_location (inst, "http://mycool.movie.com/test.mov");
     //m = libvlc_media_new_path (inst, "/path/to/test.mov");
        
     /* Create a media player playing environement */
     mp = libvlc_media_player_new_from_media (m);
     
     /* No need to keep the media now */
     libvlc_media_release (m);
 
 #if 0
     /* This is a non working code that show how to hooks into a window,
      * if we have a window around */
      libvlc_media_player_set_xwindow (mp, xid);
     /* or on windows */
      libvlc_media_player_set_hwnd (mp, hwnd);
     /* or on mac os */
      libvlc_media_player_set_nsobject (mp, view);
  #endif
 
     /* play the media_player */
     libvlc_media_player_play (mp);
    
     sleep (10); /* Let it play a bit */
    
     /* Stop playing */
     libvlc_media_player_stop (mp);
 
     /* Free the media_player */
     libvlc_media_player_release (mp);
 
     libvlc_release (inst);
 
     return 0;
 }

我在编译时遇到的问题如下:

test.c: In function ‘main’:
test.c:37:6: warning: implicit declaration of function ‘sleep’ [-Wimplicit-function-declaration]
   37 |      sleep (10); /* Let it play a bit */

我尝试包含 time.h 库,但问题没有解决。有谁知道会发生什么?如果您可以向我推荐一些东西或者您有一些信息,vlclib 示例将不胜感激。或者如果您推荐任何其他书店,它也对我有用。谢谢

标签: cmp3libvlc

解决方案


POSIX sleep在header中声明unistd.h,您需要包含它。


推荐阅读