0

When I compile a demo main.cpp, it failed because undefined reference to a_mtk_bt_service_init(), but I have found the symbol by

nm -D ./libmtk_bt_service_client.so|grep a_mtk_bt_service_init,

it's output is 0000000000004098 T a_mtk_bt_service_init,

I'm sure the compiler found the correct dynamic library by use command aarch64-poky-linux-g++ -print-file-name=libmtk_bt_service_client.so -o main main.cpp

This is the demo code main.cpp

void a_mtk_bt_service_init();
int main()
{
   a_mtk_bt_service_init();
   return 0;
}

and my compile command is

aarch64-poky-linux-g++ -mcpu=cortex-a72.cortex-a53+crypto -mtune=cortex-a72.cortex-a53 --sysroot=/home/sundq/code/newT9/T9-Amazon-Sdk/build/tmp/sysroots/aud8516-slc -o build/xx main.cpp -I../../include -lmtk_bt_service_client
sundq
  • 735
  • 2
  • 9
  • 28
  • `cortex-a72.cortex-a53+crypto` looks a bit unusual to me. Do you really want the `big.LITTLE system` variant? All the ARM systems I work on are little endian. What architectures does `nm` have to say about the files? Maybe try with `-march=armv8-a`. Also see [3.18.1 AArch64 Options](https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html) in the GCC manual. – jww Jan 12 '18 at 12:23

1 Answers1

0

The answer is here Call a C function from C++ code, that is, when c++ code call a c function, we also must add extern "C" before the declare of c function, so my function declare should like this

extern "C" void a_mtk_bt_service_init();

sundq
  • 735
  • 2
  • 9
  • 28