Hi All, I've written a simple C program that executes linux shell commands and returns an output. I export the C program to library and use it in C# project.
Following is the code that works on windows #include <stdio.h> #include "libserverusage.h" #define DllExport __declspec( dllexport ) DllExport int GetServerUsage() { int usage = 1; #if LINUX FILE * fp; char buf[1024]; int n = 0; char * cmd = "vmstat | gawk '/0/ {tot=tot+1; id=id+$16} END {print 100 - id/tot}'"; fp = popen(cmd,"r"); n = fread(buf,1,sizeof(buf),fp); buf[n] = '\0'; /* printf("%s\n", buf); printf("Characters read: %d\n\n", n); */ fclose(fp); usage = atoi(buf); #endif return usage; } But when i try to compile it on linux, i get these errors: libserverusage.c: In function `__declspec': libserverusage.c:33: error: parse error before '{' token libserverusage.c:39: error: parameter `n' is initialized libserverusage.c:40: error: parameter `cmd' is initialized libserverusage.c:41: error: parse error before "fp" libserverusage.c:40: error: declaration for parameter `cmd' but no such parameter libserverusage.c:39: error: declaration for parameter `n' but no such parameter libserverusage.c:38: error: declaration for parameter `buf' but no such parameter libserverusage.c:37: error: declaration for parameter `fp' but no such parameter libserverusage.c:33: error: declaration for parameter `GetServerUsage' but no such parameter BTW the code compiles with gcc compiler, if i copy the contents of this function to main method. This is how i compile my code: gcc -DLINUX -shared -fPIC -Wall -O2 libserverusage.c -o ../bin/Release/libserverusage.so Can someone help me fix this? Thanks, Romy -- View this message in context: http://www.nabble.com/Help+with+using+%60__declspec%27-t1711609.html#a4647258 Sent from the gcc - Gnu Help List forum at Nabble.com. _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus