Compile Error Message

As I am trying to learn C++ using the codes in this website, I encountered the following function evaluation code:

[code]#include “Math/IFunction.h”

class MyFunction: public ROOT::Math::IBaseFunctionOneDim
{
double DoEval(double x) const
{
return x*x;
}

ROOT::Math::IBaseFunctionOneDim* Clone() const
{
return new MyFunction();
}
};[/code]

I am compiling it using this command:

And I am receiving the following error:

/usr/lib/gcc/i686-redhat-linux/4.9.2/../../../crt1.o: In function `_start': (.text+0x18): undefined reference to `main' collect2: error: ld returned 1 exit status

I even tried to add main() function to the code. However, it still doesn’t work. I am writing my codes in my Fedora21 Linux and I think I have installed all the required root softwares on my machine. Do you know if I am doing something incorrectly? Your help is greatly appreciated.

hi,

When you added the main function the error should have greatly changed. What are you trying to accomplish? The code snippet you gave provide the declaration of a class but does not do any action in particular. What tutorials or documentation are following?

Cheers,
Philippe.

Hi,
Here is the page from Root website. I am doing the first example that appears in the page:
root.cern.ch/drupal/content/how … -framework

Thanks,

The first example show how to define the function, not how to use it. For more complete example see the end of the page you mentioned or https://root.cern.ch/drupal/content/function-integration

Cheers,
Philippe.

Thank you for your advice dear Philippe,

I’m beginner at root. And I just try type this command in terminal:

TGraphErrors *gr=new TGraphErrors(“ExampleData.txt”)

This is typically exercise to check how “Plotting Measurement” works. But I get something like this:

root [3] TGraphErrors *gr=new TGraphErrors(“ExampleData.txt”)
Error in TGraphErrors::TGraphErrors: Cannot open file: ExampleData.txt, TGraphErrors is Zombie

It’s great if anybody will help me :smiley:

“Cannot open file: ExampleData.txt” usually means that the “ExampleData.txt” file does not exist (in the current subdirectory).

I’m not sure that understand what does mean “existing in current directory”. Because I’ve just opened this file. And I know path to this file. Maybe I should cut+paste it to another place?

“In the current subdirectory” means that his file must be present in the subdirectory in which you start “root”.
You can also explicitly give the full path to this file when creating TGraphErrors (then this file can be anywhere, of course).