EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: RE: Beginners C++ questions
From: "Song, Jinhu" <[email protected]>
To: "Mark Rivers" <[email protected]>, <[email protected]>, <[email protected]>
Cc: [email protected]
Date: Tue, 29 Apr 2008 09:17:28 -0700
Hi Mark,

I had similar problem when I was trying to create a shared lib (not epics).  It was fixed by checking the order of libraries to link.

Hope this can give you a hint.

Jinhu
 

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Mark Rivers
Sent: Tuesday, April 29, 2008 8:23 AM
To: [email protected]; [email protected]
Cc: [email protected]
Subject: FW: Beginners C++ questions

Folks,

I'm having a simple problem with linking C++ on Linux that I wonder if you can help with. 

Here's the problem.

- I have a C++ base class and a number of derived classes.  If the base class is in the same library as the derived classes everything is fine.
However, if the base class is in a different library from the derived classes, then it compiles fine (because it finds the header file), but it fails at link time.  

 
My base class has methods like the following:
 
/* Constructor */
asynParamBase::asynParamBase(const char *portName, int maxAddr, int
paramTableSize)
    : maxAddr(maxAddr){ 


Since that is not declared static, if it were a C function the linker would find it even if it were in a different library.  However, when I try to link this base class which is used by a derived class in another library I get the following error:
 
../NDPluginBase.cpp:454: undefined reference to `asynParamBase::asynParamBase[not-in-charge](char const*, int, int) '../../../lib/linux-x86//libADPlugin.a
(NDPluginBase.o)(.text+0xfff): In function `NDPluginBase::NDPluginBase[in-charge](char const*, int, int, char const*, int, int, int)':

However, if I force the linker to include the module that includes the base class source code by adding the following lines to the beginning of
it:
 
/* This is for testing */
#include <epicsExport.h>
int asynParamBaseDebug=0;
epicsExportAddress(int, asynParamBaseDebug);

and then add this line to the .dbd file:

variable(asynParamBaseDebug,int)

then it links OK.

How do I get the linker to pull in the module with the base class definition without having to force it with that global definition?

Andrew Johnson suggested putting the keyword epicsShareClass before the class definition.  I tried that, but interestingly it links fine on Windows with or without that keyword, but fails on Linux with or without the keyword.

Thanks,
Mark



 



Replies:
RE: Beginners C++ questions Mark Rivers
References:
FW: Beginners C++ questions Mark Rivers

Navigate by Date:
Prev: FW: Beginners C++ questions Mark Rivers
Next: RE: Beginners C++ questions Mark Rivers
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: FW: Beginners C++ questions Mark Rivers
Next: RE: Beginners C++ questions Mark Rivers
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  <20082009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 02 Sep 2010 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·