Include/Import headache

BlitzMax Forums/BlitzMax Beginners Area/Include/Import headache

Jim Teeuwen(Posted 2004) [#1]
This stuff is giving me a serious headache.
I have a multitude of code files which all reference types defined in other files. They all exist in the same directory.

In B3D it would suffice to have 1 file which Included them all, but it appears bmax works differently.
Whether I use Include or Import, the compiler keeps popping errors about unknown identifiers. (eg types it cant find, eventhough they have been explicitly included/Imported).

How on earth does this work?

Also, what exactly is the difference between Import and Include?


TeaVirus(Posted 2004) [#2]
I was running into this as well. It seems that you can only access identifiers in imported code from the .bmx file that does the importing. I needed to change my code around a bit to accomodate this but I found it ended up being a bit cleaner because of it. I haven't tried doing it with include but it's suprising that it didn't work since I thought it was supposed to simply inline the included files.


AntonyWells(Posted 2004) [#3]
If you use the public keyword (just once, above not preceding) before defining your globals in imported(or imported files within imported files), you can access them in any other code that is being linked, including the main one.

At least It worked for me when I tried it..may not work in all cases.


Jim Teeuwen(Posted 2004) [#4]
i dont use any global variables.. Just type definitions.
The problem is, if its true that a included file can only be referenced from the file where it is included, then I have to import files in other files, and cross import em again in yet other files.

This results in all sourcefiles being imported more than once. Sometimes even 5 or 6 times. This in turn will generate a compiler error, because it does not accept multiple type definitions. (the same type is afterall imported more than once). It's getting to a point where it's just getting silly..

Ive been at this for 4 hours trying to combine a simple library of types into one unified include file but it just wont work >(


skidracer(Posted 2004) [#5]
You will not get a multiple type definition with import. To keep things simple don't use any includes and whenever you get a type not found add an import to the top of the file giving the error referencing the file with the type definition.


Jim Teeuwen(Posted 2004) [#6]
thats all well and nice, but there is no way around this.
Some of my types serve as base types for a lot of other types and therefor have to be included in a lot of files, including the main include where my program logic is located. This does result in a multiple typedefinition. (believe me, I tried it!)

[edit]
Ofcourse there is a way around this, but that would mean copying all my types and main program code into 1 single bmax file. But im sure one would agree this kindof defeats the whole modular design idea behind blitzmax..


Also, why doesnt the include command work the same way as in Blitz3D? Just copy the code into one big pile? That worked perfectly with b3d. I can't really see why one would want to change this..


marksibly(Posted 2004) [#7]
Hi,

Include should work just the way it did in B3D. If not, its a bug and needs fixing! Can you post some sample code in 'bug reports' that highlights the problem with Include and how it differs from B3Ds?

Import is different because it precompiles the imported file. However, Imports can not have 'cycles'. That means 2 bmx files can not import each other (directly or indirectly). However, I am not 100% sure that max is generating an error for this or silently ignoring it - will have a look.


Jim Teeuwen(Posted 2004) [#8]
Thank you mark. Sorry for coming off so pissed, but having spent 4 hours trying to get this to work is a wee bit frustrating. Specially since I considered this a failry trivial process. so that in turn made me think I made a fundamental mistake somewhere. If you cant find it after 4 hours.... youll agree it's not a good mood setter.

Anyhoo, I'll post an example in the Bugforums.