Importing C source files
BlitzMax Forums/BlitzMax Programming/Importing C source files
| ||
Hi. I was wondering if someone had a nice tutorial/walkthrough on how to import c source files in BlitzMax.. I've tried the very simple "Doubler" example which is listed in the help file (under Language -> Advanced topics), but I can't seem to get it to work... I get this error reported: Building main Compiling:c_func.c C:/Documents and Settings/Lars/Mine dokumenter/programmering/test prosjekter/importere_C_kilde/c_func.c:4: error: syntax error before "Doubler" C:/Documents and Settings/Lars/Mine dokumenter/programmering/test prosjekter/importere_C_kilde/c_func.c:4: error: syntax error before "x" C:/Documents and Settings/Lars/Mine dokumenter/programmering/test prosjekter/importere_C_kilde/c_func.c: In function `Doubler': C:/Documents and Settings/Lars/Mine dokumenter/programmering/test prosjekter/importere_C_kilde/c_func.c:5: error: `Return' undeclared (first use in this function) C:/Documents and Settings/Lars/Mine dokumenter/programmering/test prosjekter/importere_C_kilde/c_func.c:5: error: (Each undeclared identifier is reported only once C:/Documents and Settings/Lars/Mine dokumenter/programmering/test prosjekter/importere_C_kilde/c_func.c:5: error: for each function it appears in.) C:/Documents and Settings/Lars/Mine dokumenter/programmering/test prosjekter/importere_C_kilde/c_func.c:5: error: syntax error before "x" Process complete I must be doing something wrong... :/ |
| ||
remember that c is casesensitive. for example it seems that you have typed Return x+xinstead of return x+x just a guess, but did you also type Int instead of int? |
| ||
works fine for me. create a test folder. put a file doubler.bmx in the folder containing the following: Import "c_funcs.c" Extern Function Doubler( x ) End Extern Print doubler(10) create a file called c_funcs.c in the same folder that contains: //----- file: c_funcs.c ----- int Doubler( int x ){ return x+x; } (ensure there is a newline at the end of the file) compile and run doubler.bmx |
| ||
*EDIT* beaten to the post |
| ||
@Perturbatio ;p @LarsG You can of course type Int if you want, but only if you first define Int to be a synonym for int. typedef int Int; The cool thing about using typedef is that you can easily switch between two types. typedef float Scalar; //typedef double Scalar; By just commenting the first line and uncomment the second, all code that use the Scalar type use a double instead of a float. |
| ||
wow.. thanks guys.. it worked... :p I never knew that c was case sensitive... (cursed compiler :p) it seems that since I pasted/wrote the .c file in the BMax editor, it went ahead and case'd the keywords (Int and Return) I think it's should be mentioned this in the help file and/or here on the forum... anyways.. thanks again for the help.. sidenote: coming to think of it, wouldn't it be nice to have a choice in the IDE, which cases the keywords C style or BMax style...??? |
| ||
Do you need to have any extrenal compilers paths set for this to work? I get: Building app Compiling:c_funcs.c Process complete but the program dosent execute? |
| ||
yeah you need MinW setup and paths set to mingw's base/bin and include folders. |
| ||
OK spent 10 min hunting! Where Do you find MinW? And what do you do with it? |
| ||
You have two options. A) Install it B) Go on jerry springer and marry it. If you've decide on route A, download this http://prdownloads.sf.net/mingw/MinGW-4.1.0.exe?download Then..well, I wish I had the exacts paths to hand myself, but I don't on this install of windows. but I *think* it's-> SYstem props, enviromental settings. Add path 'Set path = C:mingw\" then add two more for "C:Mingw\Include" and C:MingW\Include. |
| ||
Downloaded and installed. All OK! System Properties/Advanced/Enviroment Variables: Path F:\Dev\MinGW\;F:\Dev\MinGW\Include;F:\Dev\MinGW\Lib Still nothing happens, just get: '' Building app Compiling:c_funcs.c Process complete '' |
| ||
It should actually flag an error if it's not found. One way to be sure is to rebuild mods using bmk. It'll fail completely if mingw isn't installed right. |
| ||
Is there a help file or readme anywhere on how to install on XP? |
| ||
Not that I know, but if you don't mind looking back through my posts.(click on my profile, post counts, just in case.) and you'll find me asking the exact same question a couple of weeks back with a working solution. Can't for the life of me remember the name of the thread though, sorry. |
| ||
Found the help from mark, installed using those comments on Windows2000 all works fine, Installed under Windows XP and you guessed it nothing. Would seem it has to be in the root directory of the HardDisc? |
| ||
Hm, well the intructions someone posted(Noel I think, might narrow the search down.) worked fine on XP for me. But yeah, C:\mingw is where I Installed. |