Compilerfehler für eigentlich funktionierendes Programm
-
Okay, der Titel mag etwas unglücklich gewählt sein, aber mir fällt ehrlich gesagt nichts besseres ein
Ich habe ein Problem mit einem Programm das eigentlich schon veraltet und für 32bit Systeme geschrieben ist, welches ich aber nun auf einem 64bit System benötige.
Wenn ich aber nun versuche es zu kompilieren, erhalte ich folgenden Fehler:
rayserver.c:19: error: expected identifier or '(' before string constant rayserver.c:34: error: expected identifier or '(' before string constant rayserver.c:58: error: expected identifier or '(' before string constant rayserver.c:81: error: expected identifier or '(' before string constant rayserver.c:108: error: expected identifier or '(' before string constant rayserver.c:128: error: expected identifier or '(' before string constant
Hier ist der Sourcecode:
(Notiz: Der Code ist NICHT von mir! Ich habe ihn aus dem "Siggraph 99 Kurs", den man hier downloaden kann: http://www.renderman.org/RMR/Publications/index.html Aus dem Kapitel "Ray Tracing with PRMan*" im Anhang)/* rayserver.c – implements the rayserver protocol -- client side. * When one of the rayserver functions is called, open a pipe to a ray server * program, and transmit queries using a rayserver protocol. * * Compile me like this (on SGI): * cc –c rayserver.c * ld –shared –o rayserver.so rayserver.o */ #include <stdio.h> #include <malloc.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <alloca.h> #include <shadeop.h> SHADEOP_TABLE(rayserver) = { { "color rayserver_trace (point, vector)", "rayserver_init", "rayserver_cleanup" }, { "color rayserver_visibility (point, point)", "rayserver_init", "rayserver_cleanup" }, { "float rayserver_rayhittest (point, vector, point, vector)", "rayserver_init", "rayserver_cleanup" }, { "" } }; typedef struct { int initialized; FILE *in; int pipe[2]; } RS_DATA; static RS_DATA rs_data = { 0 } ; SHADEOP (rayserver_trace) { float *result = (float *)argv[0]; float *pos = (float *)argv[1]; float *dir = (float *)argv[2]; char buf[256]; float fbuf[16]; if (! rs_data.initialized) { result[0] = 0; result[1] = 0; result[2] = 0; return 0; } memset (fbuf, 0, 12*sizeof(float)); buf[0] = 'b'; buf[1] = 't'; write (rs_data.pipe[1], buf, 2); memcpy (fbuf, pos, 3*sizeof(float)); memcpy (fbuf+3, dir, 3*sizeof(float)); fbuf[6] = 0.0f; /* time */ fbuf[7] = 0.5f; /* detail */ /* 8-11 are reserved */ write (rs_data.pipe[1], fbuf, 12*sizeof(float)); read (rs_data.pipe[0], result, 3*sizeof(float)); read (rs_data.pipe[0], fbuf, sizeof(float)); return 0; } SHADEOP (rayserver_visibility) { float *result = (float *)argv[0]; float *pos0 = (float *)argv[1]; float *pos1 = (float *)argv[2]; char buf[256]; float fbuf[16]; if (! rs_data.initialized) { result[0] = 0; result[1] = 0; result[2] = 0; return 0; } memset (fbuf, 0, 12*sizeof(float)); buf[0] = 'b'; buf[1] = 'v'; write (rs_data.pipe[1], buf, 2); memcpy (fbuf, pos0, 3*sizeof(float)); memcpy (fbuf+3, pos1, 3*sizeof(float)); fbuf[6] = 0.0f; /* time */ fbuf[7] = 0.5f; /* detail */ /* 8-11 are reserved */ write (rs_data.pipe[1], fbuf, 12*sizeof(float)); read (rs_data.pipe[0], result, 3*sizeof(float)); return 0; } SHADEOP (rayserver_rayhittest) { float *result = (float *)argv[0]; float *pos = (float *)argv[1]; float *dir = (float *)argv[2]; float *Phit = (float *)argv[3]; float *Nhit = (float *)argv[4]; char buf[256]; float fbuf[12]; if (! rs_data.initialized) { result[0] = 0; result[1] = 0; result[2] = 0; return 0; } memset (fbuf, 0, 12*sizeof(float)); buf[0] = 'b'; buf[1] = 'h'; write (rs_data.pipe[1], buf, 2); memcpy (fbuf, pos, 3*sizeof(float)); memcpy (fbuf+3, dir, 3*sizeof(float)); fbuf[6] = 0.0f; /* time */ fbuf[7] = 0.5f; /* detail */ /* 8-11 are reserved */ write (rs_data.pipe[1], fbuf, 12*sizeof(float)); read (rs_data.pipe[0], result, 1*sizeof(float)); read (rs_data.pipe[0], Phit, 3*sizeof(float)); read (rs_data.pipe[0], Nhit, 3*sizeof(float)); return 0; } SHADEOP_INIT (rayserver_init) { int popen2(char *, int[2]); char *servername; int len, i; if (rs_data.initialized) return NULL; servername = getenv ("RAYSERVER"); if (! servername) return NULL; /* Could not find name of server */ len = strlen (servername) + 2; if (popen2 (servername, rs_data.pipe)) { fprintf (stderr, "Error opening pipe to \"%s\"\n", servername); return NULL; /* Could not open pipe */ } rs_data.in = fdopen (rs_data.pipe[0], "r"); setlinebuf (rs_data.in); rs_data.initialized = 1; return NULL; } SHADEOP_CLEANUP (rayserver_cleanup) { if (rs_data.initialized) { close (rs_data.pipe[0]); close (rs_data.pipe[1]); rs_data.initialized = 0; } } static void sig_pipe (int signo) { fprintf (stderr, "SIGPIPE caught\n"); exit(1); } static int popen2 (char *cmd, int fd[2]) { int fd1[2], fd2[2], pid; if (signal(SIGPIPE, sig_pipe) == SIG_ERR) { fprintf (stderr, "signal error\n"); return -1; } if (pipe(fd1) < 0 || pipe(fd2) < 0) { fprintf (stderr, "pipe error\n"); return -1; } if ((pid = fork()) < 0) { fprintf (stderr, "fork error\n"); return -1; } else if (pid > 0) { /* Parent */ close (fd1[0]); close (fd2[1]); fd[0] = fd2[0]; fd[1] = fd1[1]; sleep (1); return 0; } else { /* Child */ char *argv[100]; int i, a; char *command = alloca(strlen(cmd)+2); strcpy (command, cmd); a = 0; cmd = command; argv[a++] = cmd; while (*cmd && *cmd != ' ') ++cmd; if (*cmd) *cmd++ = 0; while (*cmd) { while (*cmd == ' ') ++cmd; argv[a++] = cmd; while (*cmd && *cmd != ' ') ++cmd; if (*cmd) *cmd++ = 0; } argv[a] = NULL; close (fd1[1]); close (fd2[0]); if (fd1[0] != STDIN_FILENO) { if (dup2(fd1[0], STDIN_FILENO) != STDIN_FILENO) { fprintf (stderr, "dup2 error to stdin\n"); close (fd1[0]); } } if (fd2[1] != STDOUT_FILENO) { if (dup2(fd2[1], STDOUT_FILENO) != STDOUT_FILENO) { fprintf (stderr, "dup2 error to stdout\n"); close (fd2[1]); } } if (execvp (command, argv) < 0) { fprintf (stderr, "execl error\n"); return -1; } } return 0; }
von dem was ich bisher herausgefunden habe, könnte es an den include files liegen, ist das korrekt?
Ich bin kein Programmierer, und habe sonst auch nichts gefunden was mir weiter helfen könnte, deshalb frage ich nun hier.
MfG Rinne
PS: GCC Version 4.3.3 64bit Gentoo 2.6.27 kernel
-
das liegt scheinbar am macro oder dessen benutzung,
wie sieht z.b. das macro SHADEOP_TABLE aus ?
-
hier sieht die benutzung etwas anders aus:
http://www.renderpixie.com/pixiewiki/Documentation/DSO_shadingwo hast du den code runtergeladen?
-
Danke macro n00b,
den Sourcecode habe ich aus dem oben genannten Dokument kopiert.
Hier nochmal der direkte Link zum Dokument:
http://www.renderman.org/RMR/Publications/sig99.course25.pdfIch hoffe ja ich schädige hier keine Urheberrechte..
Allein die Frage wie die Shadeop.h denn aussieht hat mich schonmal weiter gebracht.
Es wurde nämlich scheinbar gar keine, oder eine falsche shadeop.h gefunden.
Ich habe jetzt die shadeop.h von dem Programm mit dem ich dieses Programm hier benutzen will verlinkt.
Die Fehlermeldungen sind jetzt weg, allerdings zwei neue aufgetaucht:
rayserver.c:141: error: static declaration of 'popen2' follows non-static declaration rayserver.c:110: error: previous declaration of 'popen2' was here
-
vermutlich muss das ganze einheitlich sein, entweder beides static oder beides nicht static.
ich tippe aufs erste.
-
Hmm okay, wenn ich's static weg lasse funktionierts..
Danke nochmal
jetzt läufts