Using libraries like math etc. for C / C++

Using libraries like math etc. for C / C++

von Vishnu Learning -
Anzahl Antworten: 1

We are using JOBE server and want to use math library for few problems. If i globally change the c_task.php in application/libraries of JOBE server and ass '-lm' to linkargs, then math library will be added for all programs. As per JOBE documentation linkargs parameter is sent via POST request. 

Is there a way to configure a question in Code Runner so that we can specify what link arguments to send. Mostly it will be math but later we may be using more libraries as well. Moreover, suppose I want user to write  a program to implement a^b without using pow function, i do not want to globally link with math library.

Any suggestions/solutions would be very helpful.

Thanks!

Als Antwort auf Vishnu Learning

Re: Using libraries like math etc. for C / C++

von Richard Lobb -

The most direct way to set link arguments is via the CodeRunner question authoring form. If you click the 'customise' checkbox, then expand 'Advanced Customisation', you'll find there's a Sandbox Parameters field available.

Screenshot showing parameter field

One of the parameters for Jobe is a linkargs parameters, so for example if you set the Parameters field to

{"linkargs":["-lm"]}

you'd include the math library. That and other Jobe sandbox parameters are documented in the section Run-spec Parameters at https://github.com/trampgeek/jobe/blob/master/README.md.

You could make different C/C++ question types that used different libraries by setting different values for this parameter in new question prototypes.

However, increasingly authors prefer to deal with more difficult question types using Python scripting. I've just documented a simple example of a Python script for running C/C++ programs in a section called Supporting or Implementing New Languages in the CodeRunner Readme.md file. This approach gives you much more flexibility, such as the ability to supply compile or link arguments through the question's template parameters field.

Richard