I'm trying to use graphviz as a library for a C++ project, following the libguide provided here. However I'm having problems even compiling the examples in the appendix. When I try to compile demo.c using gcc I get the following output:
$ gcc -I/usr/local/Cellar/graphviz/2.28.0/include/ demo.c -L/usr/local/Cellar/graphviz/2.28.0/lib/ -lgvc -lgraph -lcdt
demo.c: In function ‘main’:
demo.c:14: error: ‘Agdirected’ undeclared (first use in this function)
demo.c:14: error: (Each undeclared identifier is reported only once
demo.c:14: error: for each function it appears in.)
demo.c:15: error: too many arguments to function ‘agnode’
demo.c:16: error: too many arguments to function ‘agnode’
demo.c:17: error: too many arguments to function ‘agedge’
Agdirected is found in cgraph.h, but if I change the includes in demo.c to
#include <graphviz/gvc.h>
#include <graphviz/cgraph.h>
Then all hell breaks loose (mostly conflicting declarations between the two headers). How can I include the necessary headers without the headache of all these conflicts?
Mac OS X 10.8.3, Graphviz 2.28.0, GCC 4.2.1
It seems after some experimentation that adding the flag
#define WITH_CGRAPH
has the effect of including cgraph.h, which gets rid of the "'Agdirected' undeclared" error.
The other errors can be fixed by changing the command line option in gcc from -lgraph to -lcgraph
The libguide you are using is the cgraph version, which assumes Graphviz 2.30 or later. With that version, the #define WITH_CGRAPH is already provided.
Related
I am creating many threads and each one should output a random number.
I know that srand() with rand is not thread-safe and indeed all the output numbers are the same.
So I tried to use rand_r but I get the following error on my Windows terminal
main.c:47:16: warning: implicit declaration of function 'rand_r'; did you mean 'rand'? [-Wimplicit-function-declaration]
result= ( (rand_r(&seed) % (high+1-low) ) + low);
^~~~~~
rand
main.c: In function 'customerServe':
main.c:333:1: warning: control reaches end of non-void function [-Wreturn-type]
}
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe:
C:\Users\allys\AppData\Local\Temp\ccSslADA.o:main.c:(.text+0xe): undefined
reference to `rand_r'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe:
C:\Users\allys\AppData\Local\Temp\ccSslADA.o:main.c:(.text+0x41c):
undefined reference to `rand_r'
collect2.exe: error: ld returned 1 exit status
Thank you
I saw from the post tags that you are using the "pthreads" library which stands for POSIX threads. Therefore this project cannot be run on Windows since it does not support the "lpthread" flag on your system.
If you insist on working on a Windows machine, you could use something like this which lets the developer work on an Ubuntu terminal from windows. While having access to an Ubuntu-like system where the lpthreads library is supported, you can move on with your project. Another possible solution could be using docker to compile & run your project on an isolated ubuntu environment but this is kind of an overkill.
Let me know if this helped!
I needed to specify a late enough Posix source to avoid this warning, e.g.:
gcc -Wall -std=c11 -D_POSIX_C_SOURCE=199506L pi.c -o pi -lm -lpthread
I am trying to detect an error so I included in my program some traces.
The problem is that after that, it doesn't compile, giving me next error:
../src/DR700_API.c:46: parse error before `*'
I just added an fprintf at the beginning of each function:
fprintf(stdout,"_name_of_function_");
Commenting all fprintf it compiles right, so there's the error. I can't dispense with them as i want to track other error in execution time.
Here's a little example:
#include <stdio.h>
#include <stdlib.h>
ImprFunc *DR700_new()
{
fprintf(stdout,"DR700_new");
ImprFunc *impr = (ImprFunc *)malloc(sizeof(DR700_ImprFunc));
if (impr == NULL)
return NULL;
...
../src/DR700_API.c:46: parse error before `*'
../src/DR700_API.c:47: `impr' undeclared (first use in this function)
../src/DR700_API.c:47: (Each undeclared identifier is reported only once
../src/DR700_API.c:47: for each function it appears in.)
make: *** [../obj/DR700_API.o] Error 1
Probably your setup doesn't allow mixed code and declarations (as per C89). If you wish to not affect project setup - try to keep declarations before any code. In your example it means
ImprFunc *impr = (ImprFunc *)malloc(sizeof(DR700_ImprFunc));
fprintf(stdout,"DR700_new");
instead of
fprintf(stdout,"DR700_new");
ImprFunc *impr = (ImprFunc *)malloc(sizeof(DR700_ImprFunc));
Or alternatively - add -std=c99 (as was mentioned in comments).
In early versions of C, variables had to be declared at the beginning of a block.
C99 allows to mix declarations and statements arbitrarily (e.g. see Variable declaration placement in C and Where can I legally declare a variable in C99?).
You could try compiling with --std=c99 / --std=c11 which will allow you to declare variables anywhere (if supported in your version of gcc. See Status of C99 features in GCC and C11Status).
C99 is, for the most part, backward compatible with C89.
I am running Linux Mint. When I try to compile a program in C using gpp from command line, I get this output, and my program does not compile.
$ gpp snake.cpp -o snake
features.h:384: warning: Extra argument to #endif ignored
features.h:396: error: #define/#defeval requires an identifier or a single macro call
I'm not sure why I would ever be getting an error for a standard library that I haven't even touched.
I'm trying to use the original som implementation by Kohonen but I'm getting a segmentation fault error using vcal.
It turns out that you can use an unofficial version which corrects this error found at
http://cis.legacy.ics.tkk.fi/hynde/lvq/
but its from 1997, i'm sure that there are a lot of changes in cc compiler so I'm getting this error
checo#canija:~/bin/som/som_pak-3.2$ make
gcc -O2 -c -o vcal.o vcal.c
In file included from datafile.h:28,
from vcal.c:26:
fileio.h:69: error: conflicting types for ‘getline’
/usr/include/stdio.h:651: note: previous declaration of ‘getline’ was here
make: *** [vcal.o] Error 1
checo#canija:~/bin/som/som_pak-3.2$
The file datafile.h
1:#ifndef SOMPAK_DATAFILE_H
2:#define SOMPAK_DATAFILE_H
...
24:#include
25:#include
26:#include "lvq_pak.h"
27:#include "errors.h"
28:#include "fileio.h"
Is there anything I can do to recomple this code?
Converting a comment to an answer to allow the question to be resolved.
getline() is now a POSIX function; it wasn't in 1997. Your best bet may be to rename the function in fileio.h and where it is used, maybe as simply as adding before the appearance of getline and after the #include <stdio.h>.
#undef getline
#define getline(a, b, c) som_getline(a, b, c)
Use the right number of parameters, or
#define getline(...) som_getline(__VA_ARGS__)
If <stdio.h> is not yet included, then add it to ensure that getline() is declared normally, then mapped by your macro.
Here's a simple example:
#include <stdlib.h>
int main(void) {
_set_error_mode(_OUT_TO_STDERR);
return EXIT_SUCCESS;
}
When compiling this program, I get the following problems:
main.c: In function 'main':
main.c:4: error: implicit declaration of function '_set_error_mode'
main.c:4: error: '_OUT_TO_STDERR' undeclared (first use in this function)
main.c:4: error: (Each undeclared identifier is reported only once
main.c:4: error: for each function it appears in.)
The header does contain the function declaration and the macro:
_CRTIMP int __cdecl __MINGW_NOTHROW _set_error_mode (int);
# define _OUT_TO_STDERR 1
How come I get the errors? Notice that I also used the EXIT_SUCCESS macro which is also defined in the same stdlib.h header but for some reason GCC doesn't complain about it. Odd.
I'm using MinGW + GCC on a Vista machine.
Your code snippet works fine for me with MinGW 3.4.5
Are you sure you have your include file path set correctly? Maybe the wrong stdlib.h is being processed. Alternatively, maybe MingGW isn't defining __MSVCRT__ which is necessary to get that function prototype (MinGW seems to define that automatically for me - I'm not sure how one would turn it off).
edit:
tyranid's comment seems to have the answer - if I specify the -ansi option, I get the exact same set of errors as in your example.
Setting to CW and will delete if tyranid posts an answer.