如何与Windows上的clang链接? [英] How do I link with clang on windows?

查看:0
本文介绍了如何与Windows上的clang链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一些集合。使用Windows clang,我可以编写clang -c my.s并获得目标文件。我可以使用

链接它

&Q;C:程序文件(X86)Microsoft Visual Studio2019BuildToolsVCToolsMSVC14.29.30133inHostx64x64link.exe";n.o/Entry:Main

(库路径为c:/Program Files(X86)/Windows Kits/10/Lib/10.0.20348.0/um/x64/)

然而,我想不出如何使用clang的链接器来做这件事。我一直收到";错误:my.o:未知文件类型&qot;

我在我的Linux计算机上尝试

clang my.s --target=x86_64-windows-gnu "-L/run/media/eric/win10/Program Files (x86)/Windows Kits/10/Lib/10.0.20348.0/um/x64/"

我得到了一份丢失的lib的巨大列表。我真的不认为有任何必要。我需要的一切似乎都在Kernel32.lib中。我只想将Kernel32与我的程序集链接起来。(或仅使用clang的窗口)

    .text
    .def     @feat.00;
    .scl    3;
    .type   0;
    .endef
    .globl  @feat.00
.set @feat.00, 0
    .intel_syntax noprefix
    .file   "my.c"
    .def     main;
    .scl    2;
    .type   32;
    .endef
    .globl  main                            # -- Begin function main
    .p2align    4, 0x90
main:                                   # @main
.seh_proc main
# %bb.0:
    sub rsp, 56
    .seh_stackalloc 56
    .seh_endprologue
    mov dword ptr [rsp + 52], 0
    mov ecx, 4294967285
    call    GetStdHandle
    mov qword ptr [rsp + 40], rax
    mov rcx, qword ptr [rsp + 40]
    lea rdx, [rip + text_0]
    mov r8d, 10
    xor eax, eax
    mov r9d, eax
    mov qword ptr [rsp + 32], 0
    call    WriteFile
    mov ecx, 12
    call    ExitProcess
    int3
    .seh_endproc
                                        # -- End function
    .section    .rdata,"dr",discard,text_0
    .globl  text_0 # @text_0
text_0:
    .asciz  "New Text!
"

    .section    .drectve,"yn"
    .ascii  " /DEFAULTLIB:kernel32.lib"
    .addrsig

推荐答案

如果您使用的是Windows10,请使用wsl(linux下的windows子系统),安装ubuntu或其他发行版(通过应用商店https://docs.microsoft.com/en-us/windows/wsl/wsl-config),使用&Normal&GCC等linux工具:

我使用

piotr@PiotrLaptop02:/mnt/c/Users/Piotr$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal
piotr@PiotrLaptop02:/mnt/c/Users/Piotr$

这篇关于如何与Windows上的clang链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆