简体   繁体   中英

How to cross-compile for Android without cmakelists.txt?

I know that if a C++ project has CMakeLists.txt, I can create a new project and use Android studio to compile the executable to run on Android via console. However, some projects don't have CMakeList.txt and need to run . /configure and then make. eg https://github.com/strukturag/libheif Is there a easy tool that can compile it for Android on Windows?

The following assumes that you have mingw installed and also a cross-compiler compatible with your platform. Also, I'm not a big fan of Windows for this type of development. So my explanation is for Linux. But I believe you can easily adapt it to your case.

First of all, you need to install a cross-compiler. For the sake of explanation, I'm going to use gcc-linaro here.

If you open the repo, you'll see that there is a file called autogen.sh . You will need to run it. This file will create the configuration tool. Once it finishes, a file called configure will appear. This is the tool you want to use for configuring the library to be compiled, customized for your specific needs.

The next command you want to run is

./configure --help

The above command will show you all the options that you can set. You can play with them but, typically, you want to set the following, at least:

  • CC
  • --prefix
  • --includedir
  • --libdir
  • --host

These options are explained in the configure tool. To give you an idea on how to use them, the following is the generic command that you might want to run:

CC="<path to your gcc compiler>" ./configure --prefix="<path_to_the_folder_where_you_want_to_install>" --includedir="<path_to_the_include_dir>" --libdir="<path_to_the_lib_dir>" --host=arm

In my situation, I have installed the cross compiler at the following path

/home/alexis/gcc-linaro/bin/arm-linux-gnueabi-gcc

Therefore, I would need to run the command:

CC="/home/alexis/gcc-linaro/bin/arm-linux-gnueabi-gcc" ./configure --prefix=/home/alexis/gcc-linaro --includedir=/home/alexis/gcc-linaro/include --libdir=/home/alexis/gcc-linaro/lib --host=arm

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM