Running into this issue where cinterop generation ...
# kotlin-native
n
Running into this issue where cinterop generation for libjpeg fails with the following error:
Exception in thread "main" java.lang.Error: /usr/include/jpeglib.h:792:3: error: unknown type name 'size_t'
Below are the contents of the def file:
Copy code
headers = jpeglib.h
linkerOpts = -ljpeg
linkerOpts.linux_x64 = -L/usr/lib/x86_64-linux-gnu
The following include paths are used in the build file:
"/usr/include", "/usr/include/x86_64-linux-gnu"
Using headerFilter in the def file won't work since the header files are located in the system include directories (/usr/include and /usr/include/x86_64-linux-gnu).
j
Ehm, add`stdlib.h` or
stddef.h
before jpeglib.h ?
n
Adding any of the mentioned header files results in the following error appearing:
Exception in thread "main" java.lang.Error: /usr/include/jpeglib.h:916:52: error: unknown type name 'FILE'
As soon as one cinterop error is resolved another one appears in its place (whack a mole include errors) ­čśŽ .
Tried an alternative method with using a custom built libjpeg that is statically linked. Below is the portion of the build file that is used for linking the library:
Copy code
// ...            
cinterops.create("libjpeg") {
                val baseDir = "$homeDir/libjpeg_turbo-2.0.6/"
                includeDirs("$baseDir/include")
                extraOpts = listOf("-libraryPath", "$baseDir/lib/libjpeg.a")
            }
// ...
The def file only contains this single line:
headers = jpeglib.h
Unfortunately this method doesn't work, and the same error appears:
Exception in thread "main" java.lang.Error: /home/napperley/libjpeg_turbo-2.0.6/include/jpeglib.h:792:3: error: unknown type name 'size_t'
j
Don't really think your first approach is wrong, it's because when you import that jpeglib.h it does not allow for a "loading entrypoint" of the needed headers
Additionally to stdlib.h or stddef.h you need
Copy code
stdio.h
­čÖĆ 1
It's all about that you need to include all headers that jpeglib.h needs
Just continue adding additional headers until it is resolved.
From the looks of things the FILE dependency is at the very end of jpeglib.h so you should be close.
n
Bit of a trying process but got there in the end simple smile . Below is the updated contents of the def file:
Copy code
headers = stdio.h stdlib.h jpeglib.h
headerFilter = jpeglib.h
Hopefully only the API in jpeglib.h is exposed/indexed.