【问题标题】:How to add graphviz library in linux?如何在 linux 中添加 graphviz 库?
【发布时间】:2014-03-16 02:25:15
【问题描述】:

我正在尝试使用点创建图表。但是,它似乎无法识别固定大小等属性。因此,我正在尝试添加 graphviz 库,但我不知道如何使用 .deb 文件并在 C 中使用私有库。这是我的代码,其中固定大小的属性不起作用。我希望节点中的文本被调整,节点大小相同。

digraph test
{
    rankdir = LR;
    "Activity" [shape=circle;fixedsize="true";width=.5;height=.5;fontsize=5];
    "onCreate()" [shape=circle;fixedsize="true";width=.5;height=.5;fontsize=5];
    "Activity" -> "onCreate()"
    "onCreate()" [shape=circle;fixedsize="true";width=.5;height=.5;fontsize=5];
    "onStart()" [shape=circle;fixedsize="true";width=.5;height=.5;fontsize=5];
    "onCreate()" -> "onStart()"
    "onStart()" [shape=circle;fixedsize="true";width=.5;height=.5;fontsize=5];
    "onResume()" [shape=circle;fixedsize="true";width=.5;height=.5;fontsize=5];
    "onStart()" -> "onResume()"
    "Activity" [shape=circle;fixedsize="true";width=.5;height=.5;fontsize=5];
    "Activity Running" [shape=circle;fixedsize="true";width=.5;height=.5;fontsize=5];
    "Activity" -> "Activity Running"
}

【问题讨论】:

    标签: c graphviz dot


    【解决方案1】:

    fixedsize 属性不是这样工作的:

    如果false,则节点的大小由包含其标签所需的最小宽度和高度决定。

    如果true,则节点大小仅由宽度和高度属性的值指定,不会扩展为包含文本标签。如果标签(带边距)不能满足这些限制,则会出现警告

    如果fixedsize属性设置为shape,width和height属性也决定了节点shape的大小,但是label可以大很多。 [...] 如果标签太大,不会发出警告

    永远不会调整文本大小以适应节点,如果文本不适合形状大小,则只会发出警告(通过使用fixedsize=true)。

    您可以解析警告并减小相关节点的字体大小,直到没有警告为止。

    【讨论】:

      【解决方案2】:

      要使用库,您需要在APT system 中安装开发包。Developmet 包,命名如 yourpackage-dev ,对于您的答案,Debian repository 有:graphviz-dev 包裹。 但是当你用额外的库编译时:

      每个图书馆都有一个soname,例如pthread,请考虑以下代码:

      #include <stdio.h>
      #include <stdlib.h>
      #include <pthread.h>
      
      void *print_message_function( void *ptr );
      
      main()
      {
           pthread_t thread1, thread2;
           const char *message1 = "Thread 1";
           const char *message2 = "Thread 2";
           int  iret1, iret2;
      
          /* Create independent threads each of which will execute function */
      
           iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1);
           iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2);
      
           /* Wait till threads are complete before main continues. Unless we  */
           /* wait we run the risk of executing an exit which will terminate   */
           /* the process and all threads before the threads have completed.   */
      
           pthread_join( thread1, NULL);
           pthread_join( thread2, NULL); 
      
           printf("Thread 1 returns: %d\n",iret1);
           printf("Thread 2 returns: %d\n",iret2);
           exit(0);
      }
      
      void *print_message_function( void *ptr )
      {
           char *message;
           message = (char *) ptr;
           printf("%s \n", message);
      }
      

      编译代码:

      mohsen@debian:~$ gcc pthread.c 
      /tmp/cchaTHSA.o: In function `main':
      pthread.c:(.text+0x39): undefined reference to `pthread_create'
      pthread.c:(.text+0x61): undefined reference to `pthread_create'
      pthread.c:(.text+0x79): undefined reference to `pthread_join'
      pthread.c:(.text+0x8d): undefined reference to `pthread_join'
      collect2: error: ld returned 1 exit status
      

      你看到我从链接器得到错误,因为它需要我介绍它pthread 库,例如:

      mohsen@debian:~$ gcc -lpthread pthread.c 
      mohsen@debian:~$ ./a.out 
      Thread 1 
      Thread 2 
      Thread 1 returns: 0
      Thread 2 returns: 0
      mohsen@debian:~$ 
      

      -lLIBRARY_NAME 介绍 gcc 库。

      【讨论】:

      • 我要从 .deb 文件中提取任何内容吗?
      • dpkg -x your_debfile.deb TARGET_DIRECTORY 给定的命令,在你的目标目录中解压你的 deb。
      猜你喜欢
      • 2010-12-20
      • 2012-07-23
      • 2021-02-16
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      相关资源
      最近更新 更多