Thanks,
Ido.
> Hi,
> dos anyone here have experiance with using libfov?
> I've had some problems understanding some of it.
Could you be more specific? Which parts you have problems with?
--
Radomir `The Sheep' Dopieralski
As far as i understand, libfov is in c, yet it lists several of its
function as requiring parameters of the mysterios 'map data structure'
& 'source data structure' - are these structs?
Where are they defined? The example (simple.cc) seems to give libfov
instances of c++ classes... but how can a c lib accept a c++ class?
Thanks,
Ido Yehieli.
> For instance, What are these strange "void *map" and "void *source" I
> keep seeing?
These are generic helper pointers. They are not used by the library
itself, but instead passed as-is to the helper functions you provide.
You are supposed to define them by yourself, or just use NULL if you
don't need them.
> As far as i understand, libfov is in c, yet it lists several of its
> function as requiring parameters of the mysterios 'map data structure'
> & 'source data structure' - are these structs?
As you can see, these are void *, so they can be anything, really.
Depends on what you need.
> Where are they defined? The example (simple.cc) seems to give libfov
> instances of c++ classes... but how can a c lib accept a c++ class?
It just passes them trough, so it doesn't care what they are.
> These are generic helper pointers. They are not used by the library
> itself, but instead passed as-is to the helper functions you provide.
Normally speaking these helper function will be apply & opaque, right?
Like in the example.
it really looks quite simpe to use now that I understand the purpose of
map & src - I kept searching the fov.c/fov.h files for clues as to what
they were supposed to do...
> Thanks Sheep, it all makes sense now. I will continue playing with the
> example when I get back from work, I think these were the only things I
> didn't understand.
Glad I could help.
>> These are generic helper pointers. They are not used by the library
>> itself, but instead passed as-is to the helper functions you provide.
>
> Normally speaking these helper function will be apply & opaque, right?
> Like in the example.
Right.
> it really looks quite simpe to use now that I understand the purpose of
> map & src - I kept searching the fov.c/fov.h files for clues as to what
> they were supposed to do...
I think libfov could use a little better documentation. Wonder if we could
do it collaboratively on rogue basin?
I think that is a good idea.
i have this very minimal file:
***begin of libfov-test.cc***
#include <fov/fov.h>
int
main(){
return 0;
}
***end of libfov-test.cc***
And this makefile:
***begin of Makefile***
VPATH= src:../headers
bin-dir= bin/
libfov-libs= -L/usr/local/lib/ -lfov
all: libfov-test
libfov-test: libfov-test.o
$(CC) $(CFLAGS) -o $(bin-dir)$@ $(libfov-libs) libfov-test.o
***end of Makefile***
Now when I type make everything compiles just fine.
However, I soon encounter 2 problems:
1. if I change the file to include something from libfov, like that:
***begin of libfov-test.cc***
#include <fov/fov.h>
int
main(){
fov_settings_type settings;
fov_settings_init(&settings);
return 0;
}
***end of libfov-test.cc***
and then 'make', i get the following error:
libfov-test.o: In function `main':
libfov-test.cc:(.text+0x24): undefined reference to `fov_settings_init'
libfov-test.o:(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [libfov-test] Error 1
I assume that probably means I'm linking incorrectly?
2. if I go back to the first way the file was and I change the name to
libfov-test.c in order to compile it as a c program rather then a c++
program, i get the following:
In file included from src/libfov-test.c:1:
/usr/local/include/fov/fov.h:68: error: syntax error before 'bool'
/usr/local/include/fov/fov.h:83: error: syntax error before '}'
token
/usr/local/include/fov/fov.h:102: error: syntax error before '*'
token
/usr/local/include/fov/fov.h:123: error: syntax error before '*'
token
/usr/local/include/fov/fov.h:150: error: syntax error before '*'
token
/usr/local/include/fov/fov.h:161: error: syntax error before '*'
token
/usr/local/include/fov/fov.h:169: error: syntax error before '*'
token
/usr/local/include/fov/fov.h:169: error: syntax error before ')'
token
/usr/local/include/fov/fov.h:177: error: syntax error before '*'
token
/usr/local/include/fov/fov.h:177: error: syntax error before ')'
token
/usr/local/include/fov/fov.h:185: error: syntax error before '*'
token
/usr/local/include/fov/fov.h:197: error: syntax error before '*'
token
/usr/local/include/fov/fov.h:218: error: syntax error before '*'
token
make: *** [libfov-test.o] Error 1
Why would it need to be compiled as a c++ program?
Thanks in advance,
Ido Yeheili
> ok, 2 more problems I've had- this time it has to do with linking
> against libfov (I'm sorry if this is really trivial, I'm quite the
> beginner in c - more of a python/java person...):
> i have this very minimal file:
[...]
> And this makefile:
> ***begin of Makefile***
> VPATH= src:../headers
What does this line mean? I don;t understand this syntex :/
> bin-dir= bin/
> libfov-libs= -L/usr/local/lib/ -lfov
>
> all: libfov-test
> libfov-test: libfov-test.o
> $(CC) $(CFLAGS) -o $(bin-dir)$@ $(libfov-libs) libfov-test.o
> ***end of Makefile***
>
> Now when I type make everything compiles just fine.
It doesn't use any symbols from the library, it will compile
even when you don't link the library in.
> However, I soon encounter 2 problems:
> 1. if I change the file to include something from libfov, like that:
[...]
> and then 'make', i get the following error:
> libfov-test.o: In function `main':
> libfov-test.cc:(.text+0x24): undefined reference to `fov_settings_init'
> libfov-test.o:(.eh_frame+0x11): undefined reference to
> `__gxx_personality_v0'
> collect2: ld returned 1 exit status
> make: *** [libfov-test] Error 1
> I assume that probably means I'm linking incorrectly?
Yes, but no idea what's wrong :/
Honestly, I always used libfov by compiling it into an .o file
and then linking together with the rest of my objects. Can you
make sure that the libfov file really exists in the directory
you specfied?
> 2. if I go back to the first way the file was and I change the name to
> libfov-test.c in order to compile it as a c program rather then a c++
> program, i get the following:
>
> In file included from src/libfov-test.c:1:
> /usr/local/include/fov/fov.h:68: error: syntax error before 'bool'
This must be an error. Try to add:
#define bool int
somewhere in your code, before you include the fov.h, or just include
some ready-to-use bool definition from your system. AFAIR curses
defines it.
> /usr/local/include/fov/fov.h:83: error: syntax error before '}'
[...]
> /usr/local/include/fov/fov.h:218: error: syntax error before '*'
> token
> make: *** [libfov-test.o] Error 1
These are the result of the first error.
> Why would it need to be compiled as a c++ program?
It doesn't. It seems that Puyo always used it together with curses or
other library that defines 'bool' and forgot that it isn't defined in
C by default. It's a bug, of course.
the VPATH= src:../headers just tells make to search for my sources in
the 'src' directory instead of at the current directory, where the
makefile is.
I've solved my first problem by myself by using libtool like was done
in the example. My new make file looks something like this:
***begin of Makefile***
CFLAGS= -Wall -std=c99 -pedantic
VPATH= src:../headers
bin-dir= bin/
libtool-path= /usr/bin/libtool
fov-libs= /usr/local/lib/libfov.la
all: ln-libtool libfov-test
libfov-test: libfov-test.o
$(shell) ./libtool --mode=link $(CC) $(CFLAGS) -o $(bin-dir)$@ $<
$(fov-libs)
ln-libtool:
$(shell) ln -f $(libtool-path)
***end of Makefile***
As for the second problem- your solution almost fixed it ;). I had to
add #include <math.h> and link against the math lib (adding -lm to the
end of fov-libs= /usr/local/lib/libfov.la) in order for libfov to be
able to use sqrt.
I am now happily able to use libfov :)