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 Song, Jinhu
- Navigate by Date:
- Prev:
RTEMS-GeSys_2.1.beta and cexp-1.5 for uC5282 Coldfire Module K.M Ha
- Next:
RE: Beginners C++ questions Song, Jinhu
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
<2008>
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: 80 MHz clock for uC5282 Coldfire Module Eric Norum
- Next:
RE: Beginners C++ questions Song, Jinhu
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
<2008>
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|