Hello, Is there a possibility to generate a .dyli...
# kotlin-native
t
Hello, Is there a possibility to generate a .dylib (or .so), which uses a header file but don’t include the library? I would like to compile a .dylib that will be used by Unity Engine. So I’ll be using the header file, but not it’s implementation, which will be provided by Unity.
I think the correct term is “linking”. I want to create a .dylib without linking its dependencies. (Like using
clang -c main.c
to generate the
.o
file). I have no idea what I am talking about 😅
b
You never need sources when linking dynamic lib. Just headers are fine
i.e. I believe you're already doing what you need without even realising
m
IIUC he wants not link, but build dynamic lib that will be linked to some application as plugin, and need to call some functions exported by that application. But yes - there shouldn't be any problems, just .h and .def files should be enough.
t
Thanks for the answers! I’ll dig into it a little bit more later.
So when I try to compile use
linkNative
I get an error saying
Copy code
ld: symbol(s) not found for architecture x86_64
But I don’t want it to try to include it. Currently in Gradle I have something like this
Copy code
macosX64("native") {
        compilations.getByName("main") {
            cinterops {
                val lib by creating {
                    defFile(project.file("src/nativeInterop/cinterop/lib/lib.def"))
                    compilerOpts("-Isrc/nativeInterop/cinterop/lib")
                    includeDirs.allHeaders("src/nativeInterop/cinterop/lib")
                }
            }
        }

        binaries {
            sharedLib {
                baseName = "MyLibrary"
            }
        }
    }
What should I be doing that I am missing?
m
What is passed to linker if said .so/.dylib/.dll is written on some other language, not Kotlin? Add same options in your .def file in
linkerOpts.linux
,
linkerOpts.osx
t
To compile without linking I do (main includes lib.h)
Copy code
clang -c main.c
Then when I want the bin
Copy code
clang main.o lib.dylib
Fnally, I found what I needed:
Copy code
binaries {
            sharedLib {
                baseName = "MyLibrary"
                linkerOpts("-Wl,-U,_add42")
            }
        }
Then I was able to run
Copy code
clang main.o lib.o libMyLibrary.dylib
i
I know this is old, but do you have any info that could help me set up using kotlin for unreal?