سؤال

I think I spent most of yesterday unsuccessfully wrestling with this, any help would greatly appreciated and make me extremely happy! Even a next step to try to find the root of the issue is something I'm stuck on at the moment!

I have an Android 2.2 project that's trying to reference a prebuilt LuaJIT static library but ndk-build gives me this error:

test_android.cpp:25: undefined reference to `luaL_newstate' 

I built LuaJIT as liblua.a, I've placed that in the root of my JNI directory with the relevant headers. I've have one Android.mk as shown below:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := lua
LOCAL_SRC_FILES := liblua.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := test
LOCAL_CFLAGS    := -Werror
LOCAL_SRC_FILES := test_android.cpp
LOCAL_LDLIBS    := -llog -lGLESv2

LOCAL_STATIC_LIBRARIES := lua
include $(BUILD_SHARED_LIBRARY)

In test_andrdoid.cpp I've got this code:

extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}

void test()
{
    lua_State* lua = lua_open();
}

This seems like a linker error, for some reason the static library file is not being correctly referenced. But, to me, the makefile seems correct.

Any help would be greatly appreciated!

  1. To start with: is there anyway to see how everything is being linked together and if my shared library module is really get access to the static library?

Additional Information

Here's extra information that I think could be relevant!

Building the library

Maybe it's the static lib file that's not correct? (Is there anywhere I could download a prebuilt one to check?). I made it with this script (from the LuaJIT website). I'm using the latest stable LuaJIT, 1.1.8

NDK=/cygdrive/c/android-ndk-r8b
NDKABI=8
NDKVER=$NDK/toolchains/arm-linux-androideabi-4.4.3
NDKP=$NDKVER/prebuilt/linux-x86/bin/arm-linux-androideabi-
NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm"
make linux HOST_CC="gcc -m32" CROSS=$NDKP TARGET_FLAGS="$NDKF"

This builds fine and creates a liblua.a in the /src/ directory. (I ran nm on it and it lists out all the function prototypes I'd expect). I don't know if there's anything else I can do to ensure it's really a build for ARM?

NDKABI=8 means I'm targeting Android 2.2

Setting up the test Android Project

I create a brand new 2.2 android project using this command:

android create project --target 3 --name test --path . --activity TestActivity --package com.test

Target 3 maps to Android 2.2 on my system (using android list devices). I create the jni folder and have a test_android.h and test_android.cpp. Then I use ndk-build to build them - which works fine when I'm not trying to reference LuaJIT. When I do try and use Lua I get the following error:

Full Error Message

Cygwin         : Generating dependency file converter script
Compile++ thumb  : test <= test_android.cpp
In file included from jni/test_android.h:3:0, from jni/test_android.cpp:2:
    C:/android-ndk-r8b/platforms/android-8/arch-arm/usr/include/jni.h:592:13: note:
    the mangling of 'va_list' has changed in GCC 4.4
Prebuilt       : liblua.a <= jni/
StaticLibrary  : libstdc++.a
SharedLibrary  : libtest.so
obj/local/armeabi/objs/test/test_android.o: In function `test()':
C:\Users\Grrr\Documents\mycode\static_lib_test/jni/test_android.cpp:25: undefined reference to `luaL_newstate'
collect2: ld returned 1 exit status
/cygdrive/c/android-ndk-r8b/build/core/build-binary.mk:378: recipe for target `obj/local/armeabi/libtest.so' failed make: *** [obj/local/armeabi/libtest.so] Error 1

Most of the issues I've seen searching around are due to the local library include order, as I only have one library this shouldn't be an issue and suggests I've managed to get something more fundamental wrong :)

Update

I've since built normal Lua and added that as prebuilt static library and it works fine. I suspect its how I've built LuaJIT but I'm not sure how to correctly build it, or find a working prebuilt version.

هل كانت مفيدة؟

المحلول

The linking for this was fine, or at least the makefile was. The problem was the LuaJIT library wasn't built for ARM (I used objdump -a lualib.a, to check this). I downloaded the latest LuaJIT, ran the script under linux and got an ARM library. Everything links nicely now!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top