[collectd] Get collectd data from C++ source code

Massimo Canonico mex at di.unipmn.it
Wed Aug 8 12:22:10 CEST 2012


Hi Sebastian (and hi all),
I'm sure that I'm missing something in the procedure that you suggested me.
Here what I have done:
1) downloaded source code from collectd v. 5.1.0
2) tar xvfz of the source code
3) run ./configure // in order to create the config.h file
4) create the foo.cpp file as you suggested
5) run g++ -I./src/ -DHAVE_CONFIG_H -shared -fPIC -o foo.so foo.cpp

and I got several errors:

[mex at shrek collectd-5.1.0]$ g++ -I./src/ -DHAVE_CONFIG_H -shared -fPIC 
-o foo.so foo.cpp
In file included from ./src/plugin.h:26:0,
from ./src/common.h:27,
from foo.cpp:3:
./src/configfile.h:105:52: error: ‘_Bool’ has not been declared
In file included from ./src/plugin.h:27:0,
from ./src/common.h:27,
from foo.cpp:3:
./src/meta_data.h:62:5: error: ‘_Bool’ has not been declared
./src/meta_data.h:78:5: error: ‘_Bool’ has not been declared
In file included from ./src/common.h:27:0,
from foo.cpp:3:
./src/plugin.h:139:3: error: ‘_Bool’ does not name a type
./src/plugin.h:359:5: error: ‘_Bool’ has not been declared
In file included from foo.cpp:3:0:
./src/common.h:263:3: error: ‘_Bool’ has not been declared

What am I doing wrong?

Thanks,
M




On 08/03/2012 04:15 PM, Sebastian Harl wrote:
> Hi,
>
> On Fri, Aug 03, 2012 at 03:56:20PM +0200, Massimo Canonico wrote:
>> I have to get the collectd data (in particular, the idle time of the
>> last 4 measures) and use it in my C++ code.
>>
>> Is there any example available? Do you have any suggestion concerning
>> which is the best way to do it?
> While I have never tested this, this should be fairly simple. You'll
> have to make sure that the callback functions and register_module() are
> linked according to the C calling conventions, i.e., those functions
> have to be declared "extern C". You should then be able to call any C++
> code from those functions and compile the whole thing using a C++
> compiler.
>
> So, in short, an example should look something like this:
>
> foo.cpp:
>
>    extern "C" {
>        #include "collectd.h"
>        #include "common.h"
>        #include "plugin.h"
>    }
>
>    /* further, possibly C++, includes */
>
>    extern "C" {
>        static int foo_read(void);
>        void module_register(void);
>    }
>
>    static int
>    foo_read(void) { /* ... */ }
>
>    void
>    module_register(void) {
>        plugin_register_read("foo", foo_read);
>    }
>
> Compile that, again untested, using something like:
>
>    g++ -DHAVE_CONFIG_H -shared -fPIC -o foo.so foo.cpp
>
> In case you manage to get that up and running, it would be nice to get
> some feedback / short howto / example / whatever on the list or in the
> wiki :-)
>
> HTH,
> Sebastian
>





More information about the collectd mailing list