Home AMX User Forum AMX Technical Discussion

Can #include directive specify a file in a subdirectory?

I wrote #include 'subfolder/MyFile.axi', then thought, this is Windows, should that be a forward slash or backslash? So I tried compiling, and got

WARNING: (1)The pre-processor is unable to find the directory subfolder/ in the given path. Ignoring directory and continuing...
ERROR: (5)NetLinx Pre-Processor Error: Could not find the include file subfolder/MyFile.axi

OK, I figured it wants a backslash. Tried that, same error but with a backslash after the folder name. Then I found this very old thread where the verdict seemed to be that people just put all their includes in one directory and don't use folders -- nobody actually answered the question.

So: is this actually impossible? If relative paths aren't supported, then why is there a special error message about "unable to find the directory"? If they are supported, what's the syntax to include a file from a subdirectory?

Comments

  • If you attach the include into the workspace tree, does it require the subdirectory path? It should not because literally all of our files are nested within the OS file system and we never have to declare this.

    Another option would be within SETTINGS > PREFERENCES > NETLINX COMPILER > DIRECTORIES to declare a permanent folder you would always like it to check when searching for files as part of the build process.

  • I haven't tried this, but I didn't realize that the workspace tree was used for resolving #include statements -- I've definitely #includeed AXI files that are not in the workspace before, and the code compiled and ran with no warnings. (I later added the files to the workspace, because I think they may not end up in the SRC archive otherwise.)

    If I had subdir/MyFile.axi, then added that to the workspace, would I #include 'MyFile.axi';? Am I not allowed to add subA/MyFile.axi and subB/MyFile.axi to the same worksapce? If I am, how would I disambiguate?

  • I made directories sub_1 and sub_2 and put MyFile.axi in both places. I then added file from sub_1 to the workspace, and in the properties dialog I set the Identifier as MyFile_1. I also added the copy of the file from sub_2, and set the identifier to MyFile_2. I was not able to use the "identifier" to e.g. #include 'MyFile_2' (it looked for "MyFile_2.AXI"), but I was able to #include 'MyFile.axi' -- built and ran without errors.

    Where it gets interesting is, I added a simple DEFINE_CONSTANT at the top of each copy to set a different value, and in the debugger I was able to see it used the value from sub_2 when both files are in the project. I removed the file from sub_2 from the workspace -- still on disk, just not in the project definition -- and rebuilt, changing nothing else. Now, the debugger showed the value from the file in sub_1. I then removed the other file from the workspace, again changing nothing else, rebuilt, and got an error that the pre-processor could not find "MyFile.axi".

    So apparently the answer to my question is, you can import a file that resides in a subfolder, if that file is added to the workspace, but you cannot pick the file to import based on which folder it is in -- the path specifier must be the filename only. Including files that are not in the workspace is possible, and does not generate warnings, but also only works if the file is not in a subfolder.

    (IMHO, this is kind of weird behavior, and it'd be nice to see these inconsistencies addressed in future releases.)

  • If you have a standard set of includes that are used all the time then the Preferences -> NetLinx Compiler -> Directories tool could be an option. Note that the files would still require mapping into the Workspace for the Exporting into an AXW. I am fairly sure that if with duplicate file references in the Directories tool and Workspace that the Workspace file has precedence at compile.

Sign In or Register to comment.