Page 1 of 1

how to use OpenVG with C++

Posted: Wed Jan 09, 2013 12:12 pm
by tibi38
Hi,
I tried to use OpenVG in a C++-Programm.
I had setup the OpenVG correct (rebuild.sh works fine and I could start also the compiled demos like world_font.bin).
By linking my programm I add the libs and the path.
But it brings me every time the error: undefined reference to `gx_graphics_init(char const*)'

Then I tried to setup the environment with the graphics.o (there is gx_graphics_init located), but the result is the same.

Any solution or ideas?

Re: how to use OpenVG with C++

Posted: Wed Jan 09, 2013 12:36 pm
by -rst-
Clearly it is not linking in the graphics.o correctly... Maybe start with a copy of the hello_font makefile and make sure the 'include ../Makefile.include' points to correct directory (for example replace with 'include /opt/vc/src/hello_pi/Makefile.include').

Re: how to use OpenVG with C++

Posted: Wed Jan 09, 2013 1:43 pm
by tibi38
Dear rst,
i'm now a little bit farther and can compile and link a small sample.
(I use extern "C" to include the header files, after that I could link the files)
But now I got only an assert at s==0

Code: Select all

   GRAPHICS_RESOURCE_HANDLE img;
   uint32_t width, height;
   int LAYER=1;
   bcm_host_init();
   int s,t,u;
   char const fontPfad[] = ".";

   s = gx_graphics_init(".");
   assert(s == 0);

   t = graphics_get_display_size(0, &width, &height);
   assert(t == 0);
how can I check, that the bcm_host_init was proper called?

Re: how to use OpenVG with C++

Posted: Wed Jan 09, 2013 2:04 pm
by -rst-
Ah, the notorious C vs C++ name mangling issue... I have only been coding in C, so did not come to think of that. For me the examples and my derivatives have 'just worked' so far...

Someone mentioned somewhere on this forum that return values of some VC functions have changed in the latest releases - maybe it's that ...and actually if you look at the graphics.c, the comment for graphics_get_display_size says 'returns >=0 if it succeeded', so maybe try 'assert(s >= 0)'?

Re: how to use OpenVG with C++

Posted: Wed Jan 09, 2013 3:07 pm
by tibi38
hi rst,
I found the root cause: The missing ttf-file in the directory ;-)

Re: how to use OpenVG with C++

Posted: Thu Jan 10, 2013 6:27 am
by tibi38
Now, it is linkable. But it shows nothing.
So I start with a workaround: I use C in a service for the presentation layer and a c++-program for the rest. Means, I give up to mix a C and a C++ here

Re: how to use OpenVG with C++

Posted: Wed Jun 26, 2013 12:24 am
by caioporto
tibi38 ,

Can you show your solution for the undefined reference?

Thank you!

Re: how to use OpenVG with C++

Posted: Mon Jul 08, 2013 4:03 pm
by dhoyos
Hi,

Could you provide a little more insight into how were you able to use C++ and OpenVG? I'm having the same problem...

Re: how to use OpenVG with C++

Posted: Tue Jul 09, 2013 9:14 pm
by maxan
Using OpenVG should be no different than mixing C and C++... The C++ FAQ has a nice section on how to do it...

Here's a link to the relevant section (http://www.parashift.com/c++-faq/cpp-calls-c.html). The rest of the section is probably worthy of a read as well.