简体   繁体   English

为 android/iOS 编译 c++

[英]Compile c++ for android/iOS

I have to compile a library (library BPG from Bellard.org ) to create a .so or a dll that I can use with android/iOS.我必须编译一个库(来自Bellard.org 的库 BPG)来创建一个 .so 或一个我可以在 android/iOS 上使用的 dll。

I'm working with Visual Studio.我正在使用 Visual Studio。 With some researches, I found the project "Visual C++ -> Cross Platform -> Shared Library (Android, iOS)".通过一些研究,我发现了“Visual C++ -> Cross Platform -> Shared Library (Android, iOS)”项目。 But I am totally lost and can't do anything.但我完全迷失了,什么也做不了。

The downloaded library is organised with some folders but Visual don't allow to make tree, all files are sorted by filters (one for header and one for sources).下载的库由一些文件夹组织,但 Visual 不允许制作树,所有文件都按过滤器排序(一个用于标题,一个用于源)。 So I can't build, I have more than 300 errors, "can't open source file", "undefined variable"...所以我无法构建,我有300多个错误,“无法打开源文件”,“未定义的变量”......

Secondly, the README file from project says :其次,项目的自述文件说:

The following packages need to be installed: mingw64-gcc mingw64-libpng mingw64-libjpeg-turbo mingw64-SDL mingw64-SDL_image yasm需要安装以下软件包: mingw64-gcc mingw64-libpng mingw64-libjpeg-turbo mingw64-SDL mingw64-SDL_image yasm

I found installed for mingw 32 bits but no 64 bits so I don't know if build can perform.我发现为 mingw 安装了 32 位但没有 64 位,所以我不知道构建是否可以执行。 I don't know how to find the libraries.我不知道如何找到图书馆。

So my question is, what is the best way to compile a C/C++ library for android/iOS ?所以我的问题是,为 android/iOS 编译 C/C++ 库的最佳方法是什么? And where can I find a tutorial for beginners ?我在哪里可以找到适合初学者的教程?

Thank you谢谢

I have worked as cross compiling engineer for several years.我作为交叉编译工程师已经工作了几年。 The most suitable IDE for you I think, is the CLion with CMake inside.我认为最适合您的 IDE 是内置 CMake 的 CLion。

CMake is a tool which can cross-compile the C/C++ library into ios\\android\\linux\\etc.. using only one config file: "CMakeList.txt". CMake 是一种工具,它可以将 C/C++ 库交叉编译到 ios\\android\\linux\\etc.. 只使用一个配置文件:“CMakeList.txt”。 The main task of CMake is to translate CMakeList.txt to Makefile on every platform and provide you the .a and .so files. CMake 的主要任务是在每个平台上将 CMakeList.txt 转换为 Makefile,并为您提供 .a 和 .so 文件。

CLion is very powerful IDE in code editing and debugging. CLion 是代码编辑和调试方面非常强大的 IDE。

Furthermore, Android needs JNI (or JNA if performance is not concerned) to wrap your c++ interfaces to java classes.此外,Android 需要 JNI(或 JNA,如果不考虑性能)将您的 c++ 接口包装到 java 类。 Here I would recommend SWIG.在这里,我会推荐 SWIG。 SWIG is a tool to wrap C++ interfaces to other languages, that means, not only java on android you can support , other days your lib can also support python\\tcl\\Go\\etc. SWIG 是一个将 C++ 接口包装到其他语言的工具,这意味着不仅你可以支持 android 上的 java,其他日子你的 lib 还可以支持 python\\tcl\\Go\\etc。

Which os are u using to build the lib?你使用哪个操作系统来构建库? macOS or win ? macOS 还是胜利?

For iOS : .a file For Android: .so file对于 iOS:.a 文件对于 Android:.so 文件

First you should check the README file首先你应该检查自述文件

  • Edit the Makefile to change the compile options (the default compile options should be OK).编辑 Makefile 以更改编译选项(默认编译选项应该可以)。 Type 'make' to compile and 'make install' to install the compiled binaries.输入“make”进行编译,输入“make install”安装编译好的二进制文件。

  • Use 'make -j N' where N is the number of CPU cores to compile faster.使用“make -j N”,其中 N 是编译速度更快的 CPU 内核数。

  • The following packages must be installed: SDL-devel SDL_image-devel yasm.必须安装以下软件包:SDL-devel SDL_image-devel yasm。 It is recommended to use yasm version >= 1.3.0 to have a faster compilation.建议使用 yasm version >= 1.3.0 编译更快。

  • Only a 64 bit target is supported because x265 needs it for bit depths > 8.仅支持 64 位目标,因为 x265 需要它来实现大于 8 的位深度。

check this to install SDL packages https://wiki.libsdl.org/Installation选中此项以安装 SDL 软件包https://wiki.libsdl.org/Installation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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