From: Bob M. <rma...@ee...> - 2007-04-12 12:14:17
|
Why are there "$"s in your swig command? Those usually denote environment variables, which is not what you have there. Also, there's a space between the directory and the filename in the argument to -o, so it may not be recognized as a single argument. Finally, from time to time, I get random errors when building Python stuff from VS. Rebuilding seems to work. Have you tried this from the command line to make sure it will actually work? In my project, the custom build step looks like this: "$(SWIG)\swig.exe" -Wall -c++ -python -modern -I../../ClientSML/include -I../../ElementXML/include -I../../ConnectionSML/include -outdir build "$(InputPath)" SWIG is an user environment variable I set with the location of swig, and InputPath is a VS environment variable with the name of the .i file. Bob Bruno Santos wrote: > I'm trying to convert a function in C to Python using SWIG and > Microsoft Visual Studio 2005. > I already have written the code I need in C (agglomerative.cpp) and > also written the interface file (agglomerative.i). > Then I go to the properties of agglomerative.i, choose custom build > step and change the command line field to: swig -python -o > $"C:\Documents and Settings\Bruno Santos\My Documents\Visual Studio > 2005\Projects\agglomerative\" $agglomerative_wrap.cxx $"C:\Documents > and Settings\Bruno Santos\My Documents\Downloads\swigwin- 1.3.31" > Also change Description to SWIG and output to $C:\Documents and > Settings\Bruno Santos\My Documents\Visual Studio > 2005\Projects\agglomerative\$agglomerative_wrap.cxx > > Then I select the properties of the entire project in C/C++:General > add in include directories "C:\Python25\Lib\site-packages" in > C/C++:Preprocessor add __WIN32__. > But when I try to build the project I get two errors: > Error 1 Could not create output directory 'c:\program > files\microsoft visual studio 8\common7\ide\$c:\documents and > settings\bruno santos\my documents\visual studio > 2005\projects\agglomerative'. agglomerative > Error 2 error PRJ0019: A tool returned an error code from > "SWIG" agglomerative > > Where is my C code: > // agglomerative.cpp : Defines the entry point for the DLL application. > // > > #include "stdafx.h" > > > #ifdef _MANAGED > #pragma managed(push, off) > #endif > > BOOL APIENTRY DllMain( HMODULE hModule, > DWORD ul_reason_for_call, > LPVOID lpReserved > ) > { > return TRUE; > } > > void _stdcall FAR PASCAL calcMatrix(char *input, char *output, int > nNumberClusters) > { > int j; > int i; > int k; > int numCols; > int numRows; > float **dist; > float **x; > char **label; > FILE *ipFile; > > ipFile = fopen(input, "r"); > fscanf(ipFile, "# num rows=%d num columns=%d\n", &numRows, > &numCols ); > > > //Allocate memory > dist = (float**)new float[numRows * sizeof(float *)]; > x = (float**)new float[numRows * sizeof(float *)]; > label = (char**)new char[numRows * sizeof(char *)]; > for (j=0; j<numRows; j++) > { > dist[j]=(float *) new float[numRows * sizeof(float)]; > x[j]=(float*) new float[numCols * sizeof(float)]; > label[j] = (char*) new char[512 * sizeof(char)]; > } > > //Read in label and data points > for (j=0; j<numRows; j++) > { > fscanf(ipFile, "%s ", label[j]); > for (int k=0; k<numCols; k++) fscanf(ipFile, "%f ", &(x[j][k])); > fscanf(ipFile, "\n"); > } > > > i = numRows; > while (i > nNumberClusters) > { > //Calculate distance matrix and minimum > int e; > double min; > int ind[2]; > //printf("numClust=%d", i); > min = 1.0e12; > for (j=0; j<i; j++) > { > for (k=j+1; k<i; k++) > { > dist[j][k]=0; > for (e=0; e<numCols; e++) > dist[j][k]+=(x[j][e]-x[k][e]) * (x[j][e]-x[k][e]); > if (dist[k][j] < min) > { > ind[0]=j; > ind[1]=k; > min=dist[j][k]; > } > } > //Combine > for (e=0; e<numCols; e++) > x[ind[0]][e]=(x[ind[0]][e]+x[ind[1]][e])/2; > i--; > > //Move up remaining vectors > for (k=ind[0]; k<numRows-1; k++) > for (e=0; e<numCols; e++) x[k][e]=x[k+1][e]; > } > } > > //Write centroids to file > FILE *opFile; > opFile = fopen(output, "w"); > > fprintf(opFile, "# num rows=%d num columns=%d\n", nNumberClusters, > numCols); > for (int c=0; c < nNumberClusters; c++) > { > for (int e =0; e < nNumberClusters; e++) > fprintf(opFile, "%f ", x[c][e]); > fprintf(opFile, "\n"); > } > fclose(opFile); > } > > > > #ifdef _MANAGED > #pragma managed(pop) > #endif > > And my interface file: > /* agglomerative.i */ > > %module agglomerative > %{ > #include "stdafx.h" > %} > void calcMatrix(char *input, char *output, int nNumberClusters); > int j; > int i; > int k; > int numCols; > int numRows; > float **dist; > float **x; > char **label; > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > ------------------------------------------------------------------------ > > _______________________________________________ > Swig-user mailing list > Swi...@li... > https://lists.sourceforge.net/lists/listinfo/swig-user > |