G++ compilation problems

Hi rooters,

I’m running cygwin on Windows and am trying to use ROOT framework for data analysis. I’m trying to call the TFile.h from main.cc.

main.cc:

#include <iostream> #include <TFile.h> int main() { std::cout << "this works" << std::endl; // TFile *MyFile = new TFile("Event.root","NEW"); }
I can create the object file via:

but when trying to compile using:

I get an error message:

main.o:main.cc:(.text+0x8a): undefined reference to `TVersionCheck::TVersionCheck(int)' main.o:main.cc:(.text+0x8a): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `TVersionCheck::TVersionCheck(int)' collect2: error: ld returned 1 exit status

Note that this does not complain about TFile, which seems to have been found. Also, the linking order is important (found this on the net) and I think it is right. I also tried using the Makefile and replacing the location of the library by $(shell root-config --libs) but this did not work either :frowning: (same error)

Please help!

Hi,

you should do

g++ -o myProg myProg `root-config --cflags --libs`

Danilo

Hi Danilo,

and thank you for your answer. It doesn’t solve the problem, but if I understand the error message correctly, some of the libraries were not installed?

$ g++ -o main main.cc `root-config --cflags --libs` /cygdrive/c/root/bin/root-config: line 415: test: command: integer expression expected g++: error: 'C:\root\lib\libCore.lib': No such file or directory g++: error: 'C:\root\lib\libCint.lib': No such file or directory g++: error: 'C:\root\lib\libRIO.lib': No such file or directory g++: error: 'C:\root\lib\libNet.lib': No such file or directory g++: error: 'C:\root\lib\libHist.lib': No such file or directory g++: error: 'C:\root\lib\libGraf.lib': No such file or directory g++: error: 'C:\root\lib\libGraf3d.lib': No such file or directory g++: error: 'C:\root\lib\libGpad.lib': No such file or directory g++: error: 'C:\root\lib\libTree.lib': No such file or directory g++: error: 'C:\root\lib\libRint.lib': No such file or directory g++: error: 'C:\root\lib\libPostscript.lib': No such file or directory g++: error: 'C:\root\lib\libMatrix.lib': No such file or directory g++: error: 'C:\root\lib\libPhysics.lib': No such file or directory g++: error: 'C:\root\lib\libMathCore.lib': No such file or directory g++: error: 'C:\root\lib\libThread.lib': No such file or directory g++: error: unrecognized command line option ‘-GR’ g++: error: unrecognized command line option ‘-GX’ g++: error: unrecognized command line option ‘-G5’
I think I should note here that I have root installed on both Windows (at the directory shown in the error above) and in the cygwin folder too. Could this be the reason for the error in the first place?

EDIT: I searched in the directory and found the file libCore.lib and other “missing” files too…

Hi,

I think you would have needed the complete command (g++ -o main main.cc root-config --cflags --libs) from the start. On the other hand the error you show now is completely decoupled and seems to point to an incomplete installation. Can you boot root?

Danilo

Hi Danilo,

and thank you for your answer. I realised I have forgotten to set the environment variables, but even now that I have set them, I get the following error:

$ g++ -o main main.cc `root-config --cflags --libs` /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /cygdrive/c/root/v6.00.02/lib/libCore.dll.a when searching for -lCore /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /cygdrive/c/root/v6.00.02/lib/libCore.dll when searching for -lCore /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /cygdrive/c/root/v6.00.02/lib/libCore.dll.a when searching for -lCore /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /cygdrive/c/root/v6.00.02/lib/libCore.dll when searching for -lCore ... ... /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /cygdrive/c/root/v6.00.02/lib/libThread.dll when searching for -lThread /usr/lib/gcc/x86_64-pc-cygwin/4.8.3/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lThread collect2: error: ld returned 1 exit status

I also tried to reinstall root from the source, following this site:
cp3.irmp.ucl.ac.be/~rouby/root/#requirements

but ran into some problems, probably because of the lack of my computing literacy.

by cd root I assume they mean to move in the root directory (in my case /cygdrive/c/root/v6.00.02), but then I am unable to execute

./configure win32gcc because there is no such file in the directory… I have a config folder but it only contains

-rw-r--r-- 1 Miha None 279 Jul 3 12:28 Makefile.comp -rw-r--r-- 1 Miha None 10050 Jul 3 12:28 Makefile.config

The INSTALL file in the README also suggests cd root and then ./configure --help which I can’t seem to make work either :frowning:
Is there something that should be obvious and I am missing here? What I have done is downloaded a Windows version and installed it, it works directly from Windows, but typing root in cygwin terminal does not start it.

Miha

Hi Miha,

It looks like you are mixing native Windows binaries and cygwin binaries, and they are obviously not compatible. You should decide what you really need (i.e. do you REALLY need cygwin?)
Then we can try to help you fixing your broken ROOT installation.

Cheers, Bertrand.

Hi Bertrand,

I have a Windows machine and am doing a project in C++. Because gcc is a better compiler than the Visual Studio, I’m doing the project using Cygwin terminal. Is it possible to install ROOT on Windows and access it from Cygwin? Or do I have to install ROOT via Cygwin?

Is there any other way of using ROOT with the gcc compiler on Windows? MinGW perhaps, would that work?

Miha

Hi Miha,

If you want to use native ROOT on Windows, you have to use Visual Studio. If you want to use gcc, you have to compile ROOT from source in cygwin, and then you also need to use the full cygwin environment (with X11 display).
Note that you can also use a virtual machine with Linux…

BTW, what is the problem with Visual Studio?

Cheers, Bertrand

Hi Bertrand,

and thanks for your help. I have now installed Linux on my machine and ROOT works as it should. The reason I do not want to use VS is that we have been advised not to use it at the university for two reasons:

a) gcc is a better compiler
b) gcc is open source (I know VS is too, but Windows isn’t)

I’m glad I finally changed to Linux :slight_smile: