简体   繁体   English

用于嵌入SCons makery的ARM的交叉编译Swiften库

[英]Cross-Compiling Swiften library for ARM-embedded with SCons makery

Swiften is a XMPP client library and my objective was to build it for a ARM-embedded target running Linux. Swiften是XMPP客户端库,我的目标是为运行Linux的ARM嵌入式目标构建它。

I hacked my way to a successful cross-compile with little knowledge of SCons. 我几乎不懂SCons,就闯入了成功的交叉编译之路。 I'll lay out my hack here with the hope that someone can point me to a maintainable solution using the two makery files, SConscript.boot and SConstruct . 我将在这里布置我的黑客程序,希望有人可以使用两个Makery文件SConscript.bootSConstruct指向我一个可维护的解决方案。

I had two tasks (neither accomplished satisfactorily): 我完成了两项任务(均未令人满意地完成):

  1. Successfully switching the tool-chain from native-compile to cross-compile 成功地将工具链从本地编译切换到交叉编译
  2. Ensuring that OpenSSL libraries were successfully linked (not supplied by the swiftim project; they has to be installed and built in the 3rdParty folder). 确保OpenSSL库已成功链接( swiftim项目未提供;必须在3rdParty文件夹中安装并构建它们)。

Switching the tool-chain from native-compile to cross-compile for ARM 将工具链从本机编译切换到交叉编译以进行ARM

My ARM cross tool-chain components, gcc, g++, ld, etc are located here. 我的ARM跨工具链组件gcc,g ++,ld等位于此处。

/opt/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux/arm-linux-gnueabihf/bin/

I couldn't find a way to tell scons to use the cross tool-chain (from the above location) instead of the native tool (in the usual place, /usr/bin ). 我找不到一种方法来告诉scons使用交叉工具链(从上面的位置)而不是使用本机工具(通常是/usr/bin )。 Prefacing the invocation ( ./scons Swiften ) with the fully-qualified values for the environment variables, CC and CXX didn't work (while not recommended, its alluded to in one place ). 该作序调用( ./scons Swiften与环境变量的完全限定值),CC和CXX没有工作(虽然不推荐,它在提到一个地方 )。

Scons would only pick up the native tool-chain even after many ad hoc changes to the makery. 即使在对makery进行了许多临时更改之后,Scons也只会选择本地工具链。

So, as a hack , I had to change the native tool-chain to point to the cross tool-chain. 因此,作为一种技巧 ,我不得不更改本机工具链以指向交叉工具链。

/usr/bin/gcc -> /opt/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux/bin/arm-linux-gnueabihf-gcc-4.7.3*
/usr/bin/g++ -> /opt/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux/bin/arm-linux-gnueabihf-g++*

The first compile-break for ARM was fixed by adding the line below to the default portion of the build script, SConscript.boot . 通过SConscript.boot添加到构建脚本的默认部分SConscript.bootSConscript.boot了ARM的第一个编译中断。

env.Append(CPPDEFINES = ["_LITTLE_ENDIAN"])

The next compile-break has to do with the OpenSSL header files not being found. 下一个编译中断与找不到OpenSSL头文件有关。 To fix the location issue, I had to introduce the line below into SConscript.boot 要解决位置问题,我必须将以下行引入SConscript.boot

vars.Add(PackageVariable("openssl", "OpenSSL location", "/home/auro-tripathy/swiftim/swift/3rdParty/OpenSSL/openssl-1.0.1c/"))

Linking with OpenSSL 与OpenSSL链接

For the sample Switften programs to link with the OpenSSL libraries, I had to move libssl.a and libcrypto.a (built separately) from the location they were built to the toolchain library-location like so. 为了使示例Switften程序能够与OpenSSL库链接,我不得不将libssl.alibcrypto.a (分别构建)从它们的构建位置移动到这样的工具链库位置。

mv ~/swiftim/swift/3rdParty/OpenSSL/openssl-1.0.1c/libcrypto.a /opt/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux/lib/gcc/arm-linux-gnueabihf/4.7.3/.

Help 救命

Not understanding of the working of scons, I've made some hacks to get it to work. 由于不了解scons的工作原理,我进行了一些破解以使其正常工作。

I'd like some help to: 我想要一些帮助:

  1. Introduce a new target called ARM-embedded, just like other targets; 与其他目标一样,引入一个称为ARM嵌入式的新目标。 iPhone, android, etc iPhone,Android等
  2. Clean way to integrate OpenSSL into the build . 将OpenSSL集成到构建中的干净方法。

Update Per dirkbaechle, retried the script below and it works 更新 Per dirkbaechle,重试以下脚本,即可正常运行

export CC=/opt/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux/arm-linux-gnueabihf/bin/gcc
export CXX=/opt/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7-2013.01-20130125_linux/arm-linux-gnueabihf/bin/g++
./scons Swiften

Brady's answer is correct, regarding how you'd do it in plain SCons. 布雷迪的答案是正确的,关于您将如何使用普通SCons。 I'd just like to mention that the top-level SConstruct of Swiften already provides arguments like " cc= " and " cxx= " for using local toolchains. 我只想提到Swiften的顶级SConstruct已经提供了使用本地工具链的参数“ cc= ”和“ cxx= ”。 You might want to inspect the ouput of scons -h for a complete list of available options. 您可能需要检查scons -h的输出以scons -h可用选项的完整列表。

In addition, the SConscript for the OpenSSL build expects the sources to be located in the relative folder named " openssl ", not " openssl-1.0.1c " as in your case. 另外,用于OpenSSL构建的SConscript期望源位于名为“ openssl ”的相对文件夹中,而不是您所用的“ openssl-1.0.1c ”文件夹。 Maybe that's where your build problems are mainly coming from. 也许这就是您的构建问题的主要来源。

I left a comment above regarding the cross-compilation. 我在上面对交叉编译发表了评论。 Its already been answered in the link provided, but basically you just need to set the appropriate construction variables: CC, CXX, LINK, etc. 它已经在提供的链接中得到了回答,但是基本上您只需要设置适当的构造变量:CC,CXX,LINK等。

As for a "Clean way to integrate OpenSSL into the build" this can be performed simply by adding library and include paths appropriately as follows replacing the quoted values appropriately: (without having to copy/move the original files) 对于“将OpenSSL集成到构建中的干净方法”,可以简单地通过添加库来执行,并适当地包含路径,如下所示:适当地替换引用的值:(无需复制/移动原始文件)

# This sets the location of the OpenSSL Include paths
env.Append(CPPPATH="path/to/openssl/includes")

# This sets the location of the OpenSSL Libraries
env.Append(LIBPATH="path/to/openssl/libraries")

# These are the OpenSSL libraries to be linked into the binary
env.Append(LIBS=["OpenSSL_lib", "OpenSSL_lib2"])

The choice of compiler, and additional flags, can all be set in Swift's config.py file. 编译器的选择以及其他标志都可以在Swift的config.py文件中设置。 A snippet from config.py using a custom compiler and flags is below (the one I use on one of my dev boxes): 下面是使用自定义编译器和标志的config.py片段(我在其中一个开发箱中使用的片段):

cc = link = "/usr/local/llvm-git/bin/clang"
cxx = "/usr/local/llvm-git/bin/clang++"

bothflags = " -std=c++11 -stdlib=libc++ -nostdinc++"
cxxflags = bothflags + " -I/usr/local/libcxx/include -Wno-deprecated"
linkflags = bothflags + " -L/usr/local/libcxx/lib"

This should work for cross-compiling in the same manner. 这应该以相同的方式用于交叉编译。

To use a bundled openssl, you should just be able to extract into 3rdParty/OpenSSL, and add openssl_force_bundled = True to your config.py. 要使用捆绑的openssl,您应该只能解压缩到3rdParty / OpenSSL中,然后将openssl_force_bundled = True添加到config.py中。 You should not need to fiddle with setting include paths to this yourself. 您无需自己设置包含路径。 It's conceivable that this is tied to a particular openssl release as I've not compiled a bundled openssl since 1.0.0a, but if it doesn't work with the current version it's probably a bug that ought to be fixed. 可以想象这与特定的openssl版本有关,因为自1.0.0a起我还没有编译过捆绑的openssl,但是如果它不适用于当前版本,则可能是应该修复的错误。 You could also cross-compile openssl yourself and use openssl='/path/to/openssl' , but that's a little more of a nuisance for you. 您也可以自己交叉编译openssl并使用openssl='/path/to/openssl' ,但这对您来说有点麻烦。

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

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