Hey guys. How do I say Kotlin/Native to link my cI...
# kotlin-native
s
Hey guys. How do I say Kotlin/Native to link my cInterop library to link against the C++11 standard library ? I'm having a whole lot of
undefined symbol: std::__cxx11::basic_string...
error at linkage. My library is a C interface to some OpenCV features. I have
libopencv-dev
installed on my computer. Because my C wrapper transforms
const char*
into
std::string
, I can't compile my it with
-D_GLIBCXX_USE_CXX11_ABI=0
(then I get undefined symbol errors on all OpenCV method I use that takes a
std::string
because the ABI is different). The only solution I see is to download and re-compile OpenCV and all its dependencies with
-D_GLIBCXX_USE_CXX11_ABI=0
, which is an enormous hassle. Is there a way to instruct the Kotlin/Native linker to link against the C++11 standard library ?
n
If I remember correctly there is a cinterop flag that tells Kotlin to not transform const chars into Strings. Not sure if that helps
s
Nope. Sorry. This is about c-interop generated API. This is about C++11 ABI.
n
Oh I read it wrong. I thought cinterop was the one transforming chars into Strings
πŸ˜‰ 1
m
Shouldn't libopencv-dev be compiled with your system compiler and therefore with your system stdlibc++ and its ABI? Also simply setting that flag won't change the ABI. You'd actually have to recompile GCC and libstdc++ to do that since libstdc++.so would also have to change. I think there is something else going on. Maybe you need to explicitly specify -lstdc++ in the linker flags? I don't know if kotlin does that for you
s
-lstdc++
doesn't change anything.
I'm able to compile a demo C++ command line app from the static library, no problems there.
The problem only arises when K/N compiler tries to link its C-Interop lib with my static lib.
m
Does Kotlin native even use the system compiler actually?
s
Nope πŸ˜‰ It uses its own compiler toolchain
m
Yeah that's probably where the problem lies
If you know what the path to the compiler toolchain is that it downloads you can run ./gcc -v and it'll show you with what config it was compiled with and compare it to your system compiler
Might want to raise an issue on Github. On Linux they have to use the system compiler I am pretty sure. Although that makes shipping their own runtime a pain possibly
n
On the Linux side Kotlin Native uses its own compiler. Below are some of the contents from the toolchain for the linuxX64 target:
Copy code
target-gcc-toolchain-3-linux-x86-64/bin
β”œβ”€β”€ x86_64-unknown-linux-gnu-addr2line
β”œβ”€β”€ x86_64-unknown-linux-gnu-ar
β”œβ”€β”€ x86_64-unknown-linux-gnu-as
β”œβ”€β”€ x86_64-unknown-linux-gnu-c++
β”œβ”€β”€ x86_64-unknown-linux-gnu-cc -> x86_64-unknown-linux-gnu-gcc
β”œβ”€β”€ x86_64-unknown-linux-gnu-c++filt
β”œβ”€β”€ x86_64-unknown-linux-gnu-cpp
β”œβ”€β”€ x86_64-unknown-linux-gnu-ct-ng.config
β”œβ”€β”€ x86_64-unknown-linux-gnu-dwp
β”œβ”€β”€ x86_64-unknown-linux-gnu-elfedit
β”œβ”€β”€ x86_64-unknown-linux-gnu-g++
β”œβ”€β”€ x86_64-unknown-linux-gnu-gcc
β”œβ”€β”€ x86_64-unknown-linux-gnu-gcc-4.8.5
β”œβ”€β”€ x86_64-unknown-linux-gnu-gcc-ar
β”œβ”€β”€ x86_64-unknown-linux-gnu-gcc-nm
β”œβ”€β”€ x86_64-unknown-linux-gnu-gcc-ranlib
β”œβ”€β”€ x86_64-unknown-linux-gnu-gcov
β”œβ”€β”€ x86_64-unknown-linux-gnu-gdb
β”œβ”€β”€ x86_64-unknown-linux-gnu-gprof
β”œβ”€β”€ x86_64-unknown-linux-gnu-ld
β”œβ”€β”€ x86_64-unknown-linux-gnu-ld.bfd
β”œβ”€β”€ x86_64-unknown-linux-gnu-ldd
β”œβ”€β”€ x86_64-unknown-linux-gnu-ld.gold
β”œβ”€β”€ x86_64-unknown-linux-gnu-nm
β”œβ”€β”€ x86_64-unknown-linux-gnu-objcopy
β”œβ”€β”€ x86_64-unknown-linux-gnu-objdump
β”œβ”€β”€ x86_64-unknown-linux-gnu-populate
β”œβ”€β”€ x86_64-unknown-linux-gnu-ranlib
β”œβ”€β”€ x86_64-unknown-linux-gnu-readelf
β”œβ”€β”€ x86_64-unknown-linux-gnu-size
β”œβ”€β”€ x86_64-unknown-linux-gnu-strings
└── x86_64-unknown-linux-gnu-strip
All of this comes from the ~/.konan/dependencies directory.
m
Yeah that's an "ancient" version of GCC that doesn't use C++11 ABI. Any Linux distro that uses GCC 5 or higher will basically not be able to link its system libraries with Kotlin native I believe. Seems to be quite the huge oversight.
n
One of the big advantages with Kotlin Native having it own toolchain is that setting up the toolchain is quick and easy. Its all automated by Kotlin Native for you 😁 .
m
Better to be functional than beautiful