简体   繁体   中英

How to add graphviz library in linux?

I am trying to create a graph using dot. However, it seems to not recognize attributes like fixed size. Hence, I am trying to add the graphviz library, but I do not know how to use the .deb file and use private libraries in C. here is my code, where the fixedsize attributes is not working. I want the text in the nodes to be adjusted and the node size to be the same.

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"
}

That's not how the fixedsize attribute works:

If false , the size of a node is determined by smallest width and height needed to contain its label.

If true , the node size is specified by the values of the width and height attributes only and is not expanded to contain the text label. There will be a warning if the label (with margin) cannot fit within these limits.

If the fixedsize attribute is set to shape , the width and height attributes also determine the size of the node shape, but the label can be much larger. [...] No warning is given if the label is too large.

The text size will never be adjusted to fit within the node, only warnings can be emitted (by using fixedsize=true ) if the text doesn't fit the shape size.

You may parse the warnings and reduce the font size of the concerned nodes until there are no warnings left.

For using library, you need install development package.Developmet packages in APT system , naming such as yourpackage-dev , for your answer, Debian repository has: graphviz-dev package. But When you compile with extra library:

Every plibrary has a soname such as pthread , Please condider the following code:

#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);
}

Compile code :

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

You see i got error from linker because it need i introduce it pthread library such as:

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 introduve to gcc a library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM