简体   繁体   English

将Swift代码编译为32位目标文件

[英]Compiling swift code to 32 bit object files

I recently got interested in the swift programming language and i wanted to see if i could integrate it into an existing project of mine which is a 32 bit microkernel 最近,我对快速的编程语言产生了兴趣,我想看看是否可以将其集成到我现有的32位微内核项目中

The first thing i tried was to compile it into a 32 bit object file but i didn't know how so i searched google for about 3 hours and i could not find anything helpful. 我尝试的第一件事是将其编译为32位目标文件,但我不知道如何搜索Google约3个小时,但找不到任何有用的信息。 This is the code i am trying to compile 这是我正在尝试编译的代码

@_cdecl("swift_func")
func swift_f(x: Int) -> Int {
    return x-10
}

I expected to compile the file into a 32 bit ELF object but i can't seem to find the right arguments for that 我希望将文件编译成32位ELF对象,但似乎找不到正确的参数

NB: I am on debian linux NB:我在debian linux上

So i figured it out, hopefully this can help others 所以我想通了,希望这可以帮助其他人

swiftc -emit-library -emit-object -Xcc "-m32" -o hello.o hello.swift

So what was needed was telling swift to make it a static object file then pass -m32 to the underlying clang compiler which makes it a 32 bit object file 所以需要的是告诉swift使其成为静态目标文件,然后将-m32传递给基础clang编译器,从而使它成为32位目标文件

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

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