I've seen several similar posts but have been unable to fix my specific problem.
I want to use oscpack, described here, http://www.rossbencina.com/code/oscpack
and downloaded here, https://github.com/hecomi/qml-osc and then clicked on the button 'clone or download', then 'Download ZIP' link.
Note: the link I had previously, 'https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/oscpack/oscpack_1_1_0.zip' was incorrect.
Note2: I also installed oscpack on my Ubuntu 18.04 system:
$ sudo apt-get -y install liboscpack-dev liboscpack1
After including this library in my project - the moment I add the header files, and - I get multiple undefined reference errors; for example:
undefined reference to `UdpSocket::Connect(IpEndpointName const&)'
I get the errors regardless of whether I use:
LIBS += -L"/developer/3rdPartyLibs/osc/lib" -loscpack # from the downloaded ZIP file
or
LIBS += -L"/usr/lib/x86_64-linux-gnu" -loscpack # from the linux package
in my SampleProject.pro file.
I saw a very similar post/problem here: Linking a static library to my project on Visual Studio 2010
And I believe I have the same error, and that the solution is similar (it's just that I'm developing on Ubuntu 18.04 instead of Windows). I just haven't figured out how to give the linker what it needs. I expect that the linker can't find the library associated with 'sys/sockets.h', but I don't know where to find it either. I'm using Qt Creator 4.10.2, with Qt_5_13_2_GCC_64bit-Debug.
If you're not familiar with QtCreator but know what command-line arguments need to be passed to ld (and/or g++), that would still be a great help - I can try to figure out where to add that in the IDE.
I suspect no additional information will be required for this problem, but just in case, the code is below.
Thanks!
minimal project (main.qml):
import QtQuick 2.13
import QtQuick.Controls 2.5
import QtQml 2.13
import OSC 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Scroll")
Rectangle {
width: 360
height: 360
Text {
id: message
anchors.centerIn: parent
}
OSCReceiver {
port: 3333
onMessage: {
message.text = address + ' : ' + msg;
}
}
OSCSender {
id: osc
ip: '127.0.0.1'
port: 3333
}
Timer {
property int cnt: 0
interval: 1000/60
running: true
repeat: true
onTriggered: {
osc.send('/Hoge/cnt', ++cnt);
}
}
}
}
project file (SampleProject.pro):
QT += quick
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Refer to the documentation for the
# deprecated API to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp
RESOURCES += qml.qrc
LIBS += -L"/developer/3rdPartyLibs/osc/lib" -loscpack # add for oscpack
INCLUDEPATH += /developer/3rdPartyLibs/osc # add for oscpack
include(/developer/3rdPartyLibs/osc/osc.pri) # add for oscpack
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
and main.cpp file:
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <osc_receiver.h> // add for oscpack
#include <osc_sender.h> // add for oscpack
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
qmlRegisterType<OSCReceiver>("OSC", 1, 0, "OSCReceiver"); // add for oscpack
qmlRegisterType<OSCSender>("OSC", 1, 0, "OSCSender"); // add for oscpack
QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
This is the output:
14:27:49: Running steps for project SampleProject... 14:27:49: Configuration unchanged, skipping qmake step. 14:27:50: Starting: "/usr/bin/make" -j8 g++ -Wl,-rpath,/opt/Qt/5.13.2/gcc_64/lib -o SampleProject main.o osc_sender.o osc_receiver.o qrc_qml.o moc_osc_sender.o moc_osc_receiver.o -L/developer/3rdPartyLibs/osc/lib -loscpack /opt/Qt/5.13.2/gcc_64/lib/libQt5Quick.so /opt/Qt/5.13.2/gcc_64/lib/libQt5Gui.so /opt/Qt/5.13.2/gcc_64/lib/libQt5Qml.so /opt/Qt/5.13.2/gcc_64/lib/libQt5Network.so /opt/Qt/5.13.2/gcc_64/lib/libQt5Core.so -lGL -lpthread -loscpack osc_sender.o: In function
OSCSender::setIp(QString const&)': /developer/builds/qt/build-SampleProject-Desktop_Qt_5_13_2_GCC_64bit-Debug/../../../3rdPartyLibs/osc/osc_sender.cpp:21: undefined reference to
UdpSocket::Connect(IpEndpointName const&)' osc_sender.o: In functionOSCSender::setPort(int)': /developer/builds/qt/build-SampleProject-Desktop_Qt_5_13_2_GCC_64bit-Debug/Makefile:255: recipe for target 'SampleProject' failed ../../../3rdPartyLibs/osc/osc_sender.cpp:38: undefined reference to
UdpSocket::Connect(IpEndpointName const&)' osc_sender.o: In functionOSCSender::send(QString const&, QString const&)': /developer/builds/qt/build-SampleProject-Desktop_Qt_5_13_2_GCC_64bit-Debug/../../../3rdPartyLibs/osc/osc_sender.cpp:55 ... ...many similar lines... ... undefined reference to
SocketReceiveMultiplexer::~SocketReceiveMultiplexer()' /developer/builds/qt/build-SampleProject-Desktop_Qt_5_13_2_GCC_64bit-Debug/../../../3rdPartyLibs/osc/include/ip/UdpSocket.h:166: undefined reference toUdpSocket::~UdpSocket()' osc_receiver.o: In function
UdpListeningReceiveSocket::Run()': /developer/builds/qt/build-SampleProject-Desktop_Qt_5_13_2_GCC_64bit-Debug/../../../3rdPartyLibs/osc/include/ip/UdpSocket.h:169: undefined reference toSocketReceiveMultiplexer::Run()' osc_receiver.o:(.data.rel.ro._ZTI25UdpListeningReceiveSocket[_ZTI25UdpListeningReceiveSocket]+0x10): undefined reference to
typeinfo for UdpSocket' collect2: error: ld returned 1 exit status make: *** [SampleProject] Error 1 14:27:51: The process "/usr/bin/make" exited with code 2.