Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Can I bind .asm files containing x64 assembly code to my c++ project?

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

Scheduled Pinned Locked Moved Solved Language Bindings
9 Posts 3 Posters 6.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KratzKatz
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • K KratzKatz

      @kshegunov is this the right way?:

      SOURCES += main.cpp\
              mainwindow.cpp\
              asm.s
      
      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
      QMAKE_EXTRA_COMPILERS += new_moc
      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?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #9

      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
      
      QMAKE_EXTRA_COMPILERS += asm_cl
      

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KratzKatz
          wrote on last edited by
          #3

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

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

          .mainWindow.cpp:

          //some code
          extern "C" __int64 assembly();
          //some code
          void MainWindow::on_pushButton_clicked()
          {
              QString s = QString::number(assembly()); // compiling fails here
              ui->label_2->setText(s);
          }
          

          asm.o:

          .code
          assembly proc
          
          mov rax, 1
          ret
          
          xor rax, rax
          
          assembly endp
          end
          

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

          kshegunovK 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • K KratzKatz

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

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

              .mainWindow.cpp:

              //some code
              extern "C" __int64 assembly();
              //some code
              void MainWindow::on_pushButton_clicked()
              {
                  QString s = QString::number(assembly()); // compiling fails here
                  ui->label_2->setText(s);
              }
              

              asm.o:

              .code
              assembly proc
              
              mov rax, 1
              ret
              
              xor rax, rax
              
              assembly endp
              end
              

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

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #5

              @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.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              1
              • K Offline
                K Offline
                KratzKatz
                wrote on last edited by
                #6

                @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

                kshegunovK 1 Reply Last reply
                0
                • K KratzKatz

                  @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

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #7

                  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).

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  1
                  • K Offline
                    K Offline
                    KratzKatz
                    wrote on last edited by
                    #8

                    @kshegunov is this the right way?:

                    SOURCES += main.cpp\
                            mainwindow.cpp\
                            asm.s
                    
                    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
                    QMAKE_EXTRA_COMPILERS += new_moc
                    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?

                    kshegunovK 1 Reply Last reply
                    0
                    • K KratzKatz

                      @kshegunov is this the right way?:

                      SOURCES += main.cpp\
                              mainwindow.cpp\
                              asm.s
                      
                      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
                      QMAKE_EXTRA_COMPILERS += new_moc
                      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?

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by kshegunov
                      #9

                      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
                      
                      QMAKE_EXTRA_COMPILERS += asm_cl
                      

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      2

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved