Author Topic: C++ API on Linux  (Read 17130 times)

Offline novaczkisz

  • Newbie
  • *
  • Posts: 5
    • View Profile
C++ API on Linux
« on: March 31, 2010, 20:10:29 »
Hi Hugin C++ API Users!

I have a project in which i run into a task to integrate OMNeT++ with a bayesian network engine. I am testing the Hugin (Lite) C++ API for this purpose right now and am stucked in a problem: as soon as i include the API header file (hugin) in my project it wont compile any more. The reason is that the compiler (gcc version 4.4.1) stops at several syntax errors found in that header. I have copied one of the errors found. Has anyone meet a problem like this?

#########################################
/home/szabi/Desktop/HUGIN_LITE.linux/include/hugin expected ‘;’   HuginAPI      1033   C/C++ Problem
#########################################

Br,
Szabolcs

Offline novaczkisz

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: C++ API on Linux
« Reply #1 on: April 01, 2010, 14:34:16 »
Hi All!

The problem has been solved. There were three problems in the hugin cpp header file:

No1: The INFINITY function of the NetworkModel class:

Code: [Select]
        /** The infinity value used by Hugin
            @return infinity, represented as a double
        */
        double INFINITY () const;

The problem here is that INFINITY is already declared: it is the built in function of gcc __builtin_inff. Thus the compiler indicates the following error:
‘__builtin_inff’ declared as function returning a function   hugin.h   HuginAPI/src   369   C/C++ Problem

The solution is to undef infinity right at the beginning of the header:

Code: [Select]
#endif /* _WIN32 */
#endif /* H_DLL */

#ifdef INFINITY
#undef INFINITY
#endif

#include <string>
#include <vector>


No 2: H_DLL bool evidenceModeIs (EvidenceMode ev) const; in class Domain

Gcc has some problem with EvidenceMode ev

The solution is to change ev to anything you like (ev -> em):

Code: [Select]
H_DLL bool evidenceModeIs (EvidenceMode em) const;
No3:
The same problem as No 2 with function propagate of class Domain:
The solution again:

Code: [Select]
        H_DLL void propagate (Equilibrium eq = H_EQUILIBRIUM_SUM,
            EvidenceMode em = H_MODE_NORMAL);



Br,
Szabolcs




Offline Frank Jensen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 576
    • View Profile
Re: C++ API on Linux
« Reply #2 on: April 03, 2010, 21:02:53 »
INFINITY is defined as a macro when you include <cmath>.  If you include <hugin> before <cmath>, the problem disappears.

What are the problems with the "ev" identifier?  Is it also a macro problem?  ("ev" should never be defined as a macro -- defining a simple identifier like that as a macro could lead to all kinds of unexpected surprises.)