https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
k

Krystian

12/01/2023, 7:30 AM
I'm running into issues with cinterop and k/n 2.0-beta. I'm trying to run SDL2 on my Mac Studio M2 which I remember working way earlier, during compile I'm getting the following err:
Copy code
e: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors

The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
output:
ld: warning: ignoring file '/opt/homebrew/Cellar/sdl2/2.28.5/lib/libSDL2-2.0.0.dylib': found architecture 'arm64', required architecture 'x86_64'
ld: Undefined symbols:
  _SDL_CreateWindow, referenced from:
      _platform_SDL2_SDL_CreateWindow_wrapper374 in KotlinNativeTemplate.kexe.o
  _SDL_Init, referenced from:
      _platform_SDL2_SDL_Init_wrapper826 in KotlinNativeTemplate.kexe.o
  _SDL_Quit, referenced from:
      _platform_SDL2_SDL_Quit_wrapper830 in KotlinNativeTemplate.kexe.o
Why is K/N asking for x86_64 on ARM? My .def is inside this post
Copy code
package = platform.SDL2
headers = SDL2/SDL.h
compilerOpts = -D_THREAD_SAFE -I/opt/homebrew/include/ -I/opt/homebrew/include/SDL2/
linkerOpts = -L/opt/homebrew/lib/ -lSDL2
As you can see, my .def is standard as it should be
j

Jan Holešovský

12/01/2023, 7:46 AM
I suppose you might want to add x86_64 to EXCLUDED_ARCHS in the project setting in the project settings in Xcode?
k

Krystian

12/01/2023, 1:22 PM
Yeah, but the project is not connected to Xcode? I’m building this from IntelliJ. And I’m aware in the end it somehow communicates back to xcode for something
j

Jan Holešovský

12/01/2023, 1:51 PM
Yeah, I believe it runs the xcode in the end some way; I have EXCLUDED_ARCHS = x86_64; in my project.pbxproj to avoid this problem, but IIRC had configured that in there in Xcode some way; unfortunately cannot remember any details any more...
So - if you have project.pbxproj in your sources, I'd try to open that in xcode & do the modification. But if you don't have it at all, must be something else and I'm confused 🙂
k

Krystian

12/01/2023, 9:23 PM
Yeah, no I don't have this, so we're definitely talking about two different things
m

Miroslav Sobotka

12/05/2023, 9:14 AM
@Krystian what is your build.gradle.kts like? what architectures do you have?
build.gradle.kts
Copy code
plugins {
    kotlin("multiplatform") version "2.0.0-Beta1"
}

group = "cz.mira"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

kotlin {
    macosArm64 {
        compilations.getByName("main") {
            val sdl2 by cinterops.creating {

            }
        }

        binaries {
            executable {
                entryPoint = "main"
            }
        }
    }
}
sdl2.def (your file) main.kt
Copy code
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.toKString

@OptIn(ExperimentalForeignApi::class)
fun main() {
    println("Hello, Kotlin/Native! The SDL2 version " +
            "is ${platform.SDL2.SDL_GetRevision()?.toKString()}")
}
Copy code
10:34:00: Executing 'runReleaseExecutableMacosArm64'...

> Task :checkKotlinGradlePluginConfigurationErrors
> Task :cinteropSdl2MacosArm64
> Task :compileKotlinMacosArm64
> Task :xcodeVersion
> Task :linkReleaseExecutableMacosArm64

> Task :runReleaseExecutableMacosArm64
Hello, Kotlin/Native! The SDL2 version is SDL-release-2.28.5-0-g15ead9a40

BUILD SUCCESSFUL in 13s
6 actionable tasks: 6 executed
10:34:14: Execution finished 'runReleaseExecutableMacosArm64'.
k

Krystian

12/09/2023, 3:52 PM
Hey @Miroslav Sobotka Thank you! this was indeed what I was missing. I was under the assumption a gradle.properties that turns this off would work but I was wrong. However, for whatever reason be it using IntelliJ or Fleet when running runReleaseExecutable or Debug it skips that process
kodee happy 1
33 Views