问题
I am using an example program that is supposed to allow control of MIDI devices using a protocol called OSC.
What I have done is downloaded the SDK from here: http://mac.softpedia.com/get/Development/Libraries/oscpack.shtml
The 'examples' folder contains a file called 'SimpleSend.cpp'. The code for this is as follows:
#include "osc/OscOutboundPacketStream.h"
#include "ip/UdpSocket.h"
#define ADDRESS "127.0.0.1"
#define PORT 7000
#define OUTPUT_BUFFER_SIZE 1024
int main(int argc, char* argv[])
{
UdpTransmitSocket transmitSocket( IpEndpointName( ADDRESS, PORT ) );
char buffer[OUTPUT_BUFFER_SIZE];
osc::OutboundPacketStream p( buffer, OUTPUT_BUFFER_SIZE );
p << osc::BeginBundleImmediate
<< osc::BeginMessage( "/test1" )
<< true << 23 << (float)3.1415 << "hello" << osc::EndMessage
<< osc::BeginMessage( "/test2" )
<< true << 24 << (float)10.8 << "world" << osc::EndMessage
<< osc::EndBundle;
transmitSocket.Send( p.Data(), p.Size() );
}
I have opened Visual C++ and created a new (CLR console application) project, called 'osctemp'. I copy the code from the 'SimpleSend.cpp' file and paste this into the main cpp file that is created for my project, keeping the following lines of code from the default project file:
#include "stdafx.h"
using namespace System;
I then navigate to the stdafx.h header file and notice that it contains at the bottom the line:
// TODO: reference additional headers your program requires here
...So I obediently move the includes and defines from my main cpp file to here.
I also notice that I need to add the includes to my project so in Windows Explorer I copy the folders 'osc' and 'ip' into my project folder.
Upon running, I receive the following errors:
1>------ Build started: Project: osctemp, Configuration: Debug Win32 ------
1> stdafx.cpp
1> AssemblyInfo.cpp
1> osctemp.cpp
1> Generating Code...
1> .NETFramework,Version=v4.0.AssemblyAttributes.cpp
1>osctemp.obj : error LNK2028: unresolved token (0A00000A) "public: char const * __thiscall osc::OutboundPacketStream::Data(void)const " (?Data@OutboundPacketStream@osc@@$$FQBEPBDXZ) referenced in function "int __cdecl main(int,char * * const)" (?main@@$$HYAHHQAPAD@Z)
1>osctemp.obj : error LNK2028: unresolved token (0A00000B) "public: unsigned int __thiscall osc::OutboundPacketStream::Size(void)const " (?Size@OutboundPacketStream@osc@@$$FQBEIXZ) referenced in function "int __cdecl main(int,char * * const)" (?main@@$$HYAHHQAPAD@Z)
1>osctemp.obj : error LNK2028: unresolved token (0A00000C) "public: void __thiscall UdpSocket::Send(char const *,int)" (?Send@UdpSocket@@$$FQAEXPBDH@Z) referenced in function "int __cdecl main(int,char * * const)" (?main@@$$HYAHHQAPAD@Z)
...(And many more like this)...
1>D:\Temp\OSCTEMP\osctemp\Debug\osctemp.exe : fatal error LNK1120: 40 unresolved externals
What have I missed?
回答1:
From your problem description I can't find anything about how you link towards the SDK libraries. Have you done so?
To link with the SDK libraries you need one or more .lib files. Even if the SDK is distributed as DLL you need a lib file for the build-time linkage. You should read through the SDK documentation and look for guidelines about link dependencies.
If you can't seem to find any lib-files in the SDK distribution it could very well be that you need to first build the SDK to produce a library and then link towards it. Alternatively, if the SDK comes with a ready VS project you can add it to your solution and set your own project to depend on it (i.e. VS does the work of finding the output lib and linking with it).
Again, if the SDK is of any descent standard, there should be docs about building the SDK yourself if that's necessary.
Good luck.
回答2:
You're either not pulling in the correct library, or your prototype is not defining the library function correctly according to what's actually in it.
来源:https://stackoverflow.com/questions/6153765/unresolved-external-symbol-errors