-2

Here is my compilation command followed by the error message I receive. The link where you can see the code is also attached.

g++ -Wall `root-config --cflags --ldflags --libs` StevenJohnsonDoubleIntegration.cpp

/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

Link

Benjamin
  • 145
  • 8

1 Answers1

2

The error undefined reference to main means that at linking time, there was no main() function.

Looking at the example code, there is a comment that says:

Compile with -DTEST_INTEGRATOR to generate this little test program.

Usage: ./integrator <dim> <tol> <integrand> <maxeval>

where = # dimensions, = relative tolerance,
is either 0/1/2 for the three test integrands (see below), and is the maximum # function evaluations (0 for none).

Looking at the code, the main function is excluded from the build unless this symbol is defined.

So, add -DTEST_INTEGRATOR to your command line for compiling. You'll probably also want a -o integrator to make the output called integrator instead of a.out

g++ -DTEST_INTEGRATOR -Wall `root-config --cflags --ldflags --libs` StevenJohnsonDoubleIntegration.cpp -o integrator
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
John O'M.
  • 510
  • 4
  • 6
  • Thanks, I should have been more careful, – Benjamin Jan 30 '15 at 03:49
  • So, is that true that in general if some code is old using C, it might not be working using C++ commands? – Benjamin Jan 30 '15 at 03:56
  • It is true that not all C will compile as C++, but usually C can compile as C++ (specifically, C code using features from recent C standard versions that don't exist in C++, or C code using C++ reserved words) . In general I would recommend using a C compiler for C code just to not worry about it.Your issue wasn't a C++ vs C issue though; both allow for conditionally compiled code via preprocessor defines. – John O'M. Jan 30 '15 at 04:10