2014-03-05 87 views
2

有人可以向我解釋如何在基於Eclipse工作區的項目中使用oscpack庫?我用make創建了目標文件,將ip和osc目錄添加到我的項目樹中,並將這些目錄添加到項目設置> C/C++編譯>設置> GCC C++編譯器>包含中的包含路徑列表中。OSCPack Eclipse項目中的外部庫測試案例

我還沒有能夠在Eclipse或g ++命令行編譯器中使用它。我正在用盡想法。

該代碼是來自oscpack網站btw的SimpleReceive.cpp。

/* 
    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; 
} 

控制檯輸出:

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) 
+0

我們看不到的問題。我們相信你已經完成了與包含路徑相關的各種好東西。但是......什麼是問題?如果你沒有發佈任何符號,我們怎麼能聞到這個問題? – sehe

+0

阿施,達到: – staxas

+0

發佈更新與控制檯輸出 – staxas

回答

1

所以,你需要配置的路徑和編譯器/連接選項。

在我的Ubuntu中,apt-get install liboscpack-dev後,使用下列選項編譯的罰款:

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

在你的盒子,你可能需要的路徑添加到庫中也是如此,例如

-L /usr/local/lib/oscpack 

(我確實添加了#include <cstring>這是不可少的,雖然)

+0

謝謝,我會看看我是否可以執行這到我的Eclipse項目。 (y) – staxas

+0

我想說接受解決方案有點早:/ Upvote讚賞 – sehe

+0

我還沒有發現任何對-loscpack參數的引用,你怎麼知道它需要被添加? – staxas