rubis-lab / CPSim_linux

8 stars 26 forks source link

TORCS compilation error " invalid use of incomplete type ‘png_struct' " #1

Open camilo-celis opened 7 years ago

camilo-celis commented 7 years ago

When trying to compile TORCS (the one recommended on the user_manual.pdf), it is very likely to encounter a compilation error with a message like:

img.cpp:101:20: error: invalid use of incomplete type ‘png_struct {aka struct png_struct_def}’

It seems that this is because the version used for TORCS assumed an older and deprecated API calls to libpng. Specifically the setjmp() function.

This can be solved by modifying the file: torcs/src/lib/tgfclient/img.cpp.

@@ -98,7 +98,7 @@ GfImgReadPng(const char *filename, int *widthp, int *heightp, float screen_gamma
                return (unsigned char *)NULL;
        }

-       if (setjmp(png_ptr->jmpbuf))
+       if (setjmp(png_jmpbuf(png_ptr)))

@@ -229,7 +229,7 @@ GfImgWritePng(unsigned char *img, const char *filename, int width, int height)

-       if (setjmp(png_ptr->jmpbuf)) {    
+       if (setjmp(png_jmpbuf(png_ptr))) {    
we123456 commented 7 years ago

Yes, this is a known issue. When you install 'libpng' library on Ubuntu, if you use 'apt-get install' command, this problem does not occur. However, if you install the latest version of 'libpng' library manually, you'll encounter this problem. Thanks for your reporting. We'll fix this issue.

camilo-celis commented 7 years ago

I reopened this issue as this might continue to be a problem for many. Especially as the Ubuntu repo updates the version for the libpng pulled by apt-get