Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何执行此DirectFB示例?_C++_G++_Directfb - Fatal编程技术网

C++ 如何执行此DirectFB示例?

C++ 如何执行此DirectFB示例?,c++,g++,directfb,C++,G++,Directfb,我从表单中获得了以下directFB示例代码: 我正在使用DFB1.4.11(我无法更新当前项目)。如何运行此示例?(新手) --更新 更新行后(如@jclin所述): 结果是: $ g++ Test01HorizontalLine.cpp -I /usr/local/include/directfb/ /tmp/cc6iUS1W.o: In function `main': Test01HorizontalLine.cpp:(.text+0x1c): undefined reference t

我从表单中获得了以下directFB示例代码:

我正在使用DFB1.4.11(我无法更新当前项目)。如何运行此示例?(新手)

--更新

更新行后(如@jclin所述):

结果是:

$ g++ Test01HorizontalLine.cpp -I /usr/local/include/directfb/
/tmp/cc6iUS1W.o: In function `main':
Test01HorizontalLine.cpp:(.text+0x1c): undefined reference to `DirectFBInit'
Test01HorizontalLine.cpp:(.text+0x61): undefined reference to `DirectFBErrorFatal'
Test01HorizontalLine.cpp:(.text+0x6d): undefined reference to `DirectFBCreate'
Test01HorizontalLine.cpp:(.text+0xb2): undefined reference to `DirectFBErrorFatal'
Test01HorizontalLine.cpp:(.text+0x111): undefined reference to `DirectFBErrorFatal'
Test01HorizontalLine.cpp:(.text+0x188): undefined reference to `DirectFBErrorFatal'
Test01HorizontalLine.cpp:(.text+0x1ef): undefined reference to `DirectFBErrorFatal'
Test01HorizontalLine.cpp:(.text+0x26d): undefined reference to `DirectFBErrorFatal'
/tmp/cc6iUS1W.o:Test01HorizontalLine.cpp:(.text+0x2e4): more undefined references to `DirectFBErrorFatal' follow
collect2: ld returned 1 exit status

你能试试这个吗,因为我现在没有这样的版本

dsc.caps = DFBSurfaceCapabilities(DSCAPS_PRIMARY | DSCAPS_FLIPPING);  
...  
primary->Flip(primary, NULL, DFBSurfaceFlipFlags(0));  

以下代码适用于我的测试ubuntu12,我可能与您有不同的directfb,但应该是类似的:

#include <stdio.h>
#include <unistd.h>

#include <directfb/directfb.h>

static IDirectFB *dfb = NULL;
static IDirectFBSurface *primary = NULL;
static int screen_width = 0;
static int screen_height = 0;
#define DFBCHECK(x...)                                         \
  {                                                            \
    DFBResult err = x;                                         \
                                                               \
    if (err != DFB_OK)                                         \
      {                                                        \
        fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
        DirectFBErrorFatal( #x, err );                         \
      }                                                        \
  }
int main(int argc, char **argv) {

    DFBSurfaceDescription dsc;
    DFBCHECK(DirectFBInit (&argc, &argv));
    DFBCHECK(DirectFBCreate (&dfb));
    DFBCHECK(dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
    dsc.flags = DSDESC_CAPS;
    dsc.caps = DFBSurfaceCapabilities(DSCAPS_PRIMARY | DSCAPS_FLIPPING);
    DFBCHECK(dfb->CreateSurface( dfb, &dsc, &primary ));
    DFBCHECK(primary->GetSize (primary, &screen_width, &screen_height));
    DFBCHECK(primary->FillRectangle (primary, 0, 0, screen_width, screen_height));
    DFBCHECK(primary->SetColor (primary, 0x80, 0x80, 0xff, 0xff));
    DFBCHECK(primary->DrawLine (primary, 0, screen_height / 2, screen_width - 1, screen_height / 2));
    primary->Flip(primary, NULL, DFBSurfaceFlipFlags(0));
    sleep(5);
    primary->Release(primary);
    dfb->Release(dfb);
    return 23;
}
要查找libdirectfb.so所在的位置,可以使用linux
find
命令,然后将
-L
选项添加到g++命令以包含库路径,并添加
-ldirectfb
以链接libdirectfb.so文件

$ find /usr/lib -name libdirectfb.so   
运行TestLine输出:

   ~~~~~~~~~~~~~~~~~~~~~~~~~~| DirectFB 1.2.10 |~~~~~~~~~~~~~~~~~~~~~~~~~~
        (c) 2001-2008  The world wide DirectFB Open Source Community
        (c) 2000-2004  Convergence (integrated media) GmbH
      ----------------------------------------------------------------

(*) DirectFB/Core: Single Application Core. (2012-05-21 06:43)
(!) Direct/Util: opening '/dev/fb0' failed
    --> Permission denied
(!) DirectFB/FBDev: Error opening framebuffer device!
(!) DirectFB/FBDev: Use 'fbdev' option or set FRAMEBUFFER environment variable.
(!) DirectFB/Core: Could not initialize 'system_core' core!
    --> Initialization error!
Test01HorizontalLine.cpp <24>:
        (#) DirectFBError [DirectFBCreate (&dfb)]: Initialization error!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DirectFB 1.2.10|~~~~~~~~~~~~~~~~~~~~~~~~~~
(c) 2001-2008全球DirectFB开源社区
(c) 2000-2004 Convergence(集成媒体)有限公司
----------------------------------------------------------------
(*)DirectFB/Core:单应用程序核心。(2012-05-21 06:43)
(!)Direct/Util:打开“/dev/fb0”失败
-->拒绝许可
(!)DirectFB/FBDev:打开帧缓冲区设备时出错!
(!)DirectFB/FBDev:使用“FBDev”选项或设置帧缓冲区环境变量。
(!)DirectFB/Core:无法初始化“system_Core”Core!
-->初始化错误!
Test01HorizontalLine.cpp:
(#)DirectFBError[DirectFBCreate(&dfb)]:初始化错误!

如果您在项目中使用库,那么包含标题仅是工作的一半。您还必须显示实际库(libdirectfb.so在您的示例中)的位置,以便它可以链接到您的代码。通过传递-L-L选项来实现这一点(同时请注意既不需要前缀lib-也不需要extension.so):

有很多关于如何在项目中使用库的主题,例如,您可能希望开始并完成项目


另外,最好使用-Wall选项查看更多有关正在发生的事情的信息。

谢谢您的提示!现在看来问题变了。。。请参阅我的更新。是否指定了GCC的链接路径和库-ldirectfb-L/路径到\u directfb\u lib/谢谢!(奖励@KBart完整的编译行)感谢完整的编译行(太多的东西要包括…)
#include <stdio.h>
#include <unistd.h>

#include <directfb/directfb.h>

static IDirectFB *dfb = NULL;
static IDirectFBSurface *primary = NULL;
static int screen_width = 0;
static int screen_height = 0;
#define DFBCHECK(x...)                                         \
  {                                                            \
    DFBResult err = x;                                         \
                                                               \
    if (err != DFB_OK)                                         \
      {                                                        \
        fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
        DirectFBErrorFatal( #x, err );                         \
      }                                                        \
  }
int main(int argc, char **argv) {

    DFBSurfaceDescription dsc;
    DFBCHECK(DirectFBInit (&argc, &argv));
    DFBCHECK(DirectFBCreate (&dfb));
    DFBCHECK(dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN));
    dsc.flags = DSDESC_CAPS;
    dsc.caps = DFBSurfaceCapabilities(DSCAPS_PRIMARY | DSCAPS_FLIPPING);
    DFBCHECK(dfb->CreateSurface( dfb, &dsc, &primary ));
    DFBCHECK(primary->GetSize (primary, &screen_width, &screen_height));
    DFBCHECK(primary->FillRectangle (primary, 0, 0, screen_width, screen_height));
    DFBCHECK(primary->SetColor (primary, 0x80, 0x80, 0xff, 0xff));
    DFBCHECK(primary->DrawLine (primary, 0, screen_height / 2, screen_width - 1, screen_height / 2));
    primary->Flip(primary, NULL, DFBSurfaceFlipFlags(0));
    sleep(5);
    primary->Release(primary);
    dfb->Release(dfb);
    return 23;
}
 g++ -o testHorizonLine  Test01HorizontalLine.cpp -I/usr/include \
 -I/usr/include/directfb -L/usr/lib/i386-linux-gnu -ldirectfb
$ find /usr/lib -name libdirectfb.so   
   ~~~~~~~~~~~~~~~~~~~~~~~~~~| DirectFB 1.2.10 |~~~~~~~~~~~~~~~~~~~~~~~~~~
        (c) 2001-2008  The world wide DirectFB Open Source Community
        (c) 2000-2004  Convergence (integrated media) GmbH
      ----------------------------------------------------------------

(*) DirectFB/Core: Single Application Core. (2012-05-21 06:43)
(!) Direct/Util: opening '/dev/fb0' failed
    --> Permission denied
(!) DirectFB/FBDev: Error opening framebuffer device!
(!) DirectFB/FBDev: Use 'fbdev' option or set FRAMEBUFFER environment variable.
(!) DirectFB/Core: Could not initialize 'system_core' core!
    --> Initialization error!
Test01HorizontalLine.cpp <24>:
        (#) DirectFBError [DirectFBCreate (&dfb)]: Initialization error!
g++ your_source_file.cpp -I /path/to/include -L/path/to/lib -ldirectfb