I created two CCL programs ("aprog" and "bprog") and placed them in separate CCL files of the same names ("aprog.ccl" and "bprog.ccl" respectively).
Both programs work correctly by themselves. Then I changed "aprog" to call "bprog" from within the code and I got an error message when I tried to compile my private CCLs: Aprog.ccl 5: Undefined name 'bprog' Aprog.ccl 5: Syntax error near 'arg_1'
What is the problem and how do I correct it? I have called other CCL programs from within a CCL routine and I have not had any problems. Why is this a problem?
Synopsis
Correcting 'Undefined name' error in compilation of CCL files
Solution
This is a very simple problem to fix, but before we describe that, we have to explain exactly why this error occurs. Let's start by clarifying some points:
- The name of a CCL file can be different from the name of the CCL program inside of the file. In fact, you can have more than one program (or command) in a CCL file. Actually, you are encouraged to put more than one program in a CCL file if the programs are related (this way similar programs are located in one place for you to find later).
- The error refers to the program name ("bprog") that is not found, but the file name "Aprog.ccl" is also listed in the error message. The number ("5" in this case) tells the line in the "Aprog.ccl" where "bprog" is called. All this information will prove helpful in correcting the problem.
- CCL files are compiled in alphabetical order by file name. The contents of each file are then compiled sequentially. If the CCL compiler finds a reference to a program name before that program has been compiled, the error "Undefined name..." occurs.
Now, let's address the problem itself: The first line of your error message ("...Undefined name..") indicates that the program "bprog" was not compiled before the contents of the file "Aprog.ccl" was compiled. The other errors most likely stem from this problem. Once you correct the compilation issue, the other errors should go away.
How do you solve the compilation problem? CCL is based on the C programming language. And this problem is typical of something that might happen when programming in C. Fortunately, there are three easy workarounds for this (you only have to perform one of these workarounds, but you should understand how they all work):
- Rename the CCL files in a different alphabetical order so that the file containing "bprog" gets compiled before the file containing "aprog". You can try renaming the "Bprog.ccl" file to "Aaprog.ccl". You do not have to change the names of the individual programs.
- Place the "aprog" and "bprog" programs in the same file and make sure that "bprog" is placed before "aprog" (you will still have the problem if the order of the files is reversed).
- If the above options are difficult to do, you can solve the problem by declaring a "prototype" of "bprog" before "aprog" is defined. An example of this follows:
Let's assume that the first few lines of "bprog" looks like this: cmd bprog(real arg_1) { real z_point; ..... A proper prototype statement for "bprog" would be the first line of the program followed by a semicolon: cmd bprog(real arg_1); This prototype statement is a declaration that the "bprog" program will be fully defined later. All you have to do is place the prototype statement in your "aprog.ccl" file before the beginning of the "aprog" program. Make sure that the prototype statement is not contained within any other program, but stands by itself in the CCL file.