## WeBWorK Problems

by Siman Wong -
Number of replies: 10
I'm trying to learn the syntax for coding vectors by modifying existing codes. But when I copied the source code for

https://test.webwork.maa.org/webwork2_course_files/model_Calculus_1/show-source.cgi/setOrientation/prob10.pg

and pasted it onto PGLabs, I got a massive error message:

Can't locate macro file |parserOrientation.pl| via path: |.|, |/opt/webwork/courses/wikiExamples/templates/macros|, |/opt/webwork/pg/macros|, |/opt/webwork/courses/wikiExamples/templates/Library/macros/Union|, |/opt/webwork/courses/wikiExamples/templates/Library/macros/Michigan|, |/opt/webwork/courses/wikiExamples/templates/Library/macros/CollegeOfIdaho|, |/opt/webwork/courses/wikiExamples/templates/Library/macros/FortLewis|, |/opt/webwork/courses/wikiExamples/templates/Library/macros/TCNJ|, |/opt/webwork/courses/wikiExamples/templates/Library/macros/NAU|, |/opt/webwork/courses/wikiExamples/templates/Library/macros/Dartmouth| at /opt/webwork/pg/lib/PGloadfiles.pm line 338.

Could anyone explain to me what is going on?

by Jason Aubrey -
Hi Siman,

When a macro file (such as parserOrientation.pl) is loaded into a problem with loadMacros(), the system looks in a few different places for that file:

1) the directory containing the pg file (this is where instructors can put custom macro files used only in a single set)
2) the [course]/templates/macros directory (this is where instructors can put custom macro files used in many sets in a course)
3) the Library/macros directory (this is where NPL authors put custom macro files used in many of the problems they write for the NPL)
4) the pg/lib/macros directory (this is where webwork developers put macro files for general use)

The error you saw is due to the fact that parserOrientation.pl is a custom macro which comes with the Orientation problem set (case 1), so, in a standard installation, you can't use it outside of the Orientation problem set. (Of course, if you wanted to use it in other sets in your course, you could just move or copy it to your [course]/templates/macros directory.

Hope this helps,
Jason

by Nandor Sieben -
I think 4) should be: pg/macros ?

Is there similar functionality with the Library/lib directory? If not, then where should
I put custom lib files? What I have in mind is C code that needs to be compiled.

by Jason Aubrey -
Hi Nandor,

Oops - yes, I meant pg/macros for (4). As far as I'm aware your second question has no precedent, especially when it comes to C code; maybe Mike or Arnie have an opinion about where it should go. Maybe for you NAU/macros and NAU/lib would make the most sense.

I'm intrigued by your mention of C code that needs to be compiled, and I'd be interested to know what you're using it for - it sounds like you're doing pretty interesting stuff. It does make the question of how to distribute the problems a bit harder though.

Are you packaging the perl modules that need the compiled C code with some kind of standard perl build tool (e.g. Module::Build or ExtUtils::MakeMaker)? That would at least make it safe to assume that they could be installed without too much trouble on a system that webwork is installed on.

Jason

by Nandor Sieben -
Some of the graph theory problems need to know the chromatic number of a graph. I did not want to reinvent the wheel by implementing this in perl, this is why the C code is needed. As far as I know, a macro file cannot execute anything. This is why I need a perl module that essentially calls the compiled C executable.

So for this to work, I need three things:
/opt/webwork/pg/lib/Chromatic.pm
/opt/webwork/pg/lib/chromatic/color.c compiled

Chromatic.pm could be changed to compile color.c automatically if needed. This would make the installation a bit easier.

Perhaps there is an easier way now but this was the only solution in 2005. I think this is intentionally hard because of safety considerations.

by Michael Gage -
This is my understanding of what is needed also.

We're open to suggestions of things that would make it easier.

We could also include Chromatic.pm as part of the standard distribution,
but we would have to figure out some way to compile color.c on each
computer or give specific instructions for doing so. This might not
be too hard.

So far Chromatic is the first and only PG extension that has required C
code.

We could also allow a search for .pm files in the NationalProblemLibrary.

For safety reasons I think it would still be best if allowing these modules
had to be explicitly done in global.conf or course.conf.
(That's not all that much safety however.)

-- Mike

by Nandor Sieben -
I am not sure how to make this easier since I understand the safety concerns. Still, perhaps easier access to C++ would result in some sophisticated pg files but this is not necessarily the case.

Chromatic.pm can be easily changed so it checks for the existence of the compiled executable and if it's not there, then it creates it with gcc -O3 color.c. The only problem is that gcc may not be installed.

by Alex Jordan -
I just upgraded to 2.8, and the header page for a problem set is giving me the error message below, which seems to be related to this post. Is it the case that this gcc is not installed for me? And if so, would you mind instructing me on how to remedy that?

## WeBWorK Warnings

WeBWorK has encountered warnings while processing your request. If this occured when viewing a problem, it was likely caused by an error or ambiguity in that problem. Otherwise, it may indicate a problem with the WeBWorK system itself. If you are a student, report these warnings to your professor to have them corrected. If you are a professor, please consult the warning output below for more information.

### Warning messages

• ERROR: Unable to compile /opt/webwork/pg/lib/chromatic/color.c. at /opt/webwork/pg/lib/Chromatic.pm line 18.
• The command /usr/bin/gcc -O3 -o /opt/webwork/pg/lib/chromatic/color /opt/webwork/pg/lib/chromatic/color.c failed at /opt/webwork/pg/lib/Chromatic.pm line 19.
• Chromatic.pm and a compiled version of color.c are required for this problem at /opt/webwork/pg/lib/Chromatic.pm line 20.
• The file color.c will need to be compiled by a systems administrator. at /opt/webwork/pg/lib/Chromatic.pm line 21.
• Can't write into directory /opt/webwork/pg/lib/chromatic at /opt/webwork/pg/lib/Chromatic.pm line 23.

### Request information

 Time Tue Nov 19 10:41:43 2013 Method GET URI /webwork2/PCC-Development-ID/SAC_demonstration/

by Danny Glin -
Based on the error message, it looks like it is a permissions issue, rather than the lack of gcc.  By default the web server shouldn't be able to write to the pg directories.

The easiest fix is probably to run the relevant command from the command line, namely:
/usr/bin/gcc -O3 -o /opt/webwork/pg/lib/chromatic/color /opt/webwork/pg/lib/chromatic/color.c

If gcc is not installed, installing it should be as simple as running:
sudo apt-get install gcc

Danny

by Hedley Pinsent -
The release notes for 2.8 has the following instruction: - regards - hp

New script that will set permissions for all files.
• In particular the directory pg/lib/chromatic needs to have write permissions for the server since the C code color is compiled into it.
• To set all of the file permissions in webwork use sudo -E /opt/webwork/webwork2/bin/setfilepermissions