How do you include some cinterop headers in a libr...
# kotlin-native
a
How do you include some cinterop headers in a library? I've added the headers like this
Copy code
linuxX64 {
    val main by compilations.getting
    main.cinterops.create("x11") {
        defFile("src/linuxX64Main/cinterop/x11.def")
        compilerOpts.add("-I" + rootDir.resolve("include"))
    }
}
library compiles fine, and published to mavenLocal fine, but when some other project add it as a dependency and runs the linker, it produces the following
Copy code
> Task :linkReleaseExecutableLinuxX64
e: C:\Users\Animesh\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin/ld.lld invocation reported errors

The C:\Users\Animesh\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin/ld.lld command returned non-zero exit code: 1.
output:
ld.lld: error: undefined symbol: XOpenDisplay
>>> referenced by out
>>>               C:\Users\Animesh\AppData\Local\Temp\konan_temp3813013133705122841\result.o:(kfun:com.github.animeshz.keyboard.X11KeyboardHandler#prepare(){})

ld.lld: error: undefined symbol: XPeekEvent
>>> referenced by out
>>>               C:\Users\Animesh\AppData\Local\Temp\konan_temp3813013133705122841\result.o:(kfun:com.github.animeshz.keyboard.X11KeyboardHandler#readEvents(){})

ld.lld: error: undefined symbol: XCloseDisplay
>>> referenced by out
>>>               C:\Users\Animesh\AppData\Local\Temp\konan_temp3813013133705122841\result.o:(kfun:com.github.animeshz.keyboard.X11KeyboardHandler#cleanup(){})

> Task :linkReleaseExecutableLinuxX64 FAILED
Don't the c-interop symbols get shipped with the artifact?
n
Presumably a dynamic library is being used. If that is the case then each project using the library will need to have its own def file that supplies the compilerOpts, linkerOpts, and headers. Note that compilerOpts, and linkerOpts might differ between the library, and the projects using the library.