How to run a C language program in Android

Source: Internet
Author: User

Problem Description:

I use mini6410 to develop a SQLite database program, under the MINI6410 Linux system has been able to run successfully. Because Android is also using the Linux kernel, I take it for granted that the same method of porting the program to MINI6410 's Android system can run successfully, But when I ran the program, I was prompted that I couldn't find the executable file (Xlisten-arm is a cross-compiled executable):

/#./xlisten-arm
/system/bin/sh:./xlisten-arm:not found

1. Explore:

The web search was initially thought to be a result of the incomplete library file, so the dynamic link library needed to view the executable file Xlisten-arm:

Execute statement:

  1. # arm-linux-readelf-a./xlisten-arm | grep "Shared"
  2. 0x00000001 (NEEDED) Shared library: [libsqlite3.so.0]
  3. 0x00000001 (NEEDED) Shared library: [libm.so.6]
  4. 0x00000001 (NEEDED) Shared library: [Libcrypt.so.1]
  5. 0x00000001 (NEEDED) Shared library: [libpthread.so.0]
  6. 0x00000001 (NEEDED) Shared library: [Libdl.so.2]
  7. 0x00000001 (NEEDED) Shared library: [libc.so.6]

Know the required dynamic link library, to the Android file system to follow the write library file, in the directory/system/lib, really missing the corresponding library file, so that found the root of my problem, in the copy of the corresponding library files in order to preserve the original properties, but also deliberately used

    1. #cp-a filename dir

Who knows to add these libraries are still useless!

It seems not only that the library file is missing, and generally, if the problem is caused by the lack of a library file, the terminal will prompt us to link a library file without finding the library file.

2. Correct solution:

Choose static compilation When compiling the program, that is, using the option-static

I'm modifying the Cflag variable in the makefile file

CFLAGS =-wall

Switch

CFLAGS =-wall-static

However, there is a problem at this point:

Undefined reference to ' pthread_mutex_* '

Undefined reference to ' dl* '

The prompt does not define these functions, so you add both library files to the included library file

In makefile, modify the Libs variable;

LIBS =-lsqlite3-lm-lcrypt

Switch

LIBS =-LSQLITE3-LM-LCRYPT-LPTHREAD-LDL

Then cross-compile and succeed!

Compiled executable file is relatively large, because things statically compiled, I have more than 2M,

To the andriod system of the Development Board,

Modify Permissions:

#chmod 777 Xlisten-arm

Perform:

/#./xlisten-arm

The ok! can be executed correctly!

How to run a C language program in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.