设置Qt Creator以链接和编译汇编代码 [英] Setting up Qt Creator for linking and compiling assembly code

查看:766
本文介绍了设置Qt Creator以链接和编译汇编代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几周我一直在研究C ++和x64汇编,并希望使用Qt IDE进行GUI编程.问题是我找不到链接和编译包含汇编代码的文件的方法.我一直在浏览互联网和该网站,但没有发现任何帮助.

I've been studying C++ and x64 Assembly the last weeks and would like to get into GUI programming with the Qt IDE. The problem is that I can't find a way to link and compile a file containing assembly code. I've been browsing the internet and this site without finding anything helpful.

这是到目前为止我尝试过的: .pro

Here is what I have tried so far: .pro

QMAKE_CXXFLAGS += -save-temps
QT       += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test---
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS

QMAKE_EXTRA_COMPILERS += nasm

SOURCES += main.cpp\
    mainwindow.cpp\
    asm.s

HEADERS  += mainwindow.h
FORMS    += mainwindow.ui

mainwindow.cpp

mainwindow.cpp

//code
extern "C" __int64 assembly();

//code

void MainWindow::on_pushButton_clicked()
{
    int zahl = assembly(); // place what the assembly function return into "zahl"
}

asm.s

.code
.global
assembly proc

mov rax, 1
ret

xor rax, rax

assembly endp
end

构建设置img

尝试编译项目会导致以下错误消息:

Attempting to compile the project leads to following error message:

mainwindow.obj:-1: Fehler: LNK2019: unresolved external symbol assembly referenced in function "private: void __cdecl MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked@MainWindow@@AEAAXXZ)

我还找到了有关控制台应用程序的设置指南.但这似乎不适用于GUI应用程序:http://dvisagie.blogspot.de/2011/09/setting-up-qt-creator-for-assemblylinux.html

I have also found a setup guide on this for console applications. But it doesn't seem to be suitable for GUI applications: http ://dvisagie.blogspot.de/2011/09/setting-up-qt-creator-for-assemblylinux.html

这是我在Visual Studio中编译程序集文件的方式: .cpp:

Here's how I've been compiling assembly files in Visual Studio: .cpp:

#include "stdafx.h"
#include<iostream>

using namespace std;

extern "C" __int64 _stdcall assembly();

int main()
{
    cout << assembly() << endl;

    system("pause");
    return 0;
}

.asm: .代码 汇编程序

.asm: .code assembly proc

mov rax, 1234
ret
xor rax, rax

assembly endp
end

附加的版本

推荐答案

代码应如下所示(在您的pro文件中).第一个编译器(nasm)从asm文件生成第一个文件.然后,第二个编译器(nasm_ld)运行ld生成目标文件.

The code should look like this (in your pro file). The first compiler (nasm) generates the lst file from the asm file. The second compiler (nasm_ld) then runs ld to generate an object file.

对于nasm编译器,ASM_FILES是它从中读取的输入变量,并将生成的lst的名称写入LST_FILES,该名称由nasm_ld处理并添加到OBJECTS中的对象,使链接器可用.

For the nasm compiler, ASM_FILES is the input variable that it reads from, and writes the name of the generated lst to LST_FILES, which is the processed by nasm_ld and the objects added to OBJECTS, which should make the available for the linker.

nasm.name = nasm ${QMAKE_FILE_IN}
nasm.input = ASM_FILES
nasm.variable_out = OBJECTS
nasm.commands = nasm -f win64 ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
nasm.output = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}$${first(QMAKE_EXT_OBJ)}
nasm.CONFIG += target_predeps

QMAKE_EXTRA_COMPILERS  += nasm

ASM_FILES += asm.s

编辑:我已根据评论更新了代码.尝试是否可行.它应该编译asm文件并将目标文件添加到链接器.请先删除您的自定义构建步骤.

I have updated the code based on the comments. Try if this works. It should compile the asm file and add the object file to the linker. Please remove your custom build step first.

这篇关于设置Qt Creator以链接和编译汇编代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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