我有一個Qt C++項目。將程序集* .o文件包含到Qt C++項目中
系統
的Windows XP
QtCreator和QTSDK最新
C++
的MinGW/GCC/G ++
因爲我需要在裝配做一些功能的性能的原因。我的項目主要是Qt和C++,但我需要將我的C++代碼鏈接到我編寫的某個程序集。我有一個程序集* .o文件,但我無法從我的C++代碼中訪問我的彙編函數。我使用nasm編譯了calc.o文件。
簡化示例。
PRO FILE
QT += core
QT -= gui
TARGET = Test_asm
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
LIBS += C:/Users/David/Test_asm/calc.o
SOURCES += main.cpp
的main.cpp
#include <QtCore/QCoreApplication>
#include <QTextStream>
extern "C" int five();
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTextStream qout(stdout);
int f = five();
qout << "five: " << f << endl;
return a.exec();
}
ERROR
main.cpp:11: undefined reference to `five'
collect2: ld returned 1 exit status
TRY#1 - Karlphillip的方式(不工作在Windows上)
Directory of C:\x
16/03/2012 03:09 PM <DIR> .
16/03/2012 03:09 PM <DIR> ..
16/03/2012 03:07 PM 82 calc.pro
16/03/2012 03:10 PM 178 calc.S
16/03/2012 03:10 PM 164 main.c
3 File(s) 424 bytes
2 Dir(s) 78,905,851,904 bytes free
C:\x>qmake
C:\x>make
'make' is not recognized as an internal or external command,
operable program or batch file.
C:\x>mingw32-make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/x'
gcc -c -g -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -I"..\QtSDK\Desktop\Qt\4.7.3\mi
ngw\mkspecs\default" -o debug\main.o main.c
gcc -c -g -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -I"..\QtSDK\Desktop\Qt\4.7.3\mi
ngw\mkspecs\default" -o debug\calc.o calc.S
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-rel
oc -Wl,-subsystem,console -mthreads -Wl -o debug\calc.exe debug/main.o debug/cal
c.o
debug/main.o: In function `main':
C:\x/main.c:9: undefined reference to `helloasm'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\calc.exe] Error 1
mingw32-make[1]: Leaving directory `C:/x'
mingw32-make: *** [debug] Error 2
我很想在您評估[我的其他答案]後回答此問題(http://stackoverflow.com /一個/176769分之9741887)。 – karlphillip 2012-03-16 18:37:50
謝謝karlphillip,我永遠不會忘記接受答案,這只是你的答案沒有奏效(還)。檢查該帖子的更新。 WinMain @ 16錯誤。 – L123 2012-03-16 18:48:05
我做了,我已經更新了。 – karlphillip 2012-03-16 18:49:09