Inclusion of header files from include/Qt is deprecated - c++

I've recently began working through a C++ Gui Programming with Qt 4 book.
However, I can't get past the first tutorials.
#include <QApplication>
#include <QTextEdit>
int main(int argv, char **args)
{
QApplication app(argv, args);
QTextEdit textEdit;
textEdit.show();
return app.exec();
}
Each time I try to compile this, I get this:
C:\Qt\4.8.0\andrew>qmake -project
C:\Qt\4.8.0\andrew>qmake
C:\Qt\4.8.0\andrew>make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Qt/4.8.0/andrew'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -
DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -
DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\includ
e\QtCore" -I"..\include\QtGui" -I"..\include" -I"." -I"..\include\ActiveQt" -I"d
ebug" -I"..\mkspecs\win32-g++" -o debug\tutone.o tutone.cpp
In file included from tutone.cpp:1:0:
C:\Qt\4.8.0\include\Qt\Qapplication.h:3:10: warning: #warning "Inclusion of head
er files from include/Qt is deprecated." [-Wcpp]
In file included from tutone.cpp:2:0:
C:\Qt\4.8.0\include\Qt\Qpushbutton.h:3:10: warning: #warning "Inclusion of heade
r files from include/Qt is deprecated." [-Wcpp]
tutone.cpp: In function 'int qMain(int, char**)':
tutone.cpp:11:7: error: 'class QApplication' has no member named 'setMainWidget'
mingw32-make[1]: *** [debug/tutone.o] Error 1
mingw32-make[1]: Leaving directory `C:/Qt/4.8.0/andrew'
mingw32-make: *** [debug] Error 2
As I'm new to Qt and fairly new to compiling, I assume the error is on my end. Am I declaring the headers wrong or something?
My .pro file looks like this:
######################################################################
# Automatically generated by qmake (2.01a) Thu Jan 19 12:41:21 2012
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += tutone.h \
C:/Qt/4.8.0/include/Qt/Qapplication.h \
../include/QtGui/qapplication.h \
../src/gui/kernel/qapplication.h \
C:/Qt/4.8.0/include/Qt/Qpushbutton.h \
../include/QtGui/qpushbutton.h \
../src/gui/widgets/qpushbutton.h
SOURCES += tutone.cpp \
tutthree.cpp \
../src/gui/kernel/qapplication.cpp \
../src/gui/widgets/qpushbutton.cpp
Thanks

It's a false error due to a bug in the Qt build setup.
It's not a problem and has been logged on the Qt bug tracker

After running qmake -project you should add QT variable in the .pro file. Then you can remove these odd HEADERS and SOURCES (and link dynamically Qt libraries to your program):
QT += core gui # <-- this line
TEMPLATE = app
TARGET = ProjectNameHere
DEPENDPATH += .
INCLUDEPATH += .
# Input
HEADERS += tutone.h
SOURCES += tutone.cpp \
tutthree.cpp \

Related

Adding ObjectBox to Qt application

I have just tried to add ObjectBox to an empty qt application, but somehow I do not get any further.
I tried to follow the instructions: https://cpp.objectbox.io/installation
I took the win x64 lib from here: https://github.com/objectbox/objectbox-c/releases/tag/v0.17.0
I am always getting undefined reference errors and I do not know why. I guess there must be something wrong with linking in der .pro file?
Thats my .pro file (just edited the last 4 lines):
QT -= gui
CONFIG += c++11 console
CONFIG -= app_bundle
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/objectbox/lib/ -lobjectbox
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/objectbox/lib/ -lobjectbox
INCLUDEPATH += $$PWD/objectbox/include
DEPENDPATH += $$PWD/objectbox/include
And here ist my main.cpp:
#include <QCoreApplication>
#include "objectbox.hpp"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
printf("Using ObjectBox version %s\n", obx_version_string());
return a.exec();
}
Compiler says the following:
C:/Qt/Tools/mingw730_64/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/temp/obxTut/ObjectBoxTutorial'
g++ -c -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_QML_DEBUG -DQT_CORE_LIB -I. -Iobjectbox\include -I..\..\..\Qt\5.12.11\mingw73_64\include -I..\..\..\Qt\5.12.11\mingw73_64\include\QtCore -Idebug -I..\..\..\Qt\5.12.11\mingw73_64\mkspecs\win32-g++ -o debug\main.o main.cpp
In file included from main.cpp:2:0:
objectbox\include/objectbox.hpp:711:21: warning: 'std::vector<long long unsigned int> obx::{anonymous}::idVectorOrThrow(OBX_id_array*)' defined but not used [-Wunused-function]
std::vector<obx_id> idVectorOrThrow(OBX_id_array* cIds) {
^~~~~~~~~~~~~~~
objectbox\include/objectbox.hpp:703:14: warning: 'OBX_id_array obx::{anonymous}::cIdArrayRef(const std::vector<long long unsigned int>&)' defined but not used [-Wunused-function]
OBX_id_array cIdArrayRef(const std::vector<obx_id>& ids) {
^~~~~~~~~~~
g++ -Wl,-subsystem,console -mthreads -o debug\ObjectBoxTutorial.exe debug/main.o -LC:\temp\obxTut\ObjectBoxTutorial\objectbox\lib -lobjectbox C:\Qt\5.12.11\mingw73_64\lib\libQt5Cored.a
debug/main.o: In function `idVectorOrThrow':
C:\temp\obxTut\ObjectBoxTutorial/objectbox/include/objectbox.hpp:712: undefined reference to `obx::internal::throwLastError(int, char const*)'
C:\temp\obxTut\ObjectBoxTutorial/objectbox/include/objectbox.hpp:718: undefined reference to `obx::internal::throwIllegalStateException(char const*, char const*)'
debug/main.o: In function `applyTo':
C:\temp\obxTut\ObjectBoxTutorial/objectbox/include/objectbox.hpp:828: undefined reference to `obx::internal::throwIllegalStateException(char const*, char const*)'
collect2.exe: error: ld returned 1 exit status
mingw32-make[1]: *** [Makefile.Debug:65: debug/ObjectBoxTutorial.exe] Error 1
mingw32-make: *** [Makefile:38: debug] Error 2
mingw32-make[1]: Leaving directory 'C:/temp/obxTut/ObjectBoxTutorial'
23:05:08: The process "C:\Qt\Tools\mingw730_64\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project ObjectBoxTutorial (kit: Desktop Qt 5.12.11 MinGW 64-bit)
When executing step "Make"
Qt 5.12 with MinGW 7.3
The problem is the compiler that you are using, because the library is probably compiled with MSVC and you are trying to build your application with MinGW and use the C++ interface of the library.
this won't work because of name mangling and etc. see How to use libraries compiled with MingW in MSVC?
Thankfully this library also provides a pure C interface "objectbox.h", so including this header instead of the one with "hpp" would also fix your issue.
I was able to build and link a test app by using MSVC 2015 64 Bit.

SQLiteCpp cross compile error: cannot find a given function in sqlite3.c

I came across a compile error that cannot find the function defined in a given file when I try to add SQLiteCpp source to my qt application. It cost me a half day and I hope some one can kindly help me. Thanks a lot!
build libSQLiteCpp.a and libsqlite3.a
{
get src:
git clone https://github.com/SRombauts/SQLiteCpp.git
cd SQLiteCpp
git submodule init
git submodule update
build libs:
cd /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/ \
&& . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa9hf-neon-poky-linux-gnueabi \
&& ./build.sh
}
edit qt app and its project file
{
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = sqltest
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
INCLUDEPATH += /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/include/
INCLUDEPATH += /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/include/SQLiteCpp/
INCLUDEPATH += /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/sqlite3/
LIBS += /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/sqlite3/libsqlite3.a
LIBS += /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/libSQLiteCpp.a
FORMS += mainwindow.ui
}
qt app cross compile error: can not find the function defined in sqlite3.c
{
arm-poky-linux-gnueabi-g++ -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.0/sysro
ots/cortexa9hf-neon-poky-linux-gnueabi -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -Wl,-O1 -o sqltest main.o mainwindow.o moc_mainwi
ndow.o /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/sqlite3/libsqlite3.a /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp
/build/libSQLiteCpp.a -lQt5Widgets -lQt5Gui -lQt5Core -lGLESv2 -lEGL -lpthread
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/libSQLiteCpp.a(Column.cpp.o): In function `SQLite::Column::getName() const':
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/src/Column.cpp:44: undefined reference to `sqlite3_column_name'
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/libSQLiteCpp.a(Column.cpp.o): In function `SQLite::Column::getOriginName() con
st':
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/src/Column.cpp:51: undefined reference to `sqlite3_column_origin_name'
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/libSQLiteCpp.a(Column.cpp.o): In function `SQLite::Column::getInt() const':
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/src/Column.cpp:58: undefined reference to `sqlite3_column_int'
}
more info
{
ocean#mhc:~/test/qt5_all/sqltest/sqltest$ grep -rns "sqlite3_libversion" /home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/SQLiteCpp_example1
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/SQLiteCpp_tests
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/sqlite3/libsqlite3.a
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/sqlite3/CMakeFiles/sqlite3.dir/sqlite3.c.o
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/libSQLiteCpp.a
/home/ocean/test/qt5_all/sqltest/XLIBS/SQLiteCpp/build/CMakeFiles/SQLiteCpp.dir/src/Database.cpp.o
}
Can somebody tell me why why XLIBS/SQLiteCpp/src/Column.cpp cannot read sqlite3_column_origin_name() from libsqlite3.a (sqlite3.c)? I have built XLIBS/SQLiteCpp/build/sqlite3/libsqlite3.a and then the XLIBS/SQLiteCpp/build/libSQLiteCpp.a !!

Rosbag reader in qtcreator

I try to make a rosbag reader in Qtcreator. I create a project and I just want to read informations inside the bag.
Here is my pro file:
QT += core
QT -= gui
CONFIG += c++11
TARGET = ROSBag_Reader
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
LIBS += -lboost_system
LIBS+= -lpthread
LIBS+= -L/usr/lib/x86_64-linux-gnu
LIBS+= -ltf2_ros
LIBS+= -lrostime
LIBS+= -lrospack
LIBS+= -lroslz4
LIBS+= -lroslib
LIBS+= -lroscpp_serialization
LIBS+= -lroscpp
LIBS+= -lrosconsole_print
LIBS+= -lrosconsole_bridge
LIBS+= -lrosconsole_backend_interface
LIBS+= -lrosconsole
LIBS+= -lrosbag_storage
LIBS+= -lrosbag
SOURCES += main.cpp
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
And my main.cpp:
#include <rosbag/bag.h>
#include <rosbag/view.h>
#include <std_msgs/Int32.h>
#include <std_msgs/String.h>
#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH
int main(int argc, char *argv[])
{
rosbag::Bag bag;
bag.open("/home/xxx/Bureau/Developpement/ROSBag_Reader/data/dataset_table.bag", rosbag::bagmode::Read);
std::vector<std::string> topics;
topics.push_back(std::string("chatter"));
topics.push_back(std::string("numbers"));
rosbag::View view(bag, rosbag::TopicQuery(topics));
foreach(rosbag::MessageInstance const m, view)
{
std_msgs::String::ConstPtr s = m.instantiate<std_msgs::String>();
// if (s != NULL)
// std::cout << s->data << std::endl;
/*
std_msgs::Int32::ConstPtr i = m.instantiate<std_msgs::Int32>();
if (i != NULL)
std::cout << i->data << std::endl;*/
}
bag.close();
}
But when I try to run the project I get that error:
/home/xxx/Qt/5.7/gcc_64/bin/qmake -spec linux-g++ -o Makefile ../ROSBag_Reader/ROSBag_Reader.pro
g++ -Wl,-O1 -Wl,-rpath,/home/xxx/Qt/5.7/gcc_64/lib -o ROSBag_Reader main.o -lboost_system -L/usr/lib/x86_64-linux-gnu -ltf2_ros -lrostime -lrospack -lroslz4 -lroslib -lroscpp_serialization -lroscpp -lrosconsole_print -lrosconsole_bridge -lrosconsole_backend_interface -lrosconsole -lrosbag_storage -lrosbag -L/home/xxx/Qt/5.7/gcc_64/lib -lQt5Core -lpthread
/usr/bin/ld: main.o: référence au symbole non défini «_ZN3ros6HeaderC1Ev»
//usr/lib/x86_64-linux-gnu/libcpp_common.so.0d: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:214 : la recette pour la cible « ROSBag_Reader » a échouée
I don't understand where this error comes.
Did you try what the error messages suggests you to do? add -lcpp_common to your LIBS

PRECOMPILED HEADERS not working in debug build with Qt Creator / qmake / MinGw

In Qt Creator, I have a pro file using PRECOMPILED HEADERS.
The build works just perfect when I build in Release mode. But building in Debug mode gives errors, generating object files failing. Example:
17:12:40: Running steps for project Euclide...
17:12:40: Configuration unchanged, skipping qmake step.
17:12:40: Starting: "C:\Qt\Tools\mingw48_32\bin\mingw32-make.exe"
C:\Qt\5.2.0\mingw48_32\bin\qmake.exe -spec win32-g++ CONFIG+=debug -o Makefile ..\euclide\Euclide.pro
C:/Qt/Tools/mingw48_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/UserPrograms/Euclide/build'
g++ -c -include debug\_pch.h -pipe -fno-keep-inline-dllexport -std=gnu++11 -g -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_WEBKITWIDGETS_LIB -DQT_MULTIMEDIAWIDGETS_LIB -DQT_QUICK_LIB -DQT_POSITIONING_LIB -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_WEBKIT_LIB -DQT_MULTIMEDIA_LIB -DQT_QML_LIB -DQT_WIDGETS_LIB -DQT_NETWORK_LIB -DQT_SENSORS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I..\euclide -I"..\..\..\Program Files (x86)\boost\boost_1_53_0" -I"..\numlib\mathvec" -I"..\..\..\Qt\5.2.0\mingw48_32\include" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtWebKitWidgets" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtMultimediaWidgets" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtQuick" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtPositioning" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtOpenGL" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtPrintSupport" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtWebKit" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtMultimedia" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtQml" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtWidgets" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtNetwork" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtSensors" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtGui" -I"..\..\..\Qt\5.2.0\mingw48_32\include\QtCore" -I"debug" -I"." -I"." -I"..\..\..\Qt\5.2.0\mingw48_32\mkspecs\win32-g++" -o debug\main.o ..\euclide\main.cpp
Makefile.Debug:1543: recipe for target 'debug/main.o' failed
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make[1]: Leaving directory 'C:/UserPrograms/Euclide/build'
makefile:34: recipe for target 'debug' failed
mingw32-make: *** [debug] Error 2
17:12:59: The process "C:\Qt\Tools\mingw48_32\bin\mingw32-make.exe" exited with code 2.
Error while building/deploying project Euclide (kit: Desktop Qt 5.2.0 MinGW 32bit)
When executing step 'Make'
17:12:59: Elapsed time: 00:19.
What is really confusing is that it works fine in Release. I made some tests with a small project and it works fine in Release or Debug modes, but for any reason, a bigger project is failing. It is even impossible to compile a single file of the project in Debug.
The pro file is below:
QT += core gui \
webkitwidgets \
printsupport
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Euclide
TEMPLATE = app
QMAKE_CXXFLAGS += -std=gnu++11
CONFIG += precompile_header
# Use Precompiled headers (PCH)
PRECOMPILED_HEADER = _pch.h
SOURCES += main.cpp\
mainwindow.cpp \
zero.cpp \
... lot of files here...
debug_tool.cpp
HEADERS += mainwindow.h \
zero.h \
... lot of files here...
debug_tool.h \
_pch.h
FORMS += mainwindow.ui \
zero.ui \
... other files...
apphelp.ui \
message.ui
INCLUDEPATH = "C:/Program Files (x86)/boost/boost_1_53_0"
LIBS += \
../build/release/exprcompiler.dll
RESOURCES += \
resources/euclide_resources.qrc
I spent days of extensive resarch on the net to fix this problem but not found any explanation, even if documentation about qmake is complete...
Does anyone know how to fix this problem ? because the only solution I consider now, is to have a special "Debug" version of this all project, without precompiled headers...
Thanks for your help.
I have (probably) run into the same problem and took some time to find out what is going on.
After some fiddling around to create an MWE I found, that the size of the .pch file seems to be crucial for this problem.
Using a PCH that is greater than 128 MB aborts the compilation without any message and returns code 1 (instead of 0 for succesful compilation).
My findings resemble the problem stated in this GCC mailing list entry.
It seems the only way to get it working is to reduce the size of the PCH file below 128 MB.
Just for the record:
I am using a QMake project from Qt 5.2.1 and the included MinGW (rev2) gcc 4.8.0 32bit on WinXP 32bit and Win 8 64bit.
On the other hand my GCC 4.8.2 64bit under linux ate a ~5GB PCH file without complaints (I would have tested a bigger one but compiling this one nearly exceeded my RAM).
Digging deeper
I generated a header file to use as PCH with following contents:
class _1 {};
class _2 {};
class _3 {};
class _4 {};
class _5 {};
class _6 {};
class _7 {};
class _8 {};
class _9 {};
class _10 {};
//...
Using binary search (for the number of classes in this file) I found that
filling this file with 128273 classes results in a generated PCH file that has a size of 135266564 bytes and can be used during compilation of other files.
Using 128274 classes the generated PCH file has a size of 135270660 bytes and compilation using this PCH fails.
I am not sure what to do with this information. Not giving an error message is definitely wrong but I don't know who is to blame (GCC (version?), MinGW/Windows, 32bitness).
Maybe someone with more time at hand can decide and inform the right people?

Include an assembly *.o file into a Qt C++ project

I have a Qt C++ Project.
System
Windows XP
QtCreator and QtSDK newest
C++
MinGW/gcc/g++
For performance reasons I need some functions to be done in assembly. My Project is mainly Qt and c++ but I need to link my C++ code to some assembly I wrote. I have an assembly *.o file but I can't access my assembly function from my c++ code. I complied the assembly calc.o file with nasm.
Simplified example.
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's way (Does not work on 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
The best way that I found to work with assembly in QT Creator, it was to configure the .pro file. I added the nasm compiler to .pro file and some flags. You can change these flags if you need it. But with this configuration works well for me
example.pro
QMAKE_EXTRA_COMPILERS += nasm
NASMEXTRAFLAGS = -f elf64 -g -F dwarf
OTHER_FILES += $$NASM_SOURCES
nasm.output = ${QMAKE_FILE_BASE}.o
nasm.commands = nasm $$NASMEXTRAFLAGS -o ${QMAKE_FILE_BASE}.o ${QMAKE_FILE_NAME}
nasm.input = NASM_SOURCES
Finishing, you have to assign to NASM_SOURCES variable all the ASM files, in my case it was just one and it called arregloAsm.asm
NASM_SOURCES += arregloAsm.asm
I hope that all this works for you too!
Same thing as before:
calc.S:
.data
hello:
.string "Hello World\n"
.globl helloasm
helloasm:
movl $4, %eax
movl $1, %ebx
movl $hello,%ecx
movl $12,%edx
int $0x80
ret
main.c:
#include <stdio.h>
void helloasm();
int main()
{
printf("* Calling ASM function:\n");
helloasm();
printf("* Done!\n");
return 0;
}
calc.pro:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.c \
calc.S
After putting all these files within the same directory, execute:
qmake
make
to verify the output:
$ ./calc
* Calling ASM function:
Hello World
* Done!
Why didn't you add calc.o to your sources?
I first did what was mentioned earlier:
testasm.pro
QT += core
QT -= gui
CONFIG += c++11
TARGET = testasm
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
QMAKE_EXTRA_COMPILERS += nasm
NASMEXTRAFLAGS = -f elf64 -g -F dwarf
OTHER_FILES += $$NASM_SOURCES
nasm.output = ${QMAKE_FILE_BASE}.o
nasm.commands = nasm $$NASMEXTRAFLAGS -o ${QMAKE_FILE_BASE}.o ${QMAKE_FILE_NAME}
nasm.input = NASM_SOURCES
NASM_SOURCES += test.asm
main.cpp
#include <QCoreApplication>
extern "C" void test();
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
test();
return a.exec();
}
test.asm
global test
bits 64
section .text
test:
mov rax,0
ret
In the menu Build click build all and the application should be abel to run. It's a empty terminal in this example but on my system it works.
I was looking for a solution and thanks to this post, I finally have one.
Just remember to add
extern "C" void test();
to your main.cpp file. Notice "C" in the line because that was my biggest error.
(In case of language errors: I'm no native English speaker, if you like please correct the text)