I apologize if my question bothers you
I work on a code developed in C + + which worked well on mac os, this code will help create libraries *.so from *.cc and *.h I used this as flags:CXXFLAGS = -g -O2 -fPIC -Wall -ldl -D_GNU_SOURCE ,CXX := g++ and $(CXX)-shared -o $(LIBNAME) $(CLIBLIB) $(OUT_OBJS)this step is fine I got the *.so as follows. :
*****************************************
morad@linux-nzlc:~/Musique/workdir> ls library/tklibs/lib/
libAnalyticalJacobians.so libDetGeometry.so libGeomPropagators.so libPatternTestTools.so libSmearingClusterizers.so libTkLayout.so
libBaseMagneticField.so libDetLayout.so libKalmanUpdators.so libPatternTools.so libStatUtilities.so libTkNavigation.so
libBasicDet.so libDetUtilities.so libMaterialEffects.so libPropagators.so libSurfaceGeometry.so libTrackFitters.so
libBasicStripDet.so libDetVolumeGeometry.so libNumericalJacobians.so libRKPropagators.so libTkCommonDet.so libTrajectoryParametrization.so
libCommonStripDet.so libGenUtil.so libPatternPrimitives.so libSiPixelDet.so libTkFastSimHit.so libUI.so
morad@linux-nzlc:~/Musique/workdir>
*****************
then the second step I would create the executable for that I specify the-I,-L and-l in makfile I as flags:CXX = g++ and $(CXX) -O2 -g -fopenmp $(CILIBLAY) $(OUT_OBJS) $(OBJDIR)/$(MAIN_PROG).o -o $(MAIN_PROG).exe but after running it I get an error:
***************************************
morad@linux-nzlc:~/Musique/workdir/layout/analyze> make mainP=runAnalyze
Makefile:85: /home/morad/Musique/workdir/layout/build/analyze/myAnalyze.d: Aucun fichier ou dossier de ce type
g++ -MM -I/cern/CLHEP/2.0.4.5/include/ -I/home/morad/Musique/workdir/layout -I/home/morad/Musique/workdir/library/tklibs -I/cern/ROOT/source/root/include -I/usr/include/freetype2/freetype/ -I/usr/include/freetype2 -I/cern/Minuit2/5.28.00/include -I/usr/include/libxml2 -I/usr/include/libxml++-2.6 -I/usr/lib/libxml++-2.6/include/ -I/usr/include/glibmm-2.4/ -I/usr/lib/glibmm-2.4/include/ -I/usr/include/sigc++-2.0/ -I/usr/lib/sigc++-2.0/include/ -I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include/ -I/cern/gettext/0.18.2/include/ myAnalyze.cc > /home/morad/Musique/workdir/layout/build/analyze/myAnalyze.d.$$; \
sed 's,\(myAnalyze\)\.o[ :]*,\1.o /home/morad/Musique/workdir/layout/build/analyze/myAnalyze.d : ,g' < /home/morad/Musique/workdir/layout/build/analyze/myAnalyze.d.$$ > /home/morad/Musique/workdir/layout/build/analyze/myAnalyze.d; \
rm -f /home/morad/Musique/workdir/layout/build/analyze/myAnalyze.d.$$
g++ -c -I/cern/CLHEP/2.0.4.5/include/ -I/home/morad/Musique/workdir/layout -I/home/morad/Musique/workdir/library/tklibs -I/cern/ROOT/source/root/include -I/usr/include/freetype2/freetype/ -I/usr/include/freetype2 -I/cern/Minuit2/5.28.00/include -I/usr/include/libxml2 -I/usr/include/libxml++-2.6 -I/usr/lib/libxml++-2.6/include/ -I/usr/include/glibmm-2.4/ -I/usr/lib/glibmm-2.4/include/ -I/usr/include/sigc++-2.0/ -I/usr/lib/sigc++-2.0/include/ -I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include/ -I/cern/gettext/0.18.2/include/ myAnalyze.cc -o /home/morad/Musique/workdir/layout/build/analyze/myAnalyze.o
g++ -c -I/cern/CLHEP/2.0.4.5/include/ -I/home/morad/Musique/workdir/layout -I/home/morad/Musique/workdir/library/tklibs -I/cern/ROOT/source/root/include -I/usr/include/freetype2/freetype/ -I/usr/include/freetype2 -I/cern/Minuit2/5.28.00/include -I/usr/include/libxml2 -I/usr/include/libxml++-2.6 -I/usr/lib/libxml++-2.6/include/ -I/usr/include/glibmm-2.4/ -I/usr/lib/glibmm-2.4/include/ -I/usr/include/sigc++-2.0/ -I/usr/lib/sigc++-2.0/include/ -I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include/ -I/cern/gettext/0.18.2/include/ runAnalyze.cxx -o /home/morad/Musique/workdir/layout/build/analyze/runAnalyze.o
g++ -O2 -g -fopenmp -L/home/morad/Musique/workdir/library/tklibs/lib -L/home/morad/Musique/workdir/layout/lib -lxmlgeom -ltrack -lcross -lMaterialEffects -lPropagators -ltracking -lgeom -lStatUtilities -lAnalyticalJacobians -ltkhist -lxmltkgeom -lutils -lopt -ldraw -lanalyze -L/usr/lib -lGeomPropagators -lPatternPrimitives -lSurfaceGeometry -lBaseMagneticField -lUI -lGenUtil -lSiPixelDet -lSmearingClusterizers -lBasicDet -lTrackFitters -lTkFastSimHit -lCommonStripDet -lDetLayout -lTkLayout -lDetGeometry -lKalmanUpdators -lTkCommonDet -lPatternTools -lTrajectoryParametrization -lBasicStripDet -lDetUtilities -lDetVolumeGeometry -lPatternTestTools -lRKPropagators -lTkNavigation -lNumericalJacobians -lxml++-2.6 -lxml2 -lglibmm-2.4 -lgobject-2.0 -lsigc-2.0 -lglib-2.0 -L/cern/ROOT/source/root/lib -L/cern/Minuit2/5.28.00/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lfreetype -lz /usr/lib/libbz2.so.1.0.6 -lpthread -lm -ldl -lMinuit2 -L/cern/CLHEP/2.0.4.5/lib/ -lCLHEP-2.0.4.5 /usr/lib/libstdc++.so.6 /home/morad/Musique/workdir/layout/build/analyze/myAnalyze.o /home/morad/Musique/workdir/layout/build/analyze/runAnalyze.o -o runAnalyze.exe
/home/morad/Musique/workdir/library/tklibs/lib/libSmearingClusterizers.so: undefined reference to `TrivialROUSetter::set(Module)'
/home/morad/Musique/workdir/library/tklibs/lib/libTkLayout.so: undefined reference to `FixTIDTopology::recreateTopologies()'
/home/morad/Musique/workdir/library/tklibs/lib/libSmearingClusterizers.so: undefined reference to `TkDetTypeName::shortName(DetType const&)'
/home/morad/Musique/workdir/library/tklibs/lib/libTkLayout.so: undefined reference to `DetUnitGluer::glue(__gnu_cxx::__normal_iterator<DetUnit**, std::vector<DetUnit*, std::allocator<DetUnit*> > >, __gnu_cxx::__normal_iterator<DetUnit**, std::vector<DetUnit*, std::allocator<DetUnit*> > >, __gnu_cxx::__normal_iterator<DetUnit**, std::vector<DetUnit*, std::allocator<DetUnit*> > >, __gnu_cxx::__normal_iterator<DetUnit**, std::vector<DetUnit*, std::allocator<DetUnit*> > >)'
/home/morad/Musique/workdir/library/tklibs/lib/libTkFastSimHit.so: undefined reference to `RawHepEventFactoryFromGun::RawHepEventFactoryFromGun()'
/home/morad/Musique/workdir/library/tklibs/lib/libTkLayout.so: undefined reference to `toa::operator()(int const&) const'
/home/morad/Musique/workdir/library/tklibs/lib/libTkLayout.so: undefined reference to `FixTIDTopology::FixTIDTopology()'
/home/morad/Musique/workdir/library/tklibs/lib/libTkLayout.so: undefined reference to `DetBlade::DetBlade(__gnu_cxx::__normal_iterator<Det* const*, std::vector<Det*, std::allocator<Det*> > >, __gnu_cxx::__normal_iterator<Det* const*, std::vector<Det*, std::allocator<Det*> > >)'
/home/morad/Musique/workdir/library/tklibs/lib/libTkLayout.so: undefined reference to `toa::~toa()'
/home/morad/Musique/workdir/library/tklibs/lib/libTkLayout.so: undefined reference to `FullTracker::instance()'
collect2: erreur: ld a retourné 1 code d'état d'exécution
make: *** [runAnalyze] Erreur 1
morad@linux-nzlc:~/Musique/workdir/layout/analyze>
*****************************************
which is not defined in *.so for example TrivialROUSetter is only declared in a file.h is not defined in file.cc I have a hunch that the g+ + compiler for opensuse needs a flags for is seeking definitions includes *. h if it is necessary unlike g+ + mac-os
thank you in advance
2 Answers
0
I think your problem is the order of the link line. On Linux, if libA.so depends upon functions from libB.so then your link line must list libA.so before libB.so. i.e. this will cause an undefined symbol:
-L -lB -lA
whereas this will not:
-L -lA -lB
I do not believe that Mac has this requirement. If your .so files have circular dependencies, you can use -Wl,--start-group -lA -lB -Wl,--end-group. That will probably also remove the need to put the .so files in a particular order.
0
Please i recompile for link the library I met a problem the compilator gcc for opensuse gcc it Search in first time include before going out in the point that it would need these includes, for example
[code] #ifndef TimingREPORT_H
#define TimingREPORT_H
//
//
//
// V 1.1 01/09/2000
// Fast timing on Pentium
// on/off control introduced
// fixed format output
// V 1.2 21/02/2001
// cpu time added
// not thread safe yet...
#include <string>
#ifndef CMS_NO_HASH_MAP
#include <hash_map>
#include "Utilities/GenUtil/interface/stringhash.h"
#else
#include <map>
#endif
#include<iosfwd>
#include "Utilities/Notification/interface/BaseEvent.h"
[COLOR="Green"][B] #include "CommonDet/BasicDet/interface/AlignmentPositionError.h"[/B][/COLOR]
#include "Utilities/GenUtil/interface/CMSTimers.h"
/* a class to manage Timing
**/
class TimingReport {
public:
typedef BaseEvent< std::pair<double,double> > ItemObserver;
class Item {
typedef BaseEvent< std::pair<double,double> > MyObserver;
public:
Item() : on(true), cpuon(true), counter(0), o(0){}
Item & switchOn(bool ion) {on=ion; return *this;}
Item & switchCPU(bool ion) {cpuon=ion; return *this;}
void start() { if (on) {counter++; if (cpuon) cpuwatch.start(); stopwatch.start(); }}
void stop(){
if (on) {
stopwatch.stop();
if (cpuon) cpuwatch.stop();
if (active()) return;
if (o) (*o)(std::pair<double,double>(stopwatch.lap().seconds(),
cpuwatch.lap().seconds()));
}
}
public:
bool active() const { return stopwatch.running();}
void setObs(MyObserver * io) { o=io;}
double realsec() const;
double realticks() const;
double cpusec() const;
public:
bool on;
bool cpuon;
int counter;
StopWatch stopwatch;
CPUWatch cpuwatch;
MyObserver * o;
};
public:
static TimingReport * current();
protected:
#ifndef CMS_NO_HASH_MAP
typedef hash_map< std::string, Item, hash<std::string>, std::equal_to<std::string> > SMAP;
#else
typedef std::map< std::string, Item, std::less<std::string> > SMAP;
#endif
TimingReport();
public:
~TimingReport();
///
void dump(std::ostream & co, bool active=false);
/// report in ticks
bool & inTicks() { return inTicks_;}
/// switch all on
void switchOn(bool ion);
/// switch one ion
void switchOn(const std::string& name, bool ion) {
registry[name].switchOn(ion);
}
void start(const std::string& name) {
if(on) registry[name].start();
}
void stop(const std::string& name) {
if (on) registry[name].stop();
}
Item & operator[](const std::string& name) {
SMAP::iterator p = registry.find(name);
if (p!=registry.end()) return (*p).second;
return make(name);
}
const Item & operator[](const std::string& name) const {
SMAP::const_iterator p = registry.find(name);
if (p!=registry.end()) return (*p).second;
return const_cast<TimingReport*>(this)->make(name);
}
Item & make(const std::string& name) {
return registry[name].switchOn(on);
}
const bool & isOn() const { return on;}
private:
bool on;
bool inTicks_;
SMAP registry;
};
/** a class to time a "scope" to be used as a "Sentry".
Just create a TimeMe object giving it a name;
exiting the scope the object will be deleted;
the constuctor starts the timing.
the destructor stops it.
*/
class TimeMe{
public:
///
explicit TimeMe(const std::string& name, bool cpu=true) :
item((*TimingReport::current())[name]) {
item.switchCPU(cpu);
item.start();
}
explicit TimeMe(TimingReport::Item & iitem, bool cpu=true) :
item(iitem) {
item.switchCPU(cpu);
item.start();
}
std::pair<double,double> lap() const {
return std::pair<double,double>(item.stopwatch.lap().seconds(),
item.cpuwatch.lap().seconds());
}
///
~TimeMe() {
item.stop();
}
private:
TimingReport::Item & item;
};
#endif [/code]
then it asked me to check the path [COLOR = "green"] # include "CommonDet / BasicDet / interface / AlignmentPositionError.h" [/ COLOR] even if we need to file my question: [B]there is a FLAGS to redirect it [/ B]
Your Answer
2 Answers
I think your problem is the order of the link line. On Linux, if libA.so depends upon functions from libB.so then your link line must list libA.so before libB.so. i.e. this will cause an undefined symbol:
-L -lB -lA
whereas this will not:
-L -lA -lB
I do not believe that Mac has this requirement. If your .so files have circular dependencies, you can use -Wl,--start-group -lA -lB -Wl,--end-group. That will probably also remove the need to put the .so files in a particular order.
Please i recompile for link the library I met a problem the compilator gcc for opensuse gcc it Search in first time include before going out in the point that it would need these includes, for example
[code] #ifndef TimingREPORT_H
#define TimingREPORT_H
//
//
//
// V 1.1 01/09/2000
// Fast timing on Pentium
// on/off control introduced
// fixed format output
// V 1.2 21/02/2001
// cpu time added
// not thread safe yet...
#include <string>
#ifndef CMS_NO_HASH_MAP
#include <hash_map>
#include "Utilities/GenUtil/interface/stringhash.h"
#else
#include <map>
#endif
#include<iosfwd>
#include "Utilities/Notification/interface/BaseEvent.h"
[COLOR="Green"][B] #include "CommonDet/BasicDet/interface/AlignmentPositionError.h"[/B][/COLOR]
#include "Utilities/GenUtil/interface/CMSTimers.h"
/* a class to manage Timing
**/
class TimingReport {
public:
typedef BaseEvent< std::pair<double,double> > ItemObserver;
class Item {
typedef BaseEvent< std::pair<double,double> > MyObserver;
public:
Item() : on(true), cpuon(true), counter(0), o(0){}
Item & switchOn(bool ion) {on=ion; return *this;}
Item & switchCPU(bool ion) {cpuon=ion; return *this;}
void start() { if (on) {counter++; if (cpuon) cpuwatch.start(); stopwatch.start(); }}
void stop(){
if (on) {
stopwatch.stop();
if (cpuon) cpuwatch.stop();
if (active()) return;
if (o) (*o)(std::pair<double,double>(stopwatch.lap().seconds(),
cpuwatch.lap().seconds()));
}
}
public:
bool active() const { return stopwatch.running();}
void setObs(MyObserver * io) { o=io;}
double realsec() const;
double realticks() const;
double cpusec() const;
public:
bool on;
bool cpuon;
int counter;
StopWatch stopwatch;
CPUWatch cpuwatch;
MyObserver * o;
};
public:
static TimingReport * current();
protected:
#ifndef CMS_NO_HASH_MAP
typedef hash_map< std::string, Item, hash<std::string>, std::equal_to<std::string> > SMAP;
#else
typedef std::map< std::string, Item, std::less<std::string> > SMAP;
#endif
TimingReport();
public:
~TimingReport();
///
void dump(std::ostream & co, bool active=false);
/// report in ticks
bool & inTicks() { return inTicks_;}
/// switch all on
void switchOn(bool ion);
/// switch one ion
void switchOn(const std::string& name, bool ion) {
registry[name].switchOn(ion);
}
void start(const std::string& name) {
if(on) registry[name].start();
}
void stop(const std::string& name) {
if (on) registry[name].stop();
}
Item & operator[](const std::string& name) {
SMAP::iterator p = registry.find(name);
if (p!=registry.end()) return (*p).second;
return make(name);
}
const Item & operator[](const std::string& name) const {
SMAP::const_iterator p = registry.find(name);
if (p!=registry.end()) return (*p).second;
return const_cast<TimingReport*>(this)->make(name);
}
Item & make(const std::string& name) {
return registry[name].switchOn(on);
}
const bool & isOn() const { return on;}
private:
bool on;
bool inTicks_;
SMAP registry;
};
/** a class to time a "scope" to be used as a "Sentry".
Just create a TimeMe object giving it a name;
exiting the scope the object will be deleted;
the constuctor starts the timing.
the destructor stops it.
*/
class TimeMe{
public:
///
explicit TimeMe(const std::string& name, bool cpu=true) :
item((*TimingReport::current())[name]) {
item.switchCPU(cpu);
item.start();
}
explicit TimeMe(TimingReport::Item & iitem, bool cpu=true) :
item(iitem) {
item.switchCPU(cpu);
item.start();
}
std::pair<double,double> lap() const {
return std::pair<double,double>(item.stopwatch.lap().seconds(),
item.cpuwatch.lap().seconds());
}
///
~TimeMe() {
item.stop();
}
private:
TimingReport::Item & item;
};
#endif [/code]
then it asked me to check the path [COLOR = "green"] # include "CommonDet / BasicDet / interface / AlignmentPositionError.h" [/ COLOR] even if we need to file my question: [B]there is a FLAGS to redirect it [/ B]