Why ofxOsc doesn't work in codeblocks?

I’m just curious about this, and although I’ve read numerous ofxOsc threads around here, none of them seem to pinpoint the problem. If I run the ofxOsc example that comes with the FAT, it runs fine in codeblocks, but whenever I try to add the addon to an existing project, it always fails. I mainly use the codeblocks plugin (which works great for the other addons!) and have even tried adding ofxOsc to my project manually by adding the src files and making sure the search directories and linking settings are correct, but it never works.

I’ve resorted to just building projects off of the ofxOsc example project since that’s the only way I can get it to work, but I really hate being limited that way. Does anyone know what is different about the ofxOsc examples that makes them work? Is there some secret setting in there that must be changed other than the search directories and linker settings? Any help would be appreciated!

Post the errors you get when you create a new project with ofxOsc from scratch…

OK, I just tried adding the library manually, because after all, this could quite possibly be user error :roll:. So here is what a I did according to the install.xml file:

  1. Added src files from ofxOsc src folder to my project using Project->add files…

  2. Under project build options I selected my project name in the left navigation pane (as opposed to “release” or “debug”), and added the three include directories from the install.xml to the “search directories” tab.

  3. Under the “linker settings” tab of the build options dialog, I added the file path to the oscpack.a library.

This, according to what I can tell by comparing my project to the ofxOsc example project, is what needed to be done to get the library to work. When I build I get these errors, which all seem to relate to the networking stuff inside oscpack:

  
||=== oftest, release ===|  
||Warning: .drectve `-defaultlib:LIBCMT ' unrecognized|  
||Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized|  
||Warning: .drectve `-defaultlib:LIBCMT ' unrecognized|  
||Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized|  
||Warning: .drectve `-defaultlib:LIBCMT ' unrecognized|  
||Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized|  
||Warning: .drectve `-defaultlib:LIBCMT ' unrecognized|  
||Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized|  
||Warning: .drectve `-defaultlib:LIBCMT ' unrecognized|  
||Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized|  
||Warning: .drectve `-defaultlib:LIBCMT ' unrecognized|  
||Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized|  
||Warning: .drectve `-defaultlib:uuid.lib ' unrecognized|  
||Warning: .drectve `-defaultlib:uuid.lib ' unrecognized|  
||Warning: .drectve `-defaultlib:LIBCMT ' unrecognized|  
||Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized|  
||Warning: .drectve `/DEFAULTLIB:"LIBC" /DEFAULTLIB:"OLDNAMES" ' unrecognized|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(UdpSocket.o):UdpSocket.cpp:(.text+0x40)||undefined reference to `_htonl@4'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(UdpSocket.o):UdpSocket.cpp:(.text+0x78)||undefined reference to `_htons@4'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(UdpSocket.o):UdpSocket.cpp:(.text+0xb3)||undefined reference to `_ntohs@4'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(UdpSocket.o):UdpSocket.cpp:(.text+0xdc)||undefined reference to `_ntohl@4'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(UdpSocket.o):UdpSocket.cpp:(.text$_ZN9UdpSocket14ImplementationC1Ev[UdpSocket::Implementation::Implementation()]+0x87)||undefined reference to `_socket@12'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(UdpSocket.o):UdpSocket.cpp:(.text$_ZN9UdpSocket14ImplementationD1Ev[UdpSocket::Implementation::~Implementation()]+0x4f)||undefined reference to `_closesocket@4'|  
) const]+0xaa)||undefined reference to `_connect@12'|  
) const]+0x245)||undefined reference to `_getsockname@12'|  
) const]+0x3cf)||undefined reference to `_connect@12'|  
) const]+0x566)||undefined reference to `_connect@12'|  
) const]+0x576)||undefined reference to `_WSAGetLastError@0'|  
)]+0x70)||undefined reference to `_connect@12'|  
 int)]+0x4d)||undefined reference to `_send@16'|  
 int)]+0x13)||undefined reference to `_htonl@4'|  
 int)]+0x2d)||undefined reference to `_htons@4'|  
 int)]+0x6a)||undefined reference to `_sendto@24'|  
)]+0x6a)||undefined reference to `_bind@12'|  
 int)]+0x63)||undefined reference to `_recvfrom@24'|  
 int)]+0x86)||undefined reference to `_ntohl@4'|  
 int)]+0x9a)||undefined reference to `_ntohs@4'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(UdpSocket.o):UdpSocket.cpp:(.text$_ZN24SocketReceiveMultiplexer14Implementation3RunEv[SocketReceiveMultiplexer::Implementation::Run()]+0x19a)||undefined reference to `_WSAEventSelect@12'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(UdpSocket.o):UdpSocket.cpp:(.text$_ZN24SocketReceiveMultiplexer14Implementation3RunEv[SocketReceiveMultiplexer::Implementation::Run()]+0x833)||undefined reference to `_WSAEventSelect@12'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(UdpSocket.o):UdpSocket.cpp:(.text$_ZN24SocketReceiveMultiplexer14Implementation3RunEv[SocketReceiveMultiplexer::Implementation::Run()]+0x89a)||undefined reference to `_ioctlsocket@12'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(NetworkingUtils.o):NetworkingUtils.cpp:(.text+0x2f)||undefined reference to `_WSAStartup@8'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(NetworkingUtils.o):NetworkingUtils.cpp:(.text+0x7f)||undefined reference to `_WSAStartup@8'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(NetworkingUtils.o):NetworkingUtils.cpp:(.text+0xc3)||undefined reference to `_WSACleanup@0'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(NetworkingUtils.o):NetworkingUtils.cpp:(.text+0xf3)||undefined reference to `_WSACleanup@0'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(NetworkingUtils.o):NetworkingUtils.cpp:(.text+0x15c)||undefined reference to `_gethostbyname@4'|  
..\..\..\addons\ofxOsc\libs\oscpack\lib\win_cb\oscpack.a(NetworkingUtils.o):NetworkingUtils.cpp:(.text+0x195)||undefined reference to `_ntohl@4'|  
||=== Build finished: 29 errors, 17 warnings ===|  

Any clue on what’s going on?

can you zip up the project – this all looks like you’re somehow missing the linking with wsock32.lib

http://www.codebase.com/support/kb/?article=C01060

in your linker settings it should look like:

-lwsock32

but it should be in the project. I am happy to take a look at a zip and see what the problem is.

thanks!
zach

I checked the linker settings and lwsock32 is in fact on the list. I uploaded the zip if you want to take a look. You can grab-it-here. Any help would be appreciated.

ok cool, I checked it out and you are almost 100% proper in how you’ve hooked it up.

the problem is the linker for mingw, and the order of libraries. for example this works:

  
  
../../../libs/poco/lib/win_cb/libPocoNetmt.a  
../../../libs/poco/lib/win_cb/libPocoUtilmt.a  
../../../libs/poco/lib/win_cb/libPocoXMLmt.a  
../../../libs/poco/lib/win_cb/libPocoFoundationmt.a  
../../../addons/ofxOsc/libs/oscpack/lib/win_cb/oscpack.a  
-lopengl32  
-lglu32  
-ldsound  
-lwinmm  
-ldxguid  
-lstrmbase  
-lstrmiids  
-lz  
-luuid  
-lole32  
-loleaut32  
-lsetupapi  
-lwsock32  
-lws2_32  
-lIphlpapi  
  

but this doesn’t work (gets the errors you’ve gotten):

  
  
-lopengl32  
-lglu32  
-ldsound  
-lwinmm  
-ldxguid  
-lstrmbase  
-lstrmiids  
-lz  
-luuid  
-lole32  
-loleaut32  
-lsetupapi  
-lwsock32  
-lws2_32  
-lIphlpapi  
../../../addons/ofxOsc/libs/oscpack/lib/win_cb/oscpack.a  
  

I suspect the way you’ve included the library (on the left side “link libraries” vs the left side “other linker options” it comes out at the end of the list (like the above way that doesn’t work)

here’s some small info about why linkers might require an order – this isn’t so much a problem in other compilers but for GCC it seems to be important:

http://stackoverflow.com/questions/4513-…–order-gcc

what this means is for something specific, that might require another library (such as osc), it should be listed first – before the wsock32, etc.

does this make sense?

take care,
zach

OK, remember when I mentioned user error? :roll: When I looked at the ofxOsc example, I noticed the placement of the oscpack.a library in the “other linker options” pane, but I couldn’t figure out how to get my project to have that same line to link the library in the same order, because that side of the linker options didn’t have an “add” button like the left side. The silly thing is, I didn’t realize you could just edit the contents of that pane by clicking in the text area. I just copied in the relative path to oscpack.a in the exact place the example project file had it, and now everything compiles and links fine and the project is running. Thanks for pointing me in the right direction, zach.