我需要编译一些 c/c++ 代码。使用 NDK 和 Cygwin 的工具,我不止一次想出了错误“未定义的引用”。大多数人说这是由于调用了一个 lib 文件未包含在源文件中的函数。但是,我对 c/c++ 知之甚少,而且错误日志给出了模糊的信息,所以我不知道哪个文件中的哪一行导致了问题,甚至不知道我真正需要的是哪个 lib 文件。
我希望我能找到一些工具或方法来处理此类问题,以便我可以找到错误行或获取有关错误的更多详细信息。
非常感谢。
安卓.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
include ../includeOpenCV.mk
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
#try to load OpenCV.mk from default install location
include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk
else
include $(OPENCV_MK_PATH)
endif
LOCAL_MODULE:=AvatarSpeak
LOCAL_SRC_FILES:=AvatarSpeak.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
$NDK/ndk-build V=1
$ $NDK/ndk-build V=1
rm -f ./libs/armeabi/lib*.so ./libs/armeabi-v7a/lib*.so ./libs/mips/lib*.so ./libs/x86/lib*.so
rm -f ./libs/armeabi/gdbserver ./libs/armeabi-v7a/gdbserver ./libs/mips/gdbserver ./libs/x86/gdbserver
rm -f ./libs/armeabi/gdb.setup ./libs/armeabi-v7a/gdb.setup ./libs/mips/gdb.setup ./libs/x86/gdb.setup
Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
mkdir -p ./libs/armeabi
install -p /cygdrive/d/android-ndk-r8b/prebuilt/android-arm/gdbserver/gdbserver ./libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
mkdir -p ./libs/armeabi
echo "set solib-search-path ./obj/local/armeabi" > ./libs/armeabi/gdb.setup
echo "directory D:/android-ndk-r8b/platforms/android-14/arch-arm/usr/include "../../OpenCV-2.3.1/share/OpenCV/../../include/opencv" "../../OpenCV- 2.3.1/share/OpenCV/../../include" D:/android-ndk-r8b/sources/cxx-stl/gnu- libstdc++/4.6/include D:/android-ndk-r8b/sources/cxx-stl/gnu- libstdc++/4.6/libs/armeabi/include jni" >> ./libs/armeabi/gdb.setup
SharedLibrary : libAvatarSpeak.so
/cygdrive/d/android-ndk-r8b/toolchains/arm-linux-androideabi- 4.6/prebuilt/windows/bin/arm-linux-androideabi-g++ -Wl,-soname,libAvatarSpeak.so -shared --sysroot=D:/android-ndk-r8b/platforms/android-14/arch-arm ./obj/local/armeabi/objs- debug/AvatarSpeak/com_huawei_avatar_AvatarSpeak.o ./obj/local/armeabi/libopencv_contrib.a ./obj/local/armeabi/libopencv_calib3d.a ./obj/local/armeabi/libopencv_objdetect.a ./obj/local/armeabi/libopencv_features2d.a ./obj/local/armeabi/libopencv_video.a ./obj/local/armeabi/libopencv_imgproc.a ./obj/local/armeabi/libopencv_highgui.a ./obj/local/armeabi/libopencv_ml.a ./obj/local/armeabi/libopencv_legacy.a ./obj/local/armeabi/libopencv_flann.a ./obj/local/armeabi/libopencv_core.a ./obj/local/armeabi/libopencv_androidcamera.a ./obj/local/armeabi/liblibjpeg.a ./obj/local/armeabi/liblibpng.a ./obj/local/armeabi/liblibtiff.a ./obj/local/armeabi/liblibjasper.a ./obj/local/armeabi/libzlib.a ./obj/local/armeabi/libgnustl_static.a -Wl,--no-undefined -Wl,-z,noexecstack -Wl,- z,relro -Wl,-z,now -LD:/android-ndk-r8b/platforms/android-14/arch-arm/usr/lib -llog -lc - lm -o obj/local/armeabi/libAvatarSpeak.so
./obj/local/armeabi/objs-debug/AvatarSpeak/AvatarSpeak.o: In function `Java_com_hachi_avatar_AvatarSpeak_speak':
D:\eclipse_workspace\TestSo/jni/com_hachi_avatar_AvatarSpeak.cpp:52: undefined reference to `Fap2Avi2D(char const*, char const*, char const*, char const*, char const*, int)'
collect2: ld returned 1 exit status
/cygdrive/d/android-ndk-r8b/build/core/build-binary.mk:378: recipe for target `obj/local/armeabi/libAvatarSpeak.so' failed
make: *** [obj/local/armeabi/libAvatarSpeak.so] Error 1
AvatarSpeak.cpp
if (fImage != NULL && fPot != NULL) {
bool sucavi = Fap2Avi2D(str3, str5, str4, str1, str2, -1);
LOGI("sucess and exit!");
} else {
LOGI("unsucess and exit!");
}
Animation2D_new.h(定义方法Fap2Avi2D的头文件)
#ifndef ANIMATION_2D_NEW_H_
#define ANIMATION_2D_NEW_H_
#include <vector>
#include <string>
#include "public.h"
#include "FaceExpressionEditor.h"
//#define __declspec(dllexport)
bool Fap2Avi2D(const char *fap_file,const char *avi_file,const char *wav_file, const char* image_file,const char *pot_file=NULL,int codec_type=-1);
...