Problem in compiling with g++

Dear all

I have a strange problem, that shows up even with a very simple code like the next one saved in prova_root.cpp:

#include "TCanvas.h"
using namespace std;
int main(){
TCanvas *c1=new TCanvas (“c1”,“c1”,10,10,700,500);
}

The compilation step

g++ -c root-config --cflags --glibs prova_root.cpp
succeeds and a prova_root.o file is produced.
The linking
g++ root-config --cflags --glibs prova_root.o
goes wrong with the following message:

prova_root.o: In function main': prova_root.cpp:(.text+0x3e): undefined reference toTCanvas::TCanvas(char const*, char const*, int, int, int, int)‘
prova_root.cpp:(.text+0x5b): undefined reference to TObject::operator delete(void*)' prova_root.o: In function__static_initialization_and_destruction_0(int, int)’:
prova_root.cpp:(.text+0x92): undefined reference to TVersionCheck::TVersionCheck(int)' prova_root.o: In functionTObject::operator new(unsigned long)’:
prova_root.cpp:(.text._ZN7TObjectnwEm[TObject::operator new(unsigned long)]+0x14): undefined reference to TStorage::ObjectAlloc(unsigned long)' prova_root.o: In functionTCanvasImp::IsA() const’:
prova_root.cpp:(.text._ZNK10TCanvasImp3IsAEv[TCanvasImp::IsA() const]+0xd): undefined reference to TCanvasImp::Class()' prova_root.o:(.rodata._ZTV10TCanvasImp[vtable for TCanvasImp]+0xf8): undefined reference toTCanvasImp::ShowMembers(TMemberInspector&)'
prova_root.o:(.rodata._ZTV10TCanvasImp[vtable for TCanvasImp]+0x100): undefined reference to `TCanvasImp::Streamer(TBuffer&)'
collect2: ld returned 1 exit status

Where is the problem? Do I miss libraries? I don’t think this is related to the root version.
I am on Ubuntu 12, 64 bits.
Root 5.34/01

Many thanks and best regards

Giovanni

Hi,
try

and

Btw. if I well remember TCanvas may not appear in such application unless you try tu use TApplication class.

[quote=“dwielane”]Hi,
try

and

Btw. if I well remember TCanvas may not appear in such application unless you try tu use TApplication class.[/quote]

It works :smiley: . Thank you: as you wrote, it was just matter of using the right order

Giovanni