2

Can someone explain to me how to use the oscpack library in an Eclipse workspace based project? I have created the object files with make, added the ip and osc directories to my project tree, and added these directories to the include path list in Project settings>C/C++ Build>Settings>GCC C++ Compiler>Includes.

I haven't been able to get it working in Eclipse or the g++ commandline compiler. I am running out of ideas.

The code is the SimpleReceive.cpp from the oscpack site btw.

/* 
    Example of two different ways to process received OSC messages using oscpack.
    Receives the messages from the SimpleSend.cpp example.
*/

#include <iostream>

#include "osc/OscReceivedElements.h"
#include "osc/OscPacketListener.h"
#include "ip/UdpSocket.h"


#define PORT 7000

class ExamplePacketListener : public osc::OscPacketListener {
protected:

    virtual void ProcessMessage( const osc::ReceivedMessage& m, 
                const IpEndpointName& remoteEndpoint )
    {
        try{
            // example of parsing single messages. osc::OsckPacketListener
            // handles the bundle traversal.

            if( strcmp( m.AddressPattern(), "/test1" ) == 0 ){
                // example #1 -- argument stream interface
                osc::ReceivedMessageArgumentStream args = m.ArgumentStream();
                bool a1;
                osc::int32 a2;
                float a3;
                const char *a4;
                args >> a1 >> a2 >> a3 >> a4 >> osc::EndMessage;

                std::cout << "received '/test1' message with arguments: "
                    << a1 << " " << a2 << " " << a3 << " " << a4 << "\n";

            }else if( strcmp( m.AddressPattern(), "/test2" ) == 0 ){
                // example #2 -- argument iterator interface, supports
                // reflection for overloaded messages (eg you can call 
                // (*arg)->IsBool() to check if a bool was passed etc).
                osc::ReceivedMessage::const_iterator arg = m.ArgumentsBegin();
                bool a1 = (arg++)->AsBool();
                int a2 = (arg++)->AsInt32();
                float a3 = (arg++)->AsFloat();
                const char *a4 = (arg++)->AsString();
                if( arg != m.ArgumentsEnd() )
                    throw osc::ExcessArgumentException();

                std::cout << "received '/test2' message with arguments: "
                    << a1 << " " << a2 << " " << a3 << " " << a4 << "\n";
            }
        }catch( osc::Exception& e ){
            // any parsing errors such as unexpected argument types, or 
            // missing arguments get thrown as exceptions.
            std::cout << "error while parsing message: "
                << m.AddressPattern() << ": " << e.what() << "\n";
        }
    }
};

int main(int argc, char* argv[])
{
    ExamplePacketListener listener;
    UdpListeningReceiveSocket s(
            IpEndpointName( IpEndpointName::ANY_ADDRESS, PORT ),
            &listener );

    std::cout << "press ctrl-c to end\n";

    s.RunUntilSigInt();

    return 0;
}

Console output:

15:38:50 **** Incremental Build of configuration Debug for project NoteMaker_v2 ****
make all 
Building target: NoteMaker_v2
Invoking: MacOS X C++ Linker
g++  -o "NoteMaker_v2"  ./src/CommonFunctions.o ./src/DummyGen.o ./src/FileInterpreter.o ./src/GenAdmin.o ./src/Generator.o ./src/MusicalFunctions.o ./src/NoteBlock.o ./src/NoteMaker_v2.o ./src/NoteStack.o ./src/Serialism.o   
Undefined symbols for architecture x86_64:
  "osc::EndMessage", referenced from:
      ExamplePacketListener::ProcessMessage(osc::ReceivedMessage const&, IpEndpointName const&) in NoteMaker_v2.o
  "osc::ReceivedBundle::ReceivedBundle(osc::ReceivedPacket const&)", referenced from:
      osc::OscPacketListener::ProcessPacket(char const*, int, IpEndpointName const&) in NoteMaker_v2.o
  "osc::ReceivedBundle::ReceivedBundle(osc::ReceivedBundleElement const&)", referenced from:
      osc::OscPacketListener::ProcessBundle(osc::ReceivedBundle const&, IpEndpointName const&) in NoteMaker_v2.o
  "osc::ReceivedMessage::ReceivedMessage(osc::ReceivedPacket const&)", referenced from:
      osc::OscPacketListener::ProcessPacket(char const*, int, IpEndpointName const&) in NoteMaker_v2.o
  "osc::ReceivedMessage::ReceivedMessage(osc::ReceivedBundleElement const&)", referenced from:
      osc::OscPacketListener::ProcessBundle(osc::ReceivedBundle const&, IpEndpointName const&) in NoteMaker_v2.o
  "osc::ReceivedMessageArgumentIterator::Advance()", referenced from:
      osc::ReceivedMessageArgumentIterator::operator++(int) in NoteMaker_v2.o
  "osc::ReceivedPacket::IsBundle() const", referenced from:
      osc::OscPacketListener::ProcessPacket(char const*, int, IpEndpointName const&) in NoteMaker_v2.o
  "osc::ReceivedBundleElement::Size() const", referenced from:
      osc::ReceivedBundleElementIterator::Advance() in NoteMaker_v2.o
  "osc::ReceivedBundleElement::IsBundle() const", referenced from:
      osc::OscPacketListener::ProcessBundle(osc::ReceivedBundle const&, IpEndpointName const&) in NoteMaker_v2.o
  "osc::ReceivedMessageArgument::AsBool() const", referenced from:
      ExamplePacketListener::ProcessMessage(osc::ReceivedMessage const&, IpEndpointName const&) in NoteMaker_v2.o
      osc::ReceivedMessageArgumentStream::operator>>(bool&) in NoteMaker_v2.o
  "osc::ReceivedMessageArgument::AsFloat() const", referenced from:
      ExamplePacketListener::ProcessMessage(osc::ReceivedMessage const&, IpEndpointName const&) in NoteMaker_v2.o
      osc::ReceivedMessageArgumentStream::operator>>(float&) in NoteMaker_v2.o
  "osc::ReceivedMessageArgument::AsInt32() const", referenced from:
      ExamplePacketListener::ProcessMessage(osc::ReceivedMessage const&, IpEndpointName const&) in NoteMaker_v2.o
      osc::ReceivedMessageArgumentStream::operator>>(int&) in NoteMaker_v2.o
  "osc::ReceivedMessageArgument::AsString() const", referenced from:
      ExamplePacketListener::ProcessMessage(osc::ReceivedMessage const&, IpEndpointName const&) in NoteMaker_v2.o
      osc::ReceivedMessageArgumentStream::operator>>(char const*&) in NoteMaker_v2.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [NoteMaker_v2] Error 1

15:38:50 Build Finished (took 279ms)
sehe
  • 374,641
  • 47
  • 450
  • 633
staxas
  • 149
  • 12
  • We're don't see the problem. We believe that you've done all kinds of Good Stuff related to the include paths. But... _what is the matter_? If you don't post any symtoms, how can we smell the problem? – sehe Mar 05 '14 at 14:38
  • Ah sry, getting to that: – staxas Mar 05 '14 at 14:39
  • Post updated with console output – staxas Mar 05 '14 at 14:41
  • Okey, thats output from the actual project I am trying to implement to, but thats pretty much the problem. – staxas Mar 05 '14 at 14:42
  • So, that's a linker error. Did you include the library in the linker options? -losc or -loscpack or similar, I expect – sehe Mar 05 '14 at 14:42
  • I've added the paths to the MacOSX C++ Linker library paths, but now I'm getting this: ../src/ip/win32/NetworkingUtils.cpp:37:10: fatal error: 'ip/NetworkingUtils.h' file not found #include "ip/NetworkingUtils.h" – staxas Mar 05 '14 at 14:46
  • Ill add it to the includes search path – staxas Mar 05 '14 at 14:47

1 Answers1

1

So you needed to configure the paths and compiler/linker options.

On my ubuntu box, after apt-get install liboscpack-dev it compiled fine using the following options:

g++ -Wall -pedantic -g -O0 -I /usr/include/oscpack test.cpp -o test -loscpack

On your box you might need to add the path to the library too, e.g.

-L /usr/local/lib/oscpack

(I did add #include <cstring> that was missing, though)

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thank you, I will see if I can implement this into my Eclipse project. (y) – staxas Mar 05 '14 at 14:50
  • I'd say it's a bit early to accept as a solution then :/ Upvote appreciated – sehe Mar 05 '14 at 14:50
  • I havent found any references to the -loscpack argument, how do you know it needs to be added? – staxas Mar 05 '14 at 15:05
  • Ended up compiling the oscpack with make, and adding the objects by hand in linker properties, and adding the .h files in the appropriate ip and osc dirs in the src folder. Something works now (y) – staxas Mar 05 '14 at 15:26