I'm working on an assignment where we have to use RPCgen generated server and client .c files to exchange information about a shared drawing board. The drawing board was implemented using QtCreator and QtPainter.
The issue I'm having is that, when compiling, I get errors of undefined references both to xdr functions such as xdr_int and to functions in the class files I created inside QtCreator related to xdr. I think it's worth saying that the client/server independent code runs fine with the -ltirpc flag.
I've already tried adding the -ltirpc flag both directly in the makefile generated by the .pro + qmake, and only in the pro. file and then running through QtCreator. The LineArea function below is one of the undefined references and the first line, where it creates the client, is a reference to xdr function clnt_create.
LineArea::LineArea(char *hostname, QWidget *parent) : QWidget(parent)
{
clnt = clnt_create(hostname, WHITEBOARD_PROG, WHITEBOARD_VERSION, "udp");
if (clnt)
{
clnt_info = register_client_1(clnt_info, clnt);
setAttribute(Qt::WA_StaticContents);
press_start = false;
pen_width = 2;
pen_color = QColor(clnt_info->r, clnt_info->g, clnt_info->b);
board = QImage(500, 500, QImage::Format_RGB32);
board.fill(qRgb(255, 255, 255));
board_real = board;
update();
}
}
Here's the latest attempt at adding the compile flag to qmake/.pro:
CONFIG += c++11
SOURCES += \
LineArea.cpp \
main.cpp \
mainwindow.cpp \
whiteboard_clnt.c \
whiteboard_xdr.c
HEADERS += \
LineArea.h \
mainwindow.h \
whiteboard.h
FORMS += \
mainwindow.ui
#EXTRA FLAGS
QMAKE_CXXFLAGS += -ltirpc
Any help or suggestion is appreciated.
EDIT: these are the errors at compile time
g++ -Wl,-O1 -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o whiteboard LineArea.o main.o mainwindow.o moc_LineArea.o moc_mainwindow.o whiteboard_clnt.c whiteboard_xdr.c whiteboard.h /usr/lib/libQt5Widgets.so /usr/lib/libQt5Gui.so /usr/lib/libQt5Core.so /usr/lib/libGL.so -lpthread
/usr/bin/ld: LineArea.o: in function `LineArea::LineArea(char*, QWidget*)':
LineArea.cpp:(.text+0xa6f): undefined reference to `clnt_create'
/usr/bin/ld: /tmp/ccdM1OwC.o: in function `send_line_1':
whiteboard_clnt.c:(.text+0x43): undefined reference to `xdr_int'
/usr/bin/ld: /tmp/ccdM1OwC.o: in function `remove_client_1':
whiteboard_clnt.c:(.text+0x1cf): undefined reference to `xdr_int'
/usr/bin/ld: /tmp/cccxQLHU.o: in function `xdr_operands':
whiteboard_xdr.c:(.text+0x54): undefined reference to `xdr_int'
/usr/bin/ld: whiteboard_xdr.c:(.text+0x7e): undefined reference to `xdr_int'
/usr/bin/ld: whiteboard_xdr.c:(.text+0xa8): undefined reference to `xdr_int'
/usr/bin/ld: /tmp/cccxQLHU.o:whiteboard_xdr.c:(.text+0xd2): more undefined references to `xdr_int' follow
collect2: error: ld returned 1 exit status
make: *** [Makefile:410: whiteboard] Error 1
I'm running make manually, I've added the whiteboard_clnt.c whiteboard_xdr.c and whiteboard.h to the recipe at the makefile. Whithout them the same errors appear, except the xdr errors.
g++ -Wl,-O1 -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o whiteboard LineArea.o main.o mainwindow.o moc_LineArea.o moc_mainwindow.o /usr/lib/libQt5Widgets.so /usr/lib/libQt5Gui.so /usr/lib/libQt5Core.so /usr/lib/libGL.so -lpthread
/usr/bin/ld: LineArea.o: in function `LineArea::recvLines()':
LineArea.cpp:(.text+0x70): undefined reference to `consult_line_1'
/usr/bin/ld: LineArea.o: in function `LineArea::drawLineTo(QPoint const&)':
LineArea.cpp:(.text+0x7a0): undefined reference to `send_line_1'
/usr/bin/ld: LineArea.o: in function `LineArea::LineArea(char*, QWidget*)':
LineArea.cpp:(.text+0xa6f): undefined reference to `clnt_create'
/usr/bin/ld: LineArea.cpp:(.text+0xa86): undefined reference to `register_client_1'
collect2: error: ld returned 1 exit status
make: *** [Makefile:410: whiteboard] Error 1
QMAKE_CXXFLAGS += -ltirpc adds compiler flags, and compiler doesn't care about libraries. Assuming the lib name is correct and found without adding -L library search paths, this should work:
LIBS += -ltirrp
Related
The compiler can find all the required OpenCV header files, but it cannot find the functions included in the OpenCV library.
cv::CascadeClassifier::~CascadeClassifier()'
/usr/bin/ld: ComputerVision.cpp:(.text+0x688): undefined reference to cv::Mat::deallocate()'
/usr/bin/ld: ComputerVision.cpp:(.text+0x694): undefined reference to cv::Mat::deallocate()'
/usr/bin/ld: ComputerVision.cpp:(.text+0x6a0): undefined reference to cv::Mat::deallocate()'
/usr/bin/ld: ComputerVision.cpp:(.text+0x6ac): undefined reference to cv::Mat::deallocate()'
/usr/bin/ld: ComputerVision.cpp:(.text+0x6dc): undefined reference to cv::VideoCapture::~VideoCapture()'
/usr/bin/ld: ComputerVision.cpp:(.text+0x6e4): undefined reference to cv::CascadeClassifier::~CascadeClassifier()'
/usr/bin/ld: ComputerVision.o: in function cv::Mat::~Mat()':
ComputerVision.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x90): undefined reference to cv::fastFree(void)'
/usr/bin/ld: ComputerVision.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x9c): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
make: ** [Makefile:158: DoorLock] Error 1
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_imgproc
/usr/bin/ld: cannot find -lopencv_highgui
Update - I copied all the required OpenCV libraries into my usr/lib directory, and that seemed to work. But now I am getting the following error:
libopencv_videoio.so.4.1: error adding symbols: DSO missing from command line
For reference, he is my qmake (.pro) file:
######################################################################
# Automatically generated by qmake (3.1) Sat Nov 27 20:12:38 2021
######################################################################
TEMPLATE = app
TARGET = DoorLock
INCLUDEPATH += . "/home/pi/temp/opencv4"
###"/opt/opencv-4.1.0/include/opencv4"
# The following define makes your compiler warn you if you use any
# feature of Qt which has been marked as 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
# Input
HEADERS += Controller.h Inputs.h lcdScreen.h Outputs.h ComputerVision.h
SOURCES += Controller.cpp Inputs.cpp lcdScreen.cpp main.cpp Outputs.cpp ComputerVision.cpp
LIBS += -lpthread -lwiringPi -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_features2d -lopencv_objdetect -lopencv_videoio
QT += core widgets
CONFIG += qt warn_on release
Note temp is a symbolic link to the correct directory
(FYI Yes I do know that a similar question exists, But I have already tried all the answers.)
I'm trying to setup SDL2 with MinGW and I have everything set up beside one thing. Whenever I try to compile G++ gives no errors but then LD gives me a: undefined reference to SDL_Init Error.
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc28dE2R.o: in function `SDL_main':
C:\Users\user\Documents\SDL2/src/main.cpp:11: undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:14: undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:18: undefined reference to `IMG_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:20: undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:\MinGW\bin\g++.exe -g src\*.cpp -o build\game.exe -ID:C:\MinGW\include -LD:C:\MinGW\lib -mwindows -lmingw32 -lSDL2main -lSDL2_image -lSDL2" terminated with exit code: 1.
I have tried to move the args around. doing -mwindows, adding -lmingw32. I still keep getting the same errors.. I was able to fix the WinMain Error.. But everything else I couldn't fix.
The command I'm Running to compile:
C:\MinGW\bin\g++.exe -g src\*.cpp -o build\game.exe -ID:C:\MinGW\include -LD:C:\MinGW\lib -mwindows -lSDL2main -lSDL2_image -lSDL2
If i could get any help that would be amazing
The common cause of mysterious undefined reference errors on MinGW is using libraries compiled for x64 with an x32 compiler, or vice versa. SDL ships both x32 and x64 ones, try the other ones.
I was able to fix the WinMain Error
Be aware that the intended way of fixing undefined reference to WinMain#16 is not adding #define SDL_MAIN_HANDLED and not doing #undef main. Once you get the right libraries (see the first paragraph), the error should disappear by itself.
Make sure you use int main(int, char**) (and not int main() nor void main()), otherwise it won't work.
-ID:C:\MinGW\include -LD:C:\MinGW\lib
You shouldn't need those flags. Those directories will be searched automatically.
Since you didn't specify any other directories, I assume you placed the SDL files directly into the compiler directories, which isn't a good practice, IMO.
I assume D:C: a typo?
-mwindows
The only purpose of this flag (that I know of) is to prevent your app from automatically opening a terminal window for itself, for release builds.
I want to compile program for windows from debian
> '/opt/mingw32/bin/i686-w64-mingw32-g++' '/home/redrockfish/Projects/OpenGl0/main.cpp' -o arcanoid.exe -static-libstdc++ -static-libgcc -lglu32 -lopengl32 -lglut32
/tmp/ccrvQIKM.o:main.cpp:(.text+0x1c): undefined reference to `_imp____glutInitWithExit#12'
/tmp/ccrvQIKM.o:main.cpp:(.text+0x3e): undefined reference to `_imp____glutCreateWindowWithExit#8'
/tmp/ccrvQIKM.o:main.cpp:(.text+0x60): undefined reference to `_imp____glutCreateMenuWithExit#8'
/opt/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.9.0/../../../../i686-w64-mingw32/bin/ld: /tmp/ccrvQIKM.o: bad reloc address 0x0 in section `.ctors'
collect2: error: ld returned 1 exit status
if I remove -lglut32 the number of underfined references increases. header if freeglut.h, taken from official website. replacing glut32 with glut, adding -lGLU didn't help. with -lGL
cannot find -lGL
collect2: error: ld returned 1 exit status
Functions like __glutCreateWindowWithExit are not part of the official GLUT API. Actually, that function is an extension made by freeglut (and not even part of their external API), so you must not link some random GLUT DLL, but a freeglut one (which are available for windows).
I am following this example here.
This is the output I get for make
admin#localhost qtest$ make
g++ -Wl,-O1 -Wl,-rpath,/home/admin/Qt/5.3/gcc_64 -Wl,-rpath,/home/admin/Qt/5.3/gcc_64/lib -o qtest qtest.o -L/home/admin/Qt/5.3/gcc_64/lib -lQt5Gui -lQt5Core -lGL -lpthread
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
make: *** [qtest] Error 1
admin#localhost qtest$
My cpp file is this
#include <QtWidgets/qapplication.h>
#include <QtWidgets/qpushbutton.h>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );
hello.show();
return a.exec();
}
Any suggestions on how I can fix this ?
Update
This is what I get after
sudo yum install mesa-libGL-devel -y
Trying again to build :
admin#localhost qtest$ make
g++ -Wl,-O1 -Wl,-rpath,/home/admin/Qt/5.3/gcc_64 -Wl,-rpath,/home/admin/Qt/5.3/gcc_64/lib -o qtest qtest.o -L/home/admin/Qt/5.3/gcc_64/lib -lQt5Gui -lQt5Core -lGL -lpthread
qtest.o: In function `main':
qtest.cpp:(.text.startup+0x22): undefined reference to `QApplication::QApplication(int&, char**, int)'
qtest.cpp:(.text.startup+0x4f): undefined reference to `QPushButton::QPushButton(QString const&, QWidget*)'
qtest.cpp:(.text.startup+0x74): undefined reference to `QWidget::resize(QSize const&)'
qtest.cpp:(.text.startup+0x7c): undefined reference to `QWidget::show()'
qtest.cpp:(.text.startup+0x81): undefined reference to `QApplication::exec()'
qtest.cpp:(.text.startup+0x8c): undefined reference to `QPushButton::~QPushButton()'
qtest.cpp:(.text.startup+0x94): undefined reference to `QApplication::~QApplication()'
qtest.cpp:(.text.startup+0xab): undefined reference to `QApplication::~QApplication()'
qtest.cpp:(.text.startup+0xbe): undefined reference to `QPushButton::~QPushButton()'
qtest.cpp:(.text.startup+0xce): undefined reference to `QPushButton::~QPushButton()'
collect2: error: ld returned 1 exit status
make: *** [qtest] Error 1
To solve your error :
/usr/bin/ld: cannot find -lGL
you should install the missing mesa package by running the following install command as root or using sudo :
sudo yum install mesa-libGL-devel -y
Open up your foo.pro file.
You probably have something like:
######################################################################
# Automatically generated by qmake (3.0) Mon Nov 17 14:00:29 2014
######################################################################
TEMPLATE = app
TARGET = test
INCLUDEPATH += .
# Input
SOURCES += foo.cpp
Add to the top, "QT += widgets", such that your file now reads:
######################################################################
# Automatically generated by qmake (3.0) Mon Nov 17 14:00:29 2014
######################################################################
QT += widgets
TEMPLATE = app
TARGET = test
INCLUDEPATH += .
# Input
SOURCES += foo.cpp
then run qmake and make. This should allow it to find the relevant headers.
Your second error is not with libraries, but with finding the QtCore and QtWidgets modules of Qt.
I'm following this tutorial for building a simple OpenGl application in C++ using QT.
I'm trying to compile the application using g++ and the command line but I get the following errors:
/tmp/ccH2KFoZ.o: In function `GLWidget::GLWidget(QWidget*)':
GLWidget.cpp:(.text+0x38): undefined reference to `QGLWidget::QGLWidget(QWidget*, QGLWidget const*, QFlags<Qt::WindowType>)'
GLWidget.cpp:(.text+0x41): undefined reference to `vtable for GLWidget'
GLWidget.cpp:(.text+0x4b): undefined reference to `vtable for GLWidget'
GLWidget.cpp:(.text+0x5e): undefined reference to `QGLWidget::setMouseTracking(bool)'
GLWidget.cpp:(.text+0x6f): undefined reference to `QGLWidget::~QGLWidget()'
/tmp/ccH2KFoZ.o: In function `GLWidget::GLWidget(QWidget*)':
GLWidget.cpp:(.text+0xbe): undefined reference to `QGLWidget::QGLWidget(QWidget*, QGLWidget const*, QFlags<Qt::WindowType>)'
GLWidget.cpp:(.text+0xc7): undefined reference to `vtable for GLWidget'
GLWidget.cpp:(.text+0xd1): undefined reference to `vtable for GLWidget'
GLWidget.cpp:(.text+0xe4): undefined reference to `QGLWidget::setMouseTracking(bool)'
GLWidget.cpp:(.text+0xf5): undefined reference to `QGLWidget::~QGLWidget()'
/tmp/ccH2KFoZ.o: In function `GLWidget::resizeGL(int, int)':
GLWidget.cpp:(.text+0x1e1): undefined reference to `gluOrtho2D'
/tmp/ccH2KFoZ.o: In function `GLWidget::keyPressEvent(QKeyEvent*)':
GLWidget.cpp:(.text+0x2dd): undefined reference to `QWidget::close()'
/tmp/ccDIuk1w.o: In function `main':
main.cpp:(.text+0x29): undefined reference to `QApplication::QApplication(int&, char**, int)'
main.cpp:(.text+0x6a): undefined reference to `QApplication::exec()'
main.cpp:(.text+0xa0): undefined reference to `QApplication::~QApplication()'
main.cpp:(.text+0xb8): undefined reference to `QApplication::~QApplication()'
/tmp/ccDIuk1w.o: In function `QWidget::resize(int, int)':
main.cpp:(.text._ZN7QWidget6resizeEii[QWidget::resize(int, int)]+0x2d): undefined reference to `QWidget::resize(QSize const&)'
/tmp/ccDIuk1w.o: In function `GLWidget::~GLWidget()':
main.cpp:(.text._ZN8GLWidgetD1Ev[GLWidget::~GLWidget()]+0x13): undefined reference to `vtable for GLWidget'
main.cpp:(.text._ZN8GLWidgetD1Ev[GLWidget::~GLWidget()]+0x1d): undefined reference to `vtable for GLWidget'
main.cpp:(.text._ZN8GLWidgetD1Ev[GLWidget::~GLWidget()]+0x28): undefined reference to `QGLWidget::~QGLWidget()'
collect2: ld returned 1 exit status
I've tried searching for a solution but all the solutions I can suggest altering a .pro file which I assume is something used by Netbeans or Codeblocks, neither of which I'm using.
What are the correct command line flags to pass to g++ so I can compile this application?
Here is the g++ command I'm currently using:
g++ *.cpp -I/usr/include/qt4 -I/usr/include/qt4/Qt -I/usr/include/QtCore -I/usr/include/QtGui -lGL
Edit: I ended up using a project file that looks like this.
TEMPLATE = app
TARGET = glQt
QT += opengl
HEADERS += \
GLWidget.h
SOURCES += \
GLWidget.cpp \
main.cpp
The .pro file is needed by QMake, the make app distributed with Qt.
This pro file specifies all the files needed to build your project, as well as the Qt modules.
More about qmake and the .pro file here: http://qt-project.org/doc/qt-4.8/qmake-manual.html
If you install the IDE QtCreator, the task of modifying the .pro file and compiling your app will be a bit easier.
After you modify the .pro file, you usually build the Qt app using the command qmake, which produces a make file ready to be used by your system (on Windows it can also produce .sln solutions for Visual Studio)
A short .pro file from one of my projects:
TEMPLATE = app
TARGET = icat2browser
QT += network webkit <-- add here the opengl module
DEFINES += QT_LARGEFILE_SUPPORT
HEADERS += \
qicat2networkaccessmanager.h \
ctimeline.h \
cobjectsview.h \
cicat2WebResponse.h \
cicat2usersdialog.h \
cicat2previewdialog.h \
cicat2login.h \
cicat2clients.h \
cicat2browser.h \
SOURCES += \
qicat2networkaccessmanager.cpp \
main.cpp \
ctimeline.cpp \
cobjectsview.cpp \
cicat2WebResponse.cpp \
cicat2usersdialog.cpp \
cicat2previewdialog.cpp \
cicat2login.cpp \
cicat2clients.cpp \
cicat2browser.cpp \
It looks like you are having a linker error. Although I have not used Qt, but from the way you compiling it looks like you are not linking Qt libraries. Try linking Qt libraries while building your example as follows (untested):
g++ *.cpp -I./ -I/usr/include/qt4 -I/usr/include/qt4/Qt -I/usr/include/QtCore -I/usr/include/QtGui -lGL -lQtCore -lQtGui -lQtOpenGL
I am guessing you must have installed development packages for Qt libraries in which case most likely you will have pkg-config files i.e. .pc files on you system in /usr/lib/pkgconfig. Try compiling as follows (untested):
g++ *.cpp -I./ `pkg-config --cflags --libs QtOpenGL`
Hope this helps!
I suggest you use qmake to generate a correct Makefile for your Qt installation. Using QtCreator simplifies this. Write a .pro file which is 5 lines of code and remember to add QT += opengl. Then run qmake and make.
I HIGHLY recommend you use qmake! Otherwise you will have to manually call the moc, uic, and rcc yourself!