From mmmm at pp.inet.fi  Sat Apr  2 18:40:37 2005
From: mmmm at pp.inet.fi (Markku Mielityinen)
Date: Sat Apr  2 18:36:46 2005
Subject: [Rd] Building new graphic device drivers with g++
In-Reply-To: <Pine.LNX.4.61.0504021402140.22374@gannet.stats>
Message-ID: <000001c537a2$b30fe480$0d01a8c0@MARKKUOLD>

> Is this the same devNull.cpp as below?  If so, I don't believe that it
did 
> work.

The given example devNull.cpp demonstrates the problem and thus does not
work. I have other examples that have calls to device API removed. It
seems the call to R_CheckDeviceAvailable is linked properly but calls to
GEcreateDevDesc and GEinitDisplayList are not. This must have been
confusing. Sorry...

> Where did that come from?  Why do you need the Fortran 
> runtime linked into 
> C++ code?  What has pthreads to do with this?

I like to develop code with a few additional options (such as -Wall)
that are not used with R CMD SHLIB (atleast by my system). The presented
command line is used to build the code I'm currently working on (it uses
those additional libraries). In this case those additional library
references are not needed. On the other hand they should not cause any
problems either.

> > I probably need to link to some "libR.a" module.
> 
> Please don't hypothesize out of thin air.

Good tip. If we could all just live by it... The yielded error message
is a result of a function call that cannot be dynamically linked to its
respective implementation. Usually this means you have forgotten to link
some required library. Reference to "libR.a" was not meant to specify
any particular file literally.

> You only need -lR if you built a shared-R-lib version of R, a 
> configure 
> option.  If it were needed, R SHLIB would have made use of it.

OK.

> 
> Notice the name mangling: It seems you are trying to build a 
> C++ graphics 
> device driver.

Yep.

>  Where did you get the idea that was 
> supported? 

With respect to graphic device drivers I have not seen a clear statement
one way or the other. "Writing R extensions" states that C++ can be used
for libraries. I have written a lot of C++ code that use R functions
without any problems. As far as I know it should always be possible to
call C compiled code from C++. If one can use Java to build device
drivers why not C++? Your question leads me to believe that there is
some mysterious incompatibility...

> it would be easier to write C as C and not as pseudo-C++.

True. In this case I NEED to re-use already existing C++ code. How
should I include the headers?

> Is there some local tuition about the differences between C 
> and C++ you 
> could obtain?

:(. Actually I have read quite a lot about these languages ranging from
advanced manuals to ISO/IEC 9899 and beyond. Sorry if you feel I hit a
nerve. The example I presented was a bit stupid (like examples tend to
be). Nobody uses C++ and place all code in extern "C" block.

Regards,
	Markku Mielityinen


[Rd] Building new graphic device drivers with g++
Markku Mielityinen