[GiNaC-devel] about adding new function

Chris Dams Chris.Dams at mi.infn.it
Fri Jul 7 13:11:19 CEST 2006


Dear Wangtielei,

First I would like to point out to you that ginac-devel at ginac.de is not
the right list for questions like this. Better use ginac-list at ginac.de for
this.

On Thu, 6 Jul 2006, [gb2312] wangtielei(=CD=F5=CC=FA=C0=DA) wrote:

> #include <ginac/ginac.h>
> using namespace std;

It is generally considered bad to use "using" in a header file. The reason=
=20
is that everybody using your header will get everything that is in the=20
std-namespace for free and they may not want it because it may cause=20
conflicting names.

> namespace GiNaC {

I'm not sure what generally the opinions are on putting your own=20
functions inside the namespace of a library. I never do that.

> /* a test function*/
> DECLARE_FUNCTION_2P(myfcn)
> }
> #endif

Delete the #endif. There is no corresponding #if. Better yet, use include
guards for the header file.
 =20
> and the source file <xxx.cxx>
> #include "xxx.h"
> #include "ginac.h"

This should be <ginac/ginac.h>. Or just omit the entire line as ginac.h is=
=20
already included via xxx.h.

> namespace GiNaC {
> REGISTER_FUNCTION(myfcn, dummy())
> }

Now you also need test program that uses your new function. An example=20
would be (put this in a file test.cxx):

#include "xxx.h"

using namespace std;
using namespace GiNaC;

int main()
{  ex f =3D myfcn(1,2);
   cout << f << endl;
   return 0;
}

Both files are compiled using

g++ -c `ginac-config --cppflags` xxx.cxx
g++ -c `ginac-config --cppflags` test.cxx

and then linked using

g++ -o test `ginac-config --libs` test.cxx xxx.cxx

Actually, usually one would control the process of compiling and linking
using a tool like make.

Now typing ./test gives the output:
myfcn(1,2)

Good luck!
Chris




More information about the GiNaC-devel mailing list