Can I bind .asm files containing x64 assembly code to my c++ project?

  • Hello,
    I've been looking for a good way to create GUIs with c++ and x64 assembly. Everything works great so far except that I could not figure out how to bind a .asm file containing x64 assembly code to my project.
    Does anyone know how to do this?

  • Lifetime Qt Champion


    I haven't tried it but did you add your assembler files to the SOURCES variable ?

  • Sorry for late reply.
    Yes, I think I did. But I don't think I've done it properly.

    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = test---
    TEMPLATE = app
    SOURCES += main.cpp\
    HEADERS  += mainwindow.h
    FORMS    += mainwindow.ui
    DISTFILES += \
    LIBS += asm.o


    //some code
    extern "C" __int64 assembly();
    //some code
    void MainWindow::on_pushButton_clicked()
        QString s = QString::number(assembly()); // compiling fails here


    assembly proc
    mov rax, 1
    xor rax, rax
    assembly endp

    I get an error message stating that the object "assembly" cannot be found

  • Lifetime Qt Champion

    What OS are you running ?
    What compiler are you using ?

  • Qt Champions 2017

    @KratzKatz said in Can I bind .asm files containing x64 assembly code to my c++ project?:

    Have you compiled your assembly file? You can't link text files ... Also this:

    LIBS += asm.o

    doesn't look right.

  • @SGaist Windows 10 on my Laptop, Windows 7 on my tower and school's computer.
    The compiler I'm using is Desktop_Qt_5_8_0_MSVC2015_64bit.

    @kshegunov "LIBS += asm.o" was just an attempt on getting things to work. I have it now commented out

  • Qt Champions 2017

    As I said, you have to compile the assembly file. For that to happen in QtCreator you need to add an extra compiler and after that add the resulting object files to the OBJECTS qmake variable, so the linker will put it all together. Your asm compiler for VS is called ml (see here - the second post - for a long explanation of what switches you might need).

  • @kshegunov is this the right way?:

    SOURCES += main.cpp\
    HEADERS  += mainwindow.h
    FORMS    += mainwindow.ui
    new_moc.output  = moc_${QMAKE_FILE_BASE}.cpp
    new_moc.commands = moc ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
    new_moc.depend_command = g++ -E -M ${QMAKE_FILE_NAME} | sed "s,^.*: ,,"
    new_moc.input = NEW_HEADERS
    OBJECTS += asm.s
    input = asm.s
    output = asm.bin

    But still no compilation. I do know how to compile assembly code to an .exe in VS, but I don't want to use it for GUI programming. But does this mean I can compile my assembly file with VS and link it to my QT project?

  • Qt Champions 2017

    No it is not. Have you read the documentation carefully? It should look something like:

    ASM_FILES += asm.s
    asm_cl.output  = ${QMAKE_FILE_OUT}
    asm_cl.commands = ml /c /Cx /coff /Fo${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
    asm_cl.input = ASM_FILES
    asm_cl.variable_out = OBJECTS

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.