【问题标题】:Kotlin/Native OpenGL interopKotlin/Native OpenGL 互操作
【发布时间】:2023-04-10 10:22:02
【问题描述】:

我正在尝试设置使用 OpenGL C 库的 kotlin/native 项目。

操作系统:ArchLabs,linux 5.1.15(与 arch 共享存储库)

安装的包:glu、glew、freeglut、glfw

在我的 main() 中只有一个函数被调用(它是从 samples 复制的):

glutInit(argc.ptr, null)

我的项目中没有开箱即用的 OpenGL 支持,所以我决定制作 opengl.def:

package = platform.OpenGL
headers = GL/glut.h

compilerOpts = -I/usr/include
$ ls /usr/include/GL  
freeglut_ext.h  glcorearb.h  gl.h         glu_mangle.h  glxext.h  glx_mangle.h  glxtokens.h  wglew.h
freeglut.h      glew.h       gl_mangle.h  glut.h        glx.h     glxmd.h       internal
freeglut_std.h  glext.h      glu.h        glxew.h       glxint.h  glxproto.h    osmesa.h

这是我的gradle.build.kts

plugins {
    id("org.jetbrains.kotlin.multiplatform") version "1.3.41"
}

repositories {
    mavenCentral()
}

kotlin {
    linuxX64("opengl") {
        val main by compilations.getting
        val opengl by main.cinterops.creating

        binaries {
            executable {
                entryPoint = "opengl.main"
            }
        }
    }
}

生成了一个 .kt 文件:build/classes/.../OpenGL/OpenGL.kt,其中包含 glutInit 函数的定义(嗯,我猜更多是参考)

这是runReleaseExecutableOpengl的输出

> Configure project :
Kotlin Multiplatform Projects are an experimental feature.

> Task :cinteropOpenglOpengl

> Task :linkReleaseExecutableOpengl
/home/Opengl/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/ld.lld: error: undefined symbol: glutInit
>>> referenced by ld-temp.o
>>>               /tmp/konan_temp5065866915785286367/combined.o:(platform_OpenGL_kniBridge520)
e: /home/Opengl/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/ld.lld invocation reported errors

> Task :linkReleaseExecutableOpengl FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':linkReleaseExecutableOpengl'.

> Process 'command '/usr/lib/jvm/java-11-openjdk/bin/java'' finished with non-zero exit value 1

有办法解决吗?我最好的猜测是我必须安装mingw-w64-* 包,例如mingw-w64-freeglut。是这样吗?也可能是我指向了错误的标头(我还没有真正接触 C,而且我已经很久没有使用 C++了)并且它找不到这些标头的实现。

提前致谢!

【问题讨论】:

    标签: opengl kotlin kotlin-native


    【解决方案1】:

    您需要在 def 文件中使用linkerOpts = -L/usr/lib -lglut,以动态链接 freeglut。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-22
      • 2019-07-15
      • 2011-12-03
      • 2013-07-27
      • 1970-01-01
      • 2019-11-05
      • 1970-01-01
      • 2020-06-21
      相关资源
      最近更新 更多