Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

interop with package name failed #490

Closed
bennyhuo opened this issue Apr 15, 2017 · 6 comments
Closed

interop with package name failed #490

bennyhuo opened this issue Apr 15, 2017 · 6 comments

Comments

@bennyhuo
Copy link
Contributor

Hi, I tried konan with a interop config like this:

konanInterop {
    kotliner {
        defFile 'kotliner.def'
        includeDirs "src/c"
        pkg "cn.kotliner"
    }
}

while generating the cstubs, error occurred:

12:40:42: Executing external task 'build'...
:downloadKonanCompiler
Exception in thread "main" java.lang.Error: Process finished with non-zero exit code: 1
:genKotlinerInteropStubs
/Users/benny/Github/kotlin-native/dist/dependencies/clang-llvm-3.9.0-darwin-macos/bin/clang -isystem /Users/benny/Github/kotlin-native/dist/dependencies/clang-llvm-3.9.0-darwin-macos/lib/clang/3.9.0/include -B/Users/benny/Github/kotlin-native/dist/dependencies/target-sysroot-1-darwin-macos/usr/bin --sysroot=/Users/benny/Github/kotlin-native/dist/dependencies/target-sysroot-1-darwin-macos -mmacosx-version-min=10.11 -Isrc/c -emit-llvm -c /Users/benny/workspace/Kotlin-Imooc/code/KonanGradleDemo/build/konan/nativelibs/genKotlinerInteropStubs/cnkotlinerstubs.c -o /Users/benny/workspace/Kotlin-Imooc/code/KonanGradleDemo/build/konan/nativelibs/genKotlinerInteropStubs/cnkotlinerstubs.bc
/Users/benny/workspace/Kotlin-Imooc/code/KonanGradleDemo/build/konan/nativelibs/genKotlinerInteropStubs/cnkotlinerstubs.c:4:15: error: expected ';' after top level declarator
int32_t kni_cn.kotliner_factorial (int32_t n) {
              ^
              ;
1 error generated.
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.runExpectingSuccess(main.kt:106)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.runCmd(main.kt:152)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processLib(main.kt:382)
	at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.main(main.kt:37)
:genKotlinerInteropStubs FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':genKotlinerInteropStubs'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 8.251 secs
Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
12:40:50: External task execution finished 'build'.

The referred file "cnkotlinerstubs.c":

#include <stdint.h>
#include <cn_kotliner.h>

int32_t kni_cn.kotliner_factorial (int32_t n) {
    return (int32_t) (factorial((int)n));
}

Maybe the generated cstubs name should avoid using the package name or just replace '.' with '_' as jni does.

@vvlevchenko
Copy link
Contributor

vvlevchenko commented Apr 15, 2017

I believe dots in function names are not allowed by C compiler:

0:minamoto@minamoto-osx(0)# clang -o /dev/null -xc -c -
int dotty.function() {
  return 0;
}
<stdin>:1:10: error: expected ';' after top level declarator
int dotty.function() {
         ^
         ;
1 error generated.

@bennyhuo
Copy link
Contributor Author

bennyhuo commented Apr 15, 2017

@vvlevchenko
I KNOW what you said, but the c file is generated by konan plugin according to the pkg config.
Note that "cnkotlinerstubs.c" is generated when the gradle task "genXXXInteropStubs" executing and will be deleted if the cstubs.bc generated successfully.

@bennyhuo
Copy link
Contributor Author

@vvlevchenko

If the plugin generates invalid c codes, I don't think it's a good choice to close this issue at this moment. Any comments on this?

@vvlevchenko
Copy link
Contributor

vvlevchenko commented Apr 15, 2017

We will ensure issue will get fixed.

@vvlevchenko vvlevchenko reopened this Apr 15, 2017
@bennyhuo
Copy link
Contributor Author

I have found out that the generator tries to replace the "/" with "" in pkg, while the format of the pkg should be "x.y.z", so just replace the "." with "" may solve the problem.

SvyatoslavScherbina pushed a commit that referenced this issue Apr 17, 2017
…e should replace "." with "_" instead of "/". Related Issue: #490
@bennyhuo
Copy link
Contributor Author

This should be fixed by now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants