Urgent: Make libraries on root

Hello everyone,

I’ve made a code on c++ using root, and gets long on one file.
SO, I tought of making some functions on a different file “xxx.cc” and a header file “xxx.h” .
that’s what I’ve did, and I put the .h on the folder “include” of root, and the librarie (.cc) on the macro file with the main file. But when I try compiling it, it won’t. I get the Error: void type variable cannot be declared.

did anyone have already make a library on root? plz I need your help! :slight_smile:

PS/ I’ve made 2 files: the .h containing only protypes, and a .cc file containing the functions.

[quote=“Momos1989”]Hello everyone,

I’ve made a code on c++ using root, and gets long on one file.
SO, I tought of making some functions on a different file “xxx.cc” and a header file “xxx.h” .
that’s what I’ve did, and I put the .h on the folder “include” of root, and the librarie (.cc) on the macro file with the main file. But when I try compiling it, it won’t. I get the Error: void type variable cannot be declared.

did anyone have already make a library on root? plz I need your help! :slight_smile:

PS/ I’ve made 2 files: the .h containing only protypes, and a .cc file containing the functions.[/quote]

It’s actually not clear what you are trying to do. One thing is to write your own code with some build scripts/makefiles, another thing is to use macros in ROOT. In no case you should place any headers into the $ROOTSYS/include, that was quite a funny idea :slight_smile:

I can give you a simple example in case you are using ROOT’s interpreter and you are working with macros:

//t.h - contains a declaration.
void test_fun();
//t.cpp - contains the function's definition
#include <iostream>

void test_fun()
{
   std::cout<<"hellllooo..\n";
}

//now your "driver" macro.C
#include "t.h"

void macro()
{
    gROOT->LoadMacro("t.cpp");
    test_fun();
}

This works for me, though probably this is not the best (or even “right”) way to work with interpreter and many files, also I think ‘#include “t.h”’ can be omitted, but it does not really matter here.
So you just execute macro.C in a ROOT’s session: .x macro.C. (BTW I believe it should be explained in the ROOT user’s guide - how to work with many files or how to use ACLiC, for example - I would recommend to read these chapters). t.h, t.cpp, macro.C - they are all placed in the same directory (wherever you want, but not in $ROOTSYS/include :slight_smile: ).

If you are working with a standalone program and compiled (not interpreted) code - I suggest you read any introductory tutorial about how to compile C/C++ program from several source/header files and how to link with external libraries (ROOT).

Thank you for your help! :slight_smile: