Android NDK CMakeLists.txt: error: undefined reference to: -
i've looked around i've been able find solutions use android.mk
, application.mk
. right in thinking using cmakelists.txt
don't need either of files? first venture using android ndk.
i've based cmakelists.txt
off of superpoweredexample
, have called library nativelib
. seems .cpp file cannot pick references in header file. doing wrong? builds fine throws these errors on compilation.
cmakelists.txt:
cmake_minimum_required(version 3.4.1) # creates , names library, sets either static # or shared, , provides relative paths source code. # can define multiple libraries, , cmake builds you. # gradle automatically packages shared libraries apk. add_library( # sets name of library. nativelib # sets library shared library. shared # provides relative path source file(s). # associated headers in same location source # file automatically included. g:/git/ndktest/app/src/main/jni/nativelib.cpp ) # searches specified prebuilt library , stores path # variable. because system libraries included in search path # default, need specify name of public ndk library # want add. cmake verifies library exists before # completing build. find_library( # sets name of path variable. log-lib # specifies name of ndk library # want cmake locate. log ) # specifies libraries cmake should link target library. # can link multiple libraries, such libraries define in # build script, prebuilt third-party libraries, or system libraries. target_link_libraries( # specifies target library. nativelib # links target library log library # included in ndk. ${log-lib} ) ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // below here copy , pasted superpoweredexample ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// set( path_to_superpowered "c:/users/j/downloads/superpowered/superpowered" ) message(${android_abi}) file(glob cpp_files "*.cpp") add_library( superpoweredexample shared ${cpp_files} ${path_to_superpowered}/androidio/superpoweredandroidaudioio.cpp ) include_directories(src/main/jni) include_directories(${path_to_superpowered}) target_link_libraries( superpoweredexample log android opensles ${path_to_superpowered}/libsuperpoweredandroid${android_abi}.a nativelib )
stacktrace:
error:failure: build failed exception. * went wrong: execution failed task ':app:externalnativebuilddebug'. > build command failed. error while executing 'g:\sdk1\cmake\3.6.3155560\bin\cmake.exe' arguments {--build g:\git\ndktest\app\.externalnativebuild\cmake\debug\x86 --target nativelib} [1/2] building cxx object cmakefiles/nativelib.dir/nativelib.cpp.o [2/2] linking cxx shared library g:\git\ndktest\app\build\intermediates\cmake\debug\obj\x86\libnativelib.so failed: cmd.exe /c "cd . && g:\sdk1\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target i686-none-linux-android -gcc-toolchain g:/sdk1/ndk-bundle/toolchains/x86-4.9/prebuilt/windows-x86_64 --sysroot=g:/sdk1/ndk-bundle/platforms/android-16/arch-x86 -fpic -g -dandroid -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -wa,--noexecstack -wformat -werror=format-security -fno-exceptions -fno-rtti -g -dandroid -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -wa,--noexecstack -wformat -werror=format-security -fno-exceptions -fno-rtti -fsigned-char -inull -o0 -fno-limit-debug-info -o0 -fno-limit-debug-info -wl,--build-id -wl,--warn-shared-textrel -wl,--fatal-warnings -wl,--no-undefined -wl,-z,noexecstack -qunused-arguments -wl,-z,relro -wl,-z,now -wl,--build-id -wl,--warn-shared-textrel -wl,--fatal-warnings -wl,--no-undefined -wl,-z,noexecstack -qunused-arguments -wl,-z,relro -wl,-z,now -shared -wl,-soname,libnativelib.so -o g:\git\ndktest\app\build\intermediates\cmake\debug\obj\x86\libnativelib.so cmakefiles/nativelib.dir/nativelib.cpp.o -llog -lm "g:/sdk1/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/libgnustl_static.a" && cd ." g:\git\ndktest\app\src\main\jni/nativelib.cpp:16: error: undefined reference 'superpoweredroll::superpoweredroll(unsigned int)' g:\git\ndktest\app\src\main\jni/nativelib.cpp:17: error: undefined reference 'superpoweredfilter::superpoweredfilter(superpoweredfiltertype, unsigned int)' g:\git\ndktest\app\src\main\jni/nativelib.cpp:18: error: undefined reference 'superpoweredflanger::superpoweredflanger(unsigned int)' g:\git\ndktest\app\src\main\jni/nativelib.cpp:19: error: undefined reference 'superpoweredrecorder::superpoweredrecorder(char const*, unsigned int, unsigned int)' g:\git\ndktest\app\src\main\jni/nativelib.cpp:21: error: undefined reference 'superpoweredandroidaudioio::superpoweredandroidaudioio(int, int, bool, bool, bool (*)(void*, short*, int, int), void*, int, int, int)' g:\git\ndktest\app\src\main\jni/nativelib.cpp:28: error: undefined reference 'superpoweredrecorder::stop()' g:\git\ndktest\app\src\main\jni/nativelib.cpp:30: error: undefined reference 'superpoweredrecorder::start(char const*)' g:\git\ndktest\app\src\main\jni/nativelib.cpp:37: error: undefined reference 'superpoweredrecorder::process(float*, float*, unsigned int)' g:\git\ndktest\app\src\main\jni/nativelib.cpp:38: error: undefined reference 'superpoweredfloattoshortint(float*, short*, unsigned int, unsigned int)' g:\git\ndktest\app\src\main\jni/nativelib.cpp:43: error: undefined reference 'superpoweredandroidaudioio::~superpoweredandroidaudioio()' g:\git\ndktest\app\src\main\jni/nativelib.cpp:44: error: undefined reference 'superpoweredrecorder::~superpoweredrecorder()' clang++.exe: error: linker command failed exit code 1 (use -v see invocation) ninja: build stopped: subcommand failed. * try: run --stacktrace option stack trace. run --info or --debug option more log output.
changed name native-lib nativelib, same error.
i have feeling error around target_link_libraries()
of cmakelists.txt
. trying link nativelib
code existing superpoweredexample
code.
i think linking "nativelib" happens before linking superpowered example, therefore linker can't find superpowered parts used "nativelib".
Comments
Post a Comment