未解决的外部符号错误消息 [英] unresolved external symbol error message
问题描述
我遇到了错误LNK2019和LNK2005问题。我基本上设计了.Lib文件并尝试通过普通的控制台应用程序访问该文件。
Lib文件的详细信息:
(.h文件)
Hi, I have encountered error LNK2019 and LNK2005 issues. I had designed basically a .Lib file and tried to access the file through a normal console application.
the details of the Lib file:
(.h file)
#ifndef VNS_Lib_H_
#define VNS_Lib_H_
#pragma comment(lib,"ws2_32.lib") //Winsock Library
#include <WinSock2.h>
#include <errno.h>
#include <windows.h>
#include <process.h>
#include <algorithm>
#define LOC_ERRNO errno
bool threadFinished = false;
// This class is exported from the Ether.Lib
namespace WAVE_VNS
{
class VNS{
char receive[512];
unsigned char *received;
int vnsSocket;
bool Running;
//This variable is the signal for our thread to stop execution.
//If it's True then thread will gently stop.
bool End;
//This variable is miliseconds of delay for our join function.
//I'll explain it later.
int join_time;
//This is the identifier of our thread, each one has it's
//own unique identifier.
DWORD tid;
//This is the handle to our thread system give us when
//Thread is created.
HANDLE handle;
public:
/*message is transmitted once after each message received indicating success or failure of received commands/data [FROM INU]*/
struct Acknowledge {
static const unsigned int Ack_ID = 0x82;
unsigned int Error_Type;
unsigned int Reject_Msg_ID;
unsigned int DACK_Msg_ID;
unsigned int DACK_Msg_Counter;
unsigned int DNACK_Msg_ID;
unsigned int DNACK_Msg_Counter;
};
/* message Transmit Rate definition. IF validity is 0 or update rate 0, message will not be transmitted continuously [FROM INU]*/
struct Transmit_Rate_DEF_R {
static const unsigned int TR_ID = 0x8A;
unsigned long Validity;
unsigned int TX_Msg_1_ID;
unsigned int TX_Rate_Msg_1;
unsigned int TX_Msg_2_ID;
unsigned int TX_Rate_Msg_2;
unsigned int TX_Msg_3_ID;
unsigned int TX_Rate_Msg_3;
unsigned int TX_Msg_4_ID;
unsigned int TX_Rate_Msg_4;
unsigned int TX_Msg_5_ID;
unsigned int TX_Rate_Msg_5;
};
/*message used for setting ethernet communication parameters[FROM INU]*/
struct Ether_Confg_Msg_RB_R {
static const unsigned int EC_ID = 0x8C;
unsigned char *MAC_Source;
unsigned char *MAC_Dest;
unsigned char *IP_Source;
unsigned char *IP_Dest;
unsigned int src_port;
unsigned int dest_port;
};
/*message used to provide system parameters and is transmitted upon request[FROM INU]*/
struct System_Parameter_R {
static const unsigned int SP_ID = 0x90;
unsigned long Validity;
unsigned int Map_Datum;
unsigned int heading;
unsigned int altitude;
int utc_TO_hrs;
int utc_TO_mins;
int VMS;
unsigned int mount_pols;
int misalign_Roll;
int misalign_Pitch;
int Angle_Hdg;
unsigned int INU_Mode;
int GPS_X;
int GPS_Y;
int GPS_Z;
unsigned int NMEA_GPS_BR;
unsigned int VMS_Type;
unsigned int GPS_Type_Mode;
unsigned int GSSIP_Init;
unsigned int GSSIP_Mode;
};
/*message: cyclic 4hz. Rate can be changed by Transmission Rate Definition message [FROM INU]*/
struct STD_Output{
static const unsigned int STD_ID = 0x91;
unsigned int Validity_HI;
unsigned int Validity_LO;
unsigned int Update_Counter;
unsigned int Status;
unsigned int Alert;
unsigned int Map_Datum;
unsigned int heading_Format;
unsigned int altitude_Format;
float UTM_Northing;
float UTM_Easting;
unsigned int UTM_Zone;
char *UTM_hemi;
float GEO_Latitude;
float GEO_Longtitude;
float MGRS_Northing;
float MGRS_Easting;
wchar_t MGRS_Row;
wchar_t MGRS_Col;
unsigned int MGRS_Zone;
wchar_t MGRS_Zone_Field;
float Pos_Accuracy;
unsigned int Pos_Src;
float Altitude;
float Alt_Accuracy;
unsigned int Alt_Src;
float heading;
float heading_accuracy;
unsigned int heading_src;
float Pitch;
float Roll;
float Cant;
float roll_pitch_Accuracy;
unsigned int Waypoint_no;
float Waypoint_Dist;
float Waypoint_Bearing;
float Waypoint_Deviation;
float Horizontal_Velocity;
float North_Velocity;
float East_Velocity;
float Down_Velocity;
unsigned int Velocity_Status;
unsigned int Velocity_Source;
float dist_travelled;
unsigned int year;
unsigned int month;
unsigned int Day;
unsigned int Date_status;
unsigned int hours;
unsigned int mins;
unsigned int secs;
unsigned int time_status_src;
unsigned int GPS_DY;
unsigned int GPS_DM;
unsigned int GPS_DD;
unsigned int GPS_UTC_Hours;
unsigned int GPS_UTC_Mins;
unsigned int GPS_UTC_Secs;
float GPS_Latitude;
float GPS_Longtitude;
float GPS_Altitude;
float GPS_track_angle;
float GPS_ground_speed;
float GPS_velocity_north;
float GPS_velocity_east;
float GPS_velocity_up;
float GPS_EHE;
float GPS_EVE;
float GPS_EAE;
float GPS_HDOP;
float GPS_PDOP;
float GPS_VDOP;
unsigned int GPS_NAV_Mode;
unsigned int GPS_Status;
unsigned int VMS_Counter;
unsigned int VMS_Status;
float internal_time;
};
/*LLN Status and BIT output is transmitted in default setup config. on request [FROM INU]*/
struct Status_BIT
{
static const unsigned int SB_ID = 0x92;
unsigned long Validity;
unsigned char *INU_Part;
unsigned int INU_SN;
unsigned int INU_IDENT;
unsigned int INU_SW;
unsigned int Stat, Alert, Bit1, Bit2, Bit3;
unsigned int LRI_1, LRI_2, LRI_3;
unsigned int Wrap;
};
/*Test Data transmitted in default setup config. on request [FROM INU]*/
struct Test_Data
{
static const unsigned int TD_ID = 0x93;
unsigned long Validity;
unsigned int update_counter;
unsigned int vms_counter;
float vms_skf_Deviation;
unsigned int GPS_Stat;
unsigned int viewed_Sate;
unsigned int vms_skf_verification_stat;
unsigned int vms_int_Type2;
};
/*active waypoint message. Is transmitted upon request. currently not in use [FROM INU]*/
struct WayPoint_R
{
static const unsigned int WP_ID = 0x94;
unsigned int Waypoint_no;
unsigned char *Waypoint_name;
unsigned int Waypoint_status;
float WP_UTM_Northing;
float WP_UTM_Easting;
unsigned int WP_UTM_Zone;
unsigned char *UTM_Hemi;
float WP_GEO_LT;
float WP_GEO_LONG;
float WP_MGRS_Northing;
float WP_MGRS_Easting;
unsigned char WP_MGRS_RL;
unsigned char WP_MGRS_CL;
unsigned int WP_MGRS_Zone;
unsigned char WP_MGRS_Zone_field;
unsigned int WP_MGRS_Map_datum;
float UTM_Northing;
float UTM_Easting;
unsigned int UTM_Zone;
unsigned char *UTM_Hemisphere;
float GEO_Lat;
float GEO_Long;
float MGRS_Northing;
float MGRS_Easting;
unsigned char MGRS_RL;
unsigned char MGRS_CL;
unsigned int MGRS_Zone;
unsigned char MGRS_Zone_field;
unsigned int heading_Format;
float heading;
float WP_Dist;
float WP_Bearing;
float WP_Deviation;
};
/*Receive Portion of the VNS Message From the INU*/
struct Receive {
unsigned int System_Stat;
unsigned int Msg_ID;
unsigned int MsgCounter;
unsigned int LRI_Status;
unsigned long RTI_Count;
//For version number
unsigned int Version_Num[2];
Acknowledge Ack;
Transmit_Rate_DEF_R trd_R;
Ether_Confg_Msg_RB_R EtherConf_rb_R;
System_Parameter_R SysP_R;
STD_Output StOut;
Status_BIT Bit;
Test_Data td;
WayPoint_R wp_R;
};
//******Transmitting portion***********//
/*Commands to INU as well as data input to INU*/
struct COMMAND_MESSAGE{
static const unsigned int MCD_ID = 0x86;
unsigned int Req_ID;
unsigned int Command;
float UTM_Northing;
float UTM_Easting;
unsigned int UTM_Zone;
unsigned char UTM_Hemi;
float UTM_Pos;
float Geo_Lat;
float Geo_Long;
float Geo_Pos;
float MGRS_Northing;
float MGRS_Easting;
unsigned char MGRS_ROW;
unsigned char MGRS_COL;
unsigned int MGRS_Zone;
unsigned char MGRS_Field;
float MGRS_PosA;
};
public:
enum Msg_ID
{
SYS_PARAMETER_MSG = 0x90,
STD_OUTPUT_MSG = 0x91,
STATUS_BIT_MSG = 0x92,
TEST_DATA_MSG = 0x93,
WAYPOINT_MSG = 0x94,
};
/*up to five transmit messages continuously after startup mode. IF validity is 0 or update rate 0, message will not be transmitted continuously
Invalid IDS will be ignored [to INU]*/
struct Transmit_Rate_DEF_T{
static const unsigned int TR_ID = 0x8A;
unsigned int TX_Msg1_ID;
unsigned int TX_Rate_Msg1;
unsigned int TX_Msg2_ID;
unsigned int TX_Rate_Msg2;
unsigned int TX_Msg3_ID;
unsigned int TX_Rate_Msg3;
unsigned int TX_Msg4_ID;
unsigned int TX_Rate_Msg4;
unsigned int TX_Msg5_ID;
unsigned int TX_Rate_Msg5;
Msg_ID MSG;
protected:
static const unsigned int MSG_0 = 0;
static const unsigned int MSG_1 = 0.1;
static const unsigned int MSG_2 = 0.25;
static const unsigned int MSG_3 = 0.5;
static const unsigned int MSG_4 = 1.0;
static const unsigned int MSG_5 = 2.0;
static const unsigned int MSG_6 = 4.0;
static const unsigned int MSG_7 = 10.0;
static const unsigned int MSG_8 = 20.0;
static const unsigned int MSG_9 = 40.0;
};
/*message used for setting ethernet communication parameters [to INU]*/
struct Ether_Confg_Msg_RB_T {
static const unsigned int EC_ID = 0x8C;
unsigned char *MAC_Dest;
unsigned char *IP_Source;
unsigned char *IP_Dest;
unsigned int src_port;
unsigned int dest_port;
};
/*message used to provide system parameters and is transmitted upon request[to INU]*/
struct System_Parameter_T {
static const unsigned int SP_ID = 0x90;
unsigned int Map_Datum;
unsigned int heading;
unsigned int altitude;
int utc_TO_hrs;
int utc_TO_mins;
int VMS;
unsigned int mount_pols;
int misalign_Roll;
int misalign_Pitch;
int misalign_Angle_Hdg;
unsigned int INU_Mode;
int GPS_X;
int GPS_Y;
int GPS_Z;
unsigned int NMEA_GPS_BR;
unsigned int VMS_Type;
unsigned int GPS_Type_Mode;
unsigned int GSSIP_Init;
unsigned int GSSIP_Mode;
};
/*message used to set and read internal waypoints [up to 50] [to INU]*/
struct WayPoint_T
{
static const unsigned int WP_ID = 0x94;
unsigned int Waypoint_no;
unsigned char *Waypoint_name;
unsigned int Waypoint_cmd;
float WP_UTM_Northing;
float WP_UTM_Easting;
unsigned int UTM_Zone;
unsigned char *UTM_Hemi;
float WP_GEO_LT;
float WP_GEO_LONG;
float WP_MGRS_Northing;
float WP_MGRS_Easting;
unsigned char WP_MGRS_RL;
unsigned char WP_MGRS_CL;
unsigned int WP_MGRS_Zone;
unsigned char WP_MGRS_Zone_field;
};
public:
/*Transmit Portion of the VNS Message to the INU*/
struct Transmit{
static const unsigned int reserved = 0x00;
unsigned int MsgID;
unsigned int msg_count;
unsigned int validity;
COMMAND_MESSAGE comd_Msg;
Transmit_Rate_DEF_T trd_T;
Ether_Confg_Msg_RB_T EtherConfg_rbT;
System_Parameter_T SysP_T;
WayPoint_T WP_T;
};
public:
VNS(unsigned int port);
/*initialise Ethernet UDP Socket*/
static int initSock( unsigned int port );
/*Close Ethernet UDP Socket*/
static int endSock( int sock );
/*Receive data from Ethernet UDP Socket*/
static int rec( int sock, char * buffer, int len,char * senderipaddress );
/*Transmit data using Ethernet UDP Socket*/
static int send( int sock, const char * data, int len, const char * targetIpAdr, int port );
/*local Thread*/
static DWORD WINAPI ReceiveThread(void *param);
void InitiateThread();
DWORD ThreadRun();
void decode_Message(unsigned char *data);
void Standard_Output(unsigned char *data);
public:
Receive Recv;
Transmit Trans;
};
}
#endif
.cpp file :
.cpp file :
#include <cstdio>
#include "VNS_Lib.h"
#include <iostream>
//using namespace WAVE_VNS;
using namespace std;
using namespace WAVE_VNS;
/*initialise Ethernet UDP Socket*/
VNS::VNS(unsigned int port)
{
vnsSocket = initSock(port);
received = new unsigned char[512];
//This means thread is not running
Running = false;
//Our signal for stopping thread, in this case not.
End = false;
//Delay set up to 100 miliseconds.
join_time = 100;
//Set default values for identifier and handle
tid = 0;
handle = 0;
}
DWORD WINAPI VNS::ReceiveThread(void *param)
{
VNS *func = static_cast<VNS*>(param);
return func->ThreadRun();
}
DWORD VNS::ThreadRun()
{
Running = true; //running
do
{
printf("Thread Running %d\n", tid);
decode_Message(received);
Sleep(1000); //prevent excessive cpu use
}while (!End);
Running = false;
return 0;
}
void VNS::decode_Message(unsigned char *data)
{
switch(data[1])
{
//standard output msg
case 0x91:
Standard_Output(data);
break;
}
}
void VNS::Standard_Output(unsigned char *data)
{
//****System status*****
Recv.System_Stat = data[0];
unsigned int Zone_Change_request = data[0] & 0x80;
unsigned int Pos_Update_request = data[0] & 0x40;
unsigned int Update_Mode_Active = data[0] & 0x20;
unsigned int Command_Rejected = data[0] & 0x10;
unsigned int Mode_indicator_1 = data[0] & 0x08;
unsigned int Mode_indicator_2 = data[0] & 0x04;
unsigned int Mode_indicator_3 = data[0] & 0x02;
unsigned int Mode_indicator_4 = data[0] && 0x01;
//Zone needs to be changed according to actual position
if (Zone_Change_request == 0x80)
{
printf("\nZone Change Request activated");
}
else
printf("\nZone Change Request NOT activated");
//position error is too big, cannot be estimated
if (Pos_Update_request == 0x40)
{
printf("\nPost Update Request activated");
}
//Position update /GPS Available and Valid
else
printf("\nPost Update Request NOT activated");
//Set Position Update Time Mark received /position update has failed check and needs confirmation
if (Update_Mode_Active == 0x20)
{
printf("\nUpdate Mode Active activated");
}
//No confirmation required
else
printf("\nUpdate Mode Active Not activated");
//command and data is invalid
if (Command_Rejected == 0x10)
{
printf("\nCommand Rejected");
}
//upon successful execution of command
else
printf("\nCommand Not Rejected");
//Power ON
if ((Mode_indicator_1 == 0x00) && (Mode_indicator_2 == 0x00) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x00))
{
printf("\nPOWER ON");
}
//NAV Motion
else if ((Mode_indicator_1 == 0x00) && (Mode_indicator_2 == 0x04) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x00))
{
printf("\nNAV Motion");
}
//NAV standstill
else if ((Mode_indicator_1 == 0x00) && (Mode_indicator_2 == 0x04) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x01))
{
printf("\nNAV Standstill");
}
//Amphibious Mode
else if ((Mode_indicator_1 == 0x00) && (Mode_indicator_2 == 0x04) && (Mode_indicator_3 == 0x02) && (Mode_indicator_4 == 0x01))
{
printf("\nAmphibious Mode");
}
//Test
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x00) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x00))
{
printf("\nTest");
}
//Fault
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x00) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x01))
{
printf("\nFault");
}
//Loader Active
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x00) && (Mode_indicator_3 == 0x02) && (Mode_indicator_4 == 0x00))
{
printf("\nLoader Active");
}
//Fault, GPS Backup
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x00) && (Mode_indicator_3 == 0x02) && (Mode_indicator_4 == 0x01))
{
printf("\nFault: GPS Backup");
}
//AUTONAV Motion
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x04) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x00))
{
printf("\nAUTONAV Motion");
}
//AUTONAV Standstill
else if ((Mode_indicator_1 == 0x08) && (Mode_indicator_2 == 0x04) && (Mode_indicator_3 == 0x00) && (Mode_indicator_4 == 0x01))
{
printf("\nAUTONAV Standstill");
}
else
{
printf("\nNot Valid");
}
//*****LRI Status**********
unsigned int Fault = data[4] & 0x80;
unsigned int INU_Fail = data[4] & 0x40;
unsigned int GPS_Fail = data[4] & 0x20;
unsigned int VMS_Fail = data[4] & 0x10;
unsigned int GSP_Type = data[4] & 0x08;
unsigned int GPS_Ant = data[4] & 0x04;
unsigned int GPS_Pwr = data[4] & 0x02;
unsigned int GPS_Data = data[4] & 0x01;
Recv.LRI_Status = data[4];
//Fault
if (Fault == 0x80)
{
printf("\nFault");
}
//Fault is not true
else
printf("\nFault Not true");
//INU Fail
if (INU_Fail == 0x40)
{
printf("\nINU Fail");
}
else
printf("\nINU OK");
//GPS_Fail
if (GPS_Fail == 0x20)
{
printf("\nGPS Fail");
}
else
printf("\nGPS OK");
//VMS_Fail
if (VMS_Fail == 0x10)
{
printf("\nVMS Fail");
}
else
printf("\nVMS OK");
//GSP_Type
if (GSP_Type == 0x08)
{
printf("\nGPS Type: C/A");
}
else
printf("\nGPS Type: P(Y)");
//GPS_Ant
if (GPS_Ant == 0x04)
{
printf("\nGPS ANT: Int");
}
else
printf("\nGPS ANT: Ext");
//GPS_Pwr
if (GPS_Pwr == 0x02)
{
printf("\nGPS Pwr: Int");
}
else
printf("\nGPS Pwr: Ext");
//GPS_Data
if (GPS_Data == 0x01)
{
printf("\nGPS Data: Used");
}
else
printf("\nGPS Data: Not Used");
//Map Datum
int datum = data[28];
Recv.StOut.Map_Datum = data[28];
//Heading Format
Recv.StOut.heading_Format = data[29];
if (data[29] == 0x00)
{
printf("\nGeodetic");
}
else
printf("\nGrid");
//Altitude Format
Recv.StOut.altitude_Format = data[30];
if (data[30] == 0x00)
{
printf("\nMSL");
}
else
printf("\nDatum");
//Actual UTM Northing
unsigned char Northing[8];
Northing[0] = data[38];
Northing[1] = data[37];
Northing[2] = data[36];
Northing[3] = data[35];
Northing[4] = data[34];
Northing[5] = data[33];
Northing[6] = data[32];
Northing[7] = data[31];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.UTM_Northing, Northing, 8);
//Actual UTM Easting
unsigned char Easting[8];
Easting[0] = data[46];
Easting[1] = data[45];
Easting[2] = data[44];
Easting[3] = data[43];
Easting[4] = data[42];
Easting[5] = data[41];
Easting[6] = data[40];
Easting[7] = data[39];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.UTM_Easting, Easting, 8);
//Actual UTM Zone
int Zone = data[47];
Recv.StOut.UTM_Zone = Zone;
//Actual UTM Hemisphere
unsigned char hemi = data[48];
if (hemi == 0x4E)
printf("\nNorth");
else if (hemi == 0x53)
printf("\nSouth");
else
printf("\n-");
//Altitude
unsigned char Alt[8];
Alt[0] = data[97];
Alt[1] = data[96];
Alt[2] = data[95];
Alt[3] = data[94];
Alt[4] = data[93];
Alt[5] = data[92];
Alt[6] = data[91];
Alt[7] = data[90];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.Altitude, Alt, 8);
//Heading
unsigned char head[8];
head[0] = data[110];
head[1] = data[109];
head[2] = data[108];
head[3] = data[107];
head[4] = data[106];
head[5] = data[105];
head[6] = data[104];
head[7] = data[103];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.heading, head, 8);
//Pitch
unsigned char pitch[8];
pitch[0] = data[123];
pitch[1] = data[122];
pitch[2] = data[121];
pitch[3] = data[120];
pitch[4] = data[119];
pitch[5] = data[118];
pitch[6] = data[117];
pitch[7] = data[116];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.Pitch, pitch, 8);
//Roll
unsigned char Rl[8];
Rl[0] = data[131];
Rl[1] = data[130];
Rl[2] = data[129];
Rl[3] = data[128];
Rl[4] = data[127];
Rl[5] = data[126];
Rl[6] = data[125];
Rl[7] = data[124];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.Roll, Rl, 8);
//Cant
unsigned char Ct[8];
Ct[0] = data[139];
Ct[1] = data[138];
Ct[2] = data[137];
Ct[3] = data[136];
Ct[4] = data[135];
Ct[5] = data[134];
Ct[6] = data[133];
Ct[7] = data[132];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.Cant, Ct, 8);
//Pitch-Roll Accuracy
unsigned char ac[4];
ac[0] = data[143];
ac[1] = data[142];
ac[2] = data[141];
ac[3] = data[140];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.roll_pitch_Accuracy, ac, 4);
//Dist
unsigned char dis[4];
dis[0] = data[196];
dis[1] = data[195];
dis[2] = data[194];
dis[3] = data[193];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.dist_travelled, dis, 4);
//Year
unsigned char yr[2];
yr[0] = data[198];
yr[1] = data[197];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.year, yr, 2);
//Month
int month = data[199];
Recv.StOut.month = month;
//Day
int day = data[200];
Recv.StOut.Day = day;
//Date Status
unsigned int Stat = data[201] & 0x01;
Recv.StOut.Date_status = data[201];
if (Stat == 0x01)
{
printf("\nGPS Date");
}
else
printf("\nInternal Date");
//Hour
int hour = data[202];
Recv.StOut.hours = hour;
//Min
int min = data[203];
Recv.StOut.mins = min;
//Secs
float secs = data[204];
Recv.StOut.secs = secs;
//Velocity Status
unsigned int down = data[191] & 0x08;
unsigned int E = data[191] & 0x04;
unsigned int N = data[191] & 0x02;
unsigned int horz = data[191] & 0x01;
Recv.StOut.Velocity_Status = data[191];
if (horz == 0x01)
{
printf("\nHorizontal");
}
if (N == 0x02)
{
printf("\nNorth");
}
if (E == 0x04)
{
printf("\nEast");
}
if (down == 0x08)
{
printf("\nDown");
}
//Velocity Source
unsigned int vs02 = data[192] & 0x02;
unsigned int vs01 = data[192] & 0x01;
Recv.StOut.Velocity_Source = data[192];
if ((vs02 == 0x02) && (vs01 == 0x01))
{
printf("\nINS (Hybrid)");
}
else if ((vs02 == 0x02) && (vs01 == 0x00))
{
printf("\nGPS");
}
else if ((vs02 == 0x00) && (vs01 == 0x01))
{
printf("\nVMS");
}
else
{
printf("\nNot Available");
}
//Actual GEO Latitude
unsigned char Glat[8];
Glat[0] = data[56];
Glat[1] = data[55];
Glat[2] = data[54];
Glat[3] = data[53];
Glat[4] = data[52];
Glat[5] = data[51];
Glat[6] = data[50];
Glat[7] = data[49];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.GEO_Latitude, Glat, 8);
//Actual GEO Longtitude
unsigned char Glong[8];
Glong[0] = data[64];
Glong[1] = data[63];
Glong[2] = data[62];
Glong[3] = data[61];
Glong[4] = data[60];
Glong[5] = data[59];
Glong[6] = data[58];
Glong[7] = data[57];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.GEO_Longtitude, Glong, 8);
//Actual MGRS Northing
unsigned char MNorth[8];
MNorth[0] = data[72];
MNorth[1] = data[71];
MNorth[2] = data[70];
MNorth[3] = data[69];
MNorth[4] = data[68];
MNorth[5] = data[67];
MNorth[6] = data[66];
MNorth[7] = data[65];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.MGRS_Northing, MNorth, 8);
//Actual MGRS Easting
unsigned char MEast[8];
MEast[0] = data[80];
MEast[1] = data[79];
MEast[2] = data[78];
MEast[3] = data[77];
MEast[4] = data[76];
MEast[5] = data[75];
MEast[6] = data[74];
MEast[7] = data[73];
//copy the data from unsigned char array to the resepctive designated element
memcpy(&Recv.StOut.MGRS_Easting, MEast, 8);
//Actual MGRS Row
wchar_t Row = data[81];
Recv.StOut.MGRS_Row = Row;
//Actual MGRS Col
wchar_t Col = data[82];
Recv.StOut.MGRS_Col = Col;
//Actual MGRS Zone
int MZ = data[83];
Recv.StOut.MGRS_Zone = MZ;
//Actual MGRS Zone Field
wchar_t Field = data[84];
Recv.StOut.MGRS_Zone_Field =Field;
}
void VNS::InitiateThread()
{
//Pass static_run function and whole object as parameter.
//Get handle to our thread and identifier (tid)
handle = CreateThread(NULL,0,ReceiveThread,(void *)this,0,&tid);
}
int VNS::initSock( unsigned int port )
{
SOCKADDR_IN sin;
int sock ;
unsigned long io ;
int ret ;
ret = 0 ;
io = 1 ;
WSAData data;
WSAStartup( MAKEWORD( 2, 2 ), &data );
// port must be 0..65535 , prefarably high (as low values are often INET services reserved)
if( port < 0 || port > 65535 ) return -9;
// create the UDP socket in non-blocking mode and bind it to the indicated port number
sin.sin_family=AF_INET;
sin.sin_addr.s_addr=INADDR_ANY;//INADDR_ANY accepte toutes les ip...
sin.sin_port=htons( (unsigned short)port);
if ( ( sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) < 0 )
{
fprintf( stderr, "init : socket sock=%d error=%d \n",sock,LOC_ERRNO );
ret = -1 ;
}
else if( bind( sock, (const SOCKADDR *)( &sin ), sizeof( sin ) ) != 0 )
{
fprintf( stderr, "init : bind error %d\n", LOC_ERRNO );
ret = -1 ;
}
else
{
if ( ioctlsocket( sock, FIONBIO, &io ) < 0 )
{
// non-blocking mode (only method on QNX ) io=1 activate non-blocking ( io=0 deactivate)
fprintf( stderr, " init : ioctl error %d\n", LOC_ERRNO );
ret = -1 ;
}
else
{
return sock ;
}
}
return ret ;
}
/*Close Ethernet UDP Socket*/
int VNS::endSock( int sock )
{
int ret;
ret = 0;
if ( closesocket(sock) != 0 )
{
fprintf( stderr, "endSock close errno=%d \n",LOC_ERRNO );
ret = -1;
}
WSACleanup();
return ret;
}
/*Receive data from Ethernet UDP Socket*/
int VNS::rec( int sock, char * buffer, int len, char * senderipaddress )
{
// get the next received (well formed) message on the local socket (sock)
// timeout is 0 if no waiting (non blocking) , else value in millisec (-1 is infinite)
// return 1 if OK, 2 if new cnx, 0 if no message, -1 if dcnx or comm error, and other negative if error
// return the cnxID
// len is the max length of buffer on entry, and the receive number of bytes on out
SOCKADDR_IN sin;
int ret, mok, sinsize = sizeof( sin );
mok = 0 ;
ret = recvfrom( sock , buffer, len, 0, ( SOCKADDR *)&sin, &sinsize );
if ( ret == -1 )
{
// WIN32 socket returns ECONNRESET (remote host port unreachable) if remote socket don't exist or closed
// WSAEWOULDBLOCK is returned if no data is available
if ( LOC_ERRNO == WSAEWOULDBLOCK )
{ // no data is available
ret = 0 ;
}
else
{ // true error
fprintf( stderr, " recvfrom error errno=%d\n", LOC_ERRNO );
ret = -2 ;
}
}
else
{
senderipaddress = inet_ntoa( sin.sin_addr );
ret = 1;
// good message
}
return ret;
}
/*Transmit data using Ethernet UDP Socket*/
int VNS::send( int sock, const char * data, int len, const char * targetIpAdr, int port )
{
// send a message (id= identifier) on the connexion cnxID
// return 0 if OK, -1 if blocking, other negative if error
int Messlen, ret;
SOCKADDR_IN peerAdr;
Messlen = len ;
peerAdr.sin_family = AF_INET;
peerAdr.sin_addr.s_addr = inet_addr( targetIpAdr ); // IP adr like "127.0.0.1"
peerAdr.sin_port = htons( ( unsigned short )port );
if ( sock <= 0 ) return -7 ;
if ( ( ret = sendto( sock, data, len, 0, ( const SOCKADDR *)&peerAdr, sizeof( SOCKADDR ) ) )
!= Messlen )
{
// probably EWOULDBLOCK, which means that local UDP buffers are full,
// (too many messages sent (too fast) or cable/network problem = impossible to send )
// it's a flow control problem, application could retry the sending
// (connexion local state has not changed)
if( ret == -1 && LOC_ERRNO == WSAEWOULDBLOCK ) return -1;
if( ret == -1 && LOC_ERRNO == WSAEHOSTDOWN ) return -9;
fprintf( stderr, "sendTo error errno=%d ret=%d \n", LOC_ERRNO, ret );
return -4;
}
else
{
// message sent, update local state
return 0;
}
}
the console .cpp file:
the console .cpp file:
#include "stdafx.h"
#include "VNS_Output.h"
VNS_Output::VNS_Output()
{
VNS *v1 = new VNS(EDIP_UDP_PORT_NO);
}
following is the encountered errors:
error LNK2019: unresolved external symbol \"public: __thiscall WAVE_VNS::VNS::VNS(unsigned int)\" (??0VNS@WAVE_VNS@@QAE@I@Z) referenced in function \"public: __thiscall VNS_Output::VNS_Output(void)\" (??0VNS_Output@@QAE@XZ)
error LNK2005: \"bool threadFinished\" (?threadFinished@@3_NA) already defined in VNS_Console.obj
I’m not really sure how to solve the problem. Any suggestions will be greatly appreciated.谢谢! :)
following is the encountered errors:
error LNK2019: unresolved external symbol "public: __thiscall WAVE_VNS::VNS::VNS(unsigned int)" (??0VNS@WAVE_VNS@@QAE@I@Z) referenced in function "public: __thiscall VNS_Output::VNS_Output(void)" (??0VNS_Output@@QAE@XZ)
error LNK2005: "bool threadFinished" (?threadFinished@@3_NA) already defined in VNS_Console.obj
I'm not really sure how to solve the problem. Any suggestions will be greatly appreciated. thanks! :)
推荐答案
You need to include a reference to your .lib file in the project that is trying to use it.
And in future, please do not dump your entire code, it is far too much for anyone to read.
You need to include a reference to your .lib file in the project that is trying to use it.
And in future, please do not dump your entire code, it is far too much for anyone to read.
error LNK2019: unresolved external symbol "public: __thiscall WAVE_VNS::VNS::VNS(unsigned int)" (??0VNS@WAVE_VNS@@QAE@I@Z) referenced in function "public: __thiscall VNS_Output::VNS_Output(void)" (??0VNS_Output@@QAE@XZ)
You need to tell your linker where the lib file is that contains this.
You need to tell your linker where the lib file is that contains this.
error LNK2005: "bool threadFinished" (?threadFinished@@3_NA) already defined in VNS_Console.obj
You can’t place your global variable definition in the header file like that. It essentially attempts to get created twice. You have to define it within your cpp file and declare it as an \"extern\" everywhere else. With that said, global variables are bad and should be considered a last recourse.
You can't place your global variable definition in the header file like that. It essentially attempts to get created twice. You have to define it within your cpp file and declare it as an "extern" everywhere else. With that said, global variables are bad and should be considered a last recourse.
这篇关于未解决的外部符号错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!