Hi…
( IDE in rtp 6.2 - PE , native Nto environment)
Here I have an example of a small/simple template based c++ library, and
a main() c++ function that calls the library. The point is that when I
compile in the present form all is fine and all works. But notice that
I have to explicitly call the *.cc source member of the library (see
the code bellow and attached):
#include “MSlib.cc”
^^^^^^^^^^
and I have to provide the path to the source code. But if I have:
#include “MSlib.h”
^^^^^^^^^^
then the project will not compile (even when I provide the path to the
source code is present and the link to the library is provided).
I wonder why is this? Does this mean that we cannot have instantiated
objects in a library? If this is the case, then would this mean that I
cannot make an API available on a library written in c++?? Actually, I
am not sure what this means, or what it is that I am doing wrong. Any
help is most appreciated. Thanks.
Best Regards…
Miguel.
P.S. you ‘can make clean; make’, but you have to have the library in the
library path. Alternatively, use the IDE.
// ----------- ms.main.cc ---------------------
#include
#include
#include “MSlib.cc”
#include <stdio.h>
int main(int argc, char *argv[])
{
MSlib mslib;
printf("\n name is: %s \n", mslib.name() );
return EXIT_SUCCESS;
}
// ---------------------------------------------
////////////////////////////////////////////////////////////////////////
#ifndef MS_LIB_H
#define MS_LIB_H
//… local include
#include //… #include <stdio.h> //…NULL, O_RDWR def’s,
etc …
#include //… #include <string.h> //…memcpy, memset,
memmove…
#include //… #include <stdlib.h>
#include //… #include <math.h>
#include //… #include <stddef.h>
//… other include
/////////////////////////////////////////
// begin class declaration
/////////////////////////////////////////
template
class MSlib
{
public:
MSlib( void );
~MSlib( void );
char * name( void );
int var0;
protected:
int var1;
private:
int var2;
};
////////////////////////////////////////
/////////////////////////////////////////
/////////////////////////////////////////
#endif
////////////////////////////////////////////////////////////////////////
#ifndef MS_LIB_CC_
#define MS_LIB_CC_
//… local includes
#include “MSlib.h”
/////////////////////////////////////////////
/////////////////////////////////////////
// this is the file constructor
/////////////////////////////////////////
template
MSlib::MSlib( void )
{
}
//////////////////////////////////////////////
// this is the file destructor
/////////////////////////////////////////////
template
MSlib::~MSlib(void)
{
}
////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
template
char * MSlib::name( void )
{
return ( “ms.lib” );
} //… end getMountPoint()
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////
#endif
but