Using IMPORT instead of INCLUDE

BlitzMax Forums/BlitzMax Beginners Area/Using IMPORT instead of INCLUDE

John Pickford(Posted 2005) [#1]
I can't get this to work. My project is only 2 files, the first Including the second.

If I change the Include to Import then I get an error: "identifier xxxx not found". This appears to be when the second file is calling the function xxxx in the first file. Fair enough so I put Import "first.bmx" at the stop of the second file. Now when I try to compile I get "duplicate identifier" errors.


Perturbatio(Posted 2005) [#2]
so you are inporting the first file into the second and the second into the first? (or have I misread the above).


John Pickford(Posted 2005) [#3]
Yes. I thought I read that was what to do.

I think I misunderstood it, the docs suggest import is a more efficient alternative to includes but it seems dependency can only go one way.


fredborg(Posted 2005) [#4]
Yes, Imported files need to be self contained, or at least, not require the file that imports them to be present. Ie. you are not allowed to loop dependencies with Import.

I think Import is primarily meant for modules, but I might be wrong.


Robert(Posted 2005) [#5]
As BlitzMAX doesn't have header files, dependancies do have to be one way.

If both files need a particular function, then you should consider putting that function in a third file which can be imported by the other two files.

If you want two files to use a type declared in the other file, then create a parent type and store that in a third file.

For example, my setup is something like:

game.bmx (Defines Terrain type, imports entities.bmx)
entities.bmx (Entity code, but uses terrain code as well)
types.bmx (Defines TerrainBase type, which is what entities.bmx actually uses to call the terrain code in game.bmx)


John Pickford(Posted 2005) [#6]
There's a bit in the docs which had me confused but reading it again it makes sense. On reflection I'll stick with include.


Bot Builder(Posted 2005) [#7]
Yeah, I generally use imports for standalone function sets that dont need to be recompiled over and over again. Also, Once I get a finished project in I plan to copy the used mods into my program's directory, strip out all unused code, and import. This will probably be done for my preprocessor which uses very few mods so it shouldn't be too hard. I'll also throw in a ultra-release mode into the processor to auto-strip out the mods, and UPX the resulting exe.


Yan(Posted 2005) [#8]
Ahh...So that's what 'cycles of imports' means!

I didn't understand that bit either. :o/