Reputation: 3136
I am trying to use my NumSuch module in another program. My Makefile
includes
NUMSUCH_HOME=/home/buddha314/numsuch/src
MODULES=-M$(NUMSUCH_HOME)
yummly: yummlyAnalysis.chpl
$(CC) $(FLAGS) $(MODULES) -o yummlyAnalysis $<
#$(CC) $(MODULES) -o yummlyAnalysis $<
Within the code, I don't want to use NumSuch
because I don't want to pollute the name space. I thought I could
var g = NumSuch.buildFromSparseMatrix(A, weighted=false, directed=false);
But during compilation, I get
yummlyAnalysis.chpl:72: error: 'NumSuch' undeclared (first use this function)
Makefile:12: recipe for target 'yummly' failed
Upvotes: 1
Views: 62
Reputation: 4008
The problem with this program is that Chapel doesn't know that NumSuch
is the name of a module as opposed to a record, class, or typo. As a result, it doesn't go looking for it in your module search path. The fix is to let Chapel know that there is a module named NumSuch
:
One way to do this is via a use
statement (this asserts that there is a module with the given name, and will cause the compiler to go looking for it if it hasn't already found it). You can avoid namespace pollution as you'd hoped by using filters that cause no symbols to be made visible within the scope of the use
statement:
use NumSuch only ; // only make this (empty) list of symbols available
or:
use NumSuch except *; // make all symbols available except for `*` (all of them)
After either of these statements, your call should work:
NumSuch.buildFromSparseMatrix(...);
and an unqualified call should not since no symbols were made available via the use
:
buildFromSparseMatrix(...);
You could even put the use
statement into some other scope which would cause the compiler to go looking for the module, find it, know that there's a module with that name, and limit the namespace pollution to that scope (though I consider this stylistically worse compared to the previous, more idiomatic, approaches):
{
use NumSuch; // causes the compiler to go looking for module NumSuch; limits namespace pollution to this scope...
}
NumSuch.buildFromSparseMatrix(...);
A second way to do this is to list the NumSuch.chpl
source file explicitly on the chpl
command-line. By default, all source files named on the command line are parsed and their modules made known to the compiler.
Upvotes: 3