Skip to content
This repository has been archived by the owner on Feb 21, 2021. It is now read-only.

Properly implement the C interfaces in progeo #16

Closed
ojgarciab opened this issue Mar 24, 2015 · 1 comment
Closed

Properly implement the C interfaces in progeo #16

ojgarciab opened this issue Mar 24, 2015 · 1 comment

Comments

@ojgarciab
Copy link
Collaborator

When compiling code there is some warnings that have to be avoided:

Scanning dependencies of target progeo
[ 29%] Building C object src/stable/libs/progeo/CMakeFiles/progeo.dir/progeo.c.o
/home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.c:581:6: warning: conflicting types for ‘update_camera_matrix’ [enabled by default]
 void update_camera_matrix(TPinHoleCamera *camera)
      ^
/home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.c:345:2: note: previous implicit declaration of ‘update_camera_matrix’ was here
  update_camera_matrix(&camera);
  ^
Linking C static library libprogeo.a
[ 29%] Built target progeo
Scanning dependencies of target progeoshare
[ 29%] Building C object src/stable/libs/progeo/CMakeFiles/progeoshare.dir/progeo.c.o
/home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.c:581:6: warning: conflicting types for ‘update_camera_matrix’ [enabled by default]
 void update_camera_matrix(TPinHoleCamera *camera)
      ^
/home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.c:345:2: note: previous implicit declaration of ‘update_camera_matrix’ was here
  update_camera_matrix(&camera);
  ^
Linking C shared library libprogeo.so

This problem is due to lack of definition of the functions in C compiler at the header file:

#ifdef __cplusplus
extern "C" {
    TPinHoleCamera xmlReader(TPinHoleCamera* camera, const char *filename);
    void xmlWriter(TPinHoleCamera camera, const char *filename);
    void update_camera_matrix(TPinHoleCamera *camera);
    void reverse_update_camera_matrix(TPinHoleCamera *camera);
    void update_stereocamera_matrix(TPinHoleStereocamera *stereo);
    int project(HPoint3D in, HPoint2D *out, TPinHoleCamera camera);
    int backproject(HPoint3D *out, HPoint2D in, TPinHoleCamera camera);
    int displayline(HPoint2D p1, HPoint2D p2, HPoint2D *a, HPoint2D *b, TPinHoleCamera camera);
    void display_camerainfo(TPinHoleCamera camera);
}
#endif

It could be fixed creating a "else" case:

#ifdef __cplusplus
extern "C" {
    TPinHoleCamera xmlReader(TPinHoleCamera* camera, const char *filename);
    void xmlWriter(TPinHoleCamera camera, const char *filename);
    void update_camera_matrix(TPinHoleCamera *camera);
    void reverse_update_camera_matrix(TPinHoleCamera *camera);
    void update_stereocamera_matrix(TPinHoleStereocamera *stereo);
    int project(HPoint3D in, HPoint2D *out, TPinHoleCamera camera);
    int backproject(HPoint3D *out, HPoint2D in, TPinHoleCamera camera);
    int displayline(HPoint2D p1, HPoint2D p2, HPoint2D *a, HPoint2D *b, TPinHoleCamera camera);
    void display_camerainfo(TPinHoleCamera camera);
}
#else
TPinHoleCamera xmlReader(TPinHoleCamera* camera, const char *filename);
void xmlWriter(TPinHoleCamera camera, const char *filename);
void update_camera_matrix(TPinHoleCamera *camera);
void reverse_update_camera_matrix(TPinHoleCamera *camera);
void update_stereocamera_matrix(TPinHoleStereocamera *stereo);
int project(HPoint3D in, HPoint2D *out, TPinHoleCamera camera);
int backproject(HPoint3D *out, HPoint2D in, TPinHoleCamera camera);
int displayline(HPoint2D p1, HPoint2D p2, HPoint2D *a, HPoint2D *b, TPinHoleCamera camera);
void display_camerainfo(TPinHoleCamera camera);
#endif

But this change will fire a critical compile error:

[ 29%] Built target JderobotInterfaces
Scanning dependencies of target progeo
[ 29%] Building C object src/stable/libs/progeo/CMakeFiles/progeo.dir/progeo.c.o
/home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.c: In function ‘reverse_update_camera_matrix’:
/home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.c:536:2: error: incompatible type for argument 3 of ‘backproject’
  backproject(&out, in, camera);
  ^
In file included from /home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.c:23:0:
/home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.h:105:5: note: expected ‘TPinHoleCamera’ but argument is of type ‘struct TPinHoleCamera *’
 int backproject(HPoint3D *out, HPoint2D in, TPinHoleCamera camera);
     ^
/home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.c:561:2: error: incompatible type for argument 3 of ‘backproject’
  backproject(&p3, p2_rt_complete, camera);
  ^
In file included from /home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.c:23:0:
/home/redstar/Documentos/jderobot/temp/JdeRobot/src/stable/libs/progeo/progeo.h:105:5: note: expected ‘TPinHoleCamera’ but argument is of type ‘struct TPinHoleCamera *’
 int backproject(HPoint3D *out, HPoint2D in, TPinHoleCamera camera);
     ^
make[2]: *** [src/stable/libs/progeo/CMakeFiles/progeo.dir/progeo.c.o] Error 1
make[1]: *** [src/stable/libs/progeo/CMakeFiles/progeo.dir/all] Error 2
make: *** [all] Error 2

So we need to change proceo.c too:

@@ -533,7 +533,7 @@
    in.y = 0;
    in.h = 0;

-   backproject(&out, in, camera);
+   backproject(&out, in, *camera);

    camera->foa.X = out.X;
    camera->foa.Y = out.Y;
@@ -558,7 +558,7 @@
    p2_rt_complete.y = 1;
    p2_rt_complete.h = 0;

-   backproject(&p3, p2_rt_complete, camera);
+   backproject(&p3, p2_rt_complete, *camera);

    TPinHoleCamera cameraAux; 
    cameraAux = *camera;

But I don't want to upload this fix because I don't use progeo.

Please, could someone that use progeo test my patch?

Thanks!

@varhub
Copy link
Contributor

varhub commented Nov 23, 2015

Hello @ojgarciab, I checked it and you was right, even in dangerous consideration of change:
_any code that uses progeo with this compiler bug is using an incorrect implicit API_
discussion at #18

@fqez fqez closed this as completed in b786d00 Dec 1, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants