Compiling C++ code errors

Hi! I’ve been trying to get some C++ code to compile on Ubuntu 9.10 for use in ROOT. I’ve watched someone else compile it on a slightly older version of Linux, and it worked fine with no errors. When I try the same procedure I get a load of errors.

I did some Googling and think it might be something to do with changed header-dependencies in C++, although I might be wrong (I tried compiling some other C++ programs before and there were header issues which I managed to resolve). There are four other files called by the “makefile” script - here are the headers and ROOT files called:

[code]#include
#include
#include

#include “/usr/include/root/TROOT.h”
#include “/usr/include/root/TFile.h”
#include “/usr/include/root/TTree.h”// pretty sure these need reassigning
#include “/usr/include/root/TH1.h”
#include “/usr/include/root/TH2.h”// these point the code to the right libraries - probably delete word “physics”
#include “/usr/include/root/TMath.h”// need to go hunting for where the /include folder is :frowning:
#include “/usr/include/root/TF1.h”

#include <stdlib.h>
#include
#include <strings.h>
#include
#include <sys/stat.h>

#include “/usr/include/root/TString.h”
[/code]

Here’s the start of what I got when I tried to compile it (it goes on much longer):

eldon@eldon-laptop:/usr/share/root/macros$ sudo gedit tig-sort.cc eldon@eldon-laptop:/usr/share/root/macros$ sudo make clean rm -f *.o rm -f core rm -f *% rm -f a.out eldon@eldon-laptop:/usr/share/root/macros$ sudo make tig-sort cc -c ./tig-sort.cc -o tig-sort.o In file included from ./sort.h:15, from ./tig-sort.cc:21: ./PulserClass.h:82: warning: ‘typedef’ was ignored in this declaration cc tig-sort.o \ -o ../bin//tig-sort tig-sort.o: In function `PulserEvent::BuildEvent(char const*)': tig-sort.cc:(.text+0x68): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(char const*, std::_Ios_Openmode)' tig-sort.cc:(.text+0x90): undefined reference to `std::basic_ios<char, std::char_traits<char> >::operator!() const' tig-sort.cc:(.text+0xa0): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' tig-sort.cc:(.text+0xa7): undefined reference to `std::cout' tig-sort.cc:(.text+0xac): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))' tig-sort.cc:(.text+0xbc): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' tig-sort.cc:(.text+0xce): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' tig-sort.cc:(.text+0xd6): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)' tig-sort.cc:(.text+0xde): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))' tig-sort.cc:(.text+0x102): undefined reference to `std::basic_istream<char, std::char_traits<char> >::operator>>(double&)' tig-sort.cc:(.text+0x17b): undefined reference to `floor' tig-sort.cc:(.text+0x202): undefined reference to `std::basic_ios<char, std::char_traits<char> >::eof() const' tig-sort.cc:(.text+0x21b): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::close()' tig-sort.cc:(.text+0x229): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()' tig-sort.cc:(.text+0x249): undefined reference to `std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()' tig-sort.o: In function `PulserEvent::Print()': tig-sort.cc:(.text+0x292): undefined reference to `std::cout' tig-sort.cc:(.text+0x297): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'

Any help much appreciated. If you need more info, I’ll post it right away! Thanks in advance :slight_smile:

You should use gcc instead of cc to compile.
You should specify your include path.
I suggest to replace your statements like

#include "/usr/include/root/TROOT.h" by

#include <TROOT.h> and compile with

gcc -c ./tig-sort.cc -o tig-sort.o -I$ROOTSYS/include where ROOTSYS points to /usr/include/root
or better as suggested in the first pages of teh Users Guide

gcc -c ./tig-sort.cc -o tig-sort.o `root-config --cflags`
Rene

Ok that’s great, seems to be working now. Missed the bit in the manual where it gave that command, sorry. Compiler outputs this now:

eldon@eldon-laptop:/usr/share/root/macros$ sudo gcc -c ./tig-sort.cc -o tig-sort.o `root-config --cflags` In file included from ./sort.h:22, from ./tig-sort.cc:18: ./PulserClass.h:82: warning: ‘typedef’ was ignored in this declaration

This refers to the following bit of code; is it important that “typedef was ignored”?

typedef struct DetChan { int tig; // tig module (0-5, 8-11) int slot; // slot (1-6) int chan; // chan (0-7) int off; // offset int gain; // gain };

Thanks for the quick response :slight_smile:

[quote]This refers to the following bit of code; is it important that “typedef was ignored”? [/quote]The code you shown is actually C code, in C++ you no longer need the typedef in front of struct.

Cheers,
Philippe.

Magic, that’s cleaned up all my questions. Thank you both :slight_smile: