Difference: IanConnellyTutorials (9 vs. 10)

Revision 1013 Dec 2012 - IanConnelly

Line: 1 to 1
META TOPICPARENT name="IanConnelly"

Tutorials and tips that may come in useful

Line: 273 to 273
 M-x (ie Esc-x) normal-erase-is-backspace-mode \ No newline at end of file

Interesting thing with C dynamic libraries

    // Wierd code to load the dynamic library and extract function
    // This would work if it was a C library but it is not
    // C++ does name mangling which stops you from just using
    // the name of the function to get it from the library
    // This is because C++ allows fn overload but C does not.
    // Try using ROOT to load instead.
    void* mv1cLib = dlopen("../libMV1c_cxx.so", RTLD_LAZY);
    float (*mv1cFcn)(float,float,float,float,float,float,float);
    *(void **)(&mv1cFcn) = dlsym(mv1cLib, "mv1cEval");

Some notes on compiling against dynamic libraries/ libraries which are not listed in LD_LIBRARY_PATH

The issue with this is two fold:

  1. ) When compiling and linking, the makefile/gcc needs to know where libraries reside in order to include them.
  2. ) At run time, these libraries also need to be identified.

This means there are two things to include in the makefile:

-Wl, -rpath $(abspath./directory)

This adds a hardcoded part to the executable which says at runtime "check this path for libraries" (nb -Wl is gcc saying "pass this option to the linker").

Then one needs:

-L$(abspath ./directory) -lMyLibrary

This is used to link the library at compilation so it knows to include it.

Sidenote: Ideally, a library needs to be called

in order to include it as

Both of these terms (which one could set to a makefile variable) need to be listed as library inclusions in the building phase of the compilation and linking phase.


 readelf -d <Executable> 
will list the shared objects and the rpath.
 ldd <Executable> 
will display the libraries that are needed to run.

Using with Root dictionaries

CINT is able to produce libraries for specific ROOT objects. The main example is wanting to save a vector of TLorentzVectors to a TTree. By default this will not work. However, you can generate libraries to allow this to work. They take the command (in ROOT CINT):

>> root
>> gInterpreter->GenerateDictionary("vector<TLorentzVector>","TLorentzVector.h,vector")

Then to compile with this library you use the advice given above.

This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding RHUL Physics Department TWiki? Send feedback