Hi, I'm trying to get FFI working to interface with a C++ library (
https://support.bayesfusion.com/docs/SMILE/) I'd like to use in a Flutter app. The library is distributed as a set of .h headers and a static libsmile.a file containing the proprietary engine.
I've successfully been through the Flutter C-FFI tutorial, and have followed up by writing an example C++ function in a file named smile.cpp which calls the library. I've tested this separately by compiling with g++ and it works correctly.
When I try to incorporate into the build process indicated by the Flutter C-FFI tutorial I hit a problem - certain symbols are undefined and the linker is suggesting mangled names from the static library, i.e. in the below DSL_network <-> __ZN11DSL_networkC1Ev:
> Build command failed.
Error while executing process /Users/jamie/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/jamie/work/flutter_app/native_add/android/.cxx/cmake/debug/armeabi-v7a --target smile_test}
[1/1] Linking CXX shared library /Users/jamie/work/flutter_app/native_add/example/build/native_add/intermediates/cmake/debug/obj/armeabi-v7a/libsmile_test.so
FAILED: : && /Users/jamie/Library/Android/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi16 --gcc-toolchain=/Users/jamie/Library/Android/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/jamie/Library/Android/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libsmile_test.so -o /Users/jamie/work/flutter_app/native_add/example/build/native_add/intermediates/cmake/debug/obj/armeabi-v7a/libsmile_test.so CMakeFiles/smile_test.dir/Users/jamie/work/flutter_app/native_add/ios/Classes/smile.cpp.o -L/Users/jamie/work/flutter_app/native_add/android/../ios/lib/smile-1.6.0-B -lsmile -latomic -lm && :
ld: error: undefined symbol: DSL_network::DSL_network()
>>> referenced by smile.cpp:11 (/Users/jamie/work/flutter_app/native_add/ios/Classes/smile.cpp:11)
>>> CMakeFiles/smile_test.dir/Users/jamie/work/flutter_app/native_add/ios/Classes/smile.cpp.o:(test_network_load)
>>> did you mean: __ZN11DSL_networkC1Ev
>>> defined in: /Users/jamie/work/flutter_app/native_add/android/../ios/lib/smile-1.6.0-B/libsmile.a
I'm not very familiar with C/C++ interop but I think this is probably related to name mangling?
Can anyone point me in the right direction to resolve?I'm hoping I'm missing something obvious from my CMakeLists.txt which is currently:
cmake_minimum_required(VERSION 3.4.1)add_definitions(-DNDEBUG)set(SMILE_PATH ../ios/lib/smile-1.6.0-B)
include_directories(${SMILE_PATH})
link_directories(${SMILE_PATH})
add_library(smile_test SHARED ../ios/Classes/smile.cpp)
target_link_libraries(smile_test smile)