Kotlin-native: link to c++ library with extern "C" Wrapper?



I am trying to find a way to use a C++ library from kotlin native using a extern “C” Wrapper API.

Things work fine until the moment I try to produce the K/N executable, then I get the error message below abut a missing reference to the C++ new operator.

It looks like konanc does not link in the standard C++ runtime.

Is there a way to overcome this?

:compileKonanK-wrapperLinux_x64 FAILED
/tmp/included802814211042874970/libmyLib.a(MyWrapper.cpp.o):MyWrapper.cpp:function newMyClass: error: undefined reference to 'operator new(unsigned long)'
error: /home/vbaggiol/.konan/dependencies/target-gcc-toolchain-3-linux-x86-64/x86_64-unknown-linux-gnu/bin/ld.gold invocation reported errors

Here is the corresponding source code MyWrapper.cpp in my github project.

To reproduce this problem please checkout the two projects (tag forum-2018-07-15) from github into the /tmp directory
and follow the build instructions in the README.md files of each project:

I’m working on Ubuntu 16.04 LTS.

Many thanks in advance for your help!



linker options:
listOf("-lgcc", “–as-needed”, “-lgcc_s”, “–no-as-needed”, “-lc”, “-lgcc”, “–as-needed”, “-lgcc_s”, “–no-as-needed”)

You can try to add -lstdc++ into linkerOpts

Edit: Sorry - I was wrong: it’s in konan.properties:
-Bstatic -lstdc++ -Bdynamic -ldl -lm -lpthread --defsym __cxa_demangle=Konan_cxa_demangle

So don’t know.


Hi @msink,
thanks a lot for your help.
Indeed adding the following line to my wrapper.def helped!
linkerOpts.linux = -lstdc++

It now works, I pushed it to my github project and also updated the README to reflect this fact.

Thanks again!