I have a header file that contains functions and variables that are being shared across multiple vessels and sub classes. This file is called "AAPO_Common.h"
Recently I've started getting the following compiler error...
...for each variable and function in the file.
The problem is that the only place they are defined is in AAPO_Common.h, and I've have it guarded (pragma once).
I haven't touched any of my includes so why would this error be croping up now, and what is causing it?
Contents of AAPO_Common.h...
Recently I've started getting the following compiler error...
Code:
1>LM_Cockpit.obj : error LNK2005: "void __cdecl to_quaternion(union VECTOR3,float,float * const)" (?to_quaternion@@YAXTVECTOR3@@MQAM@Z) already defined in LM.obj
...for each variable and function in the file.
The problem is that the only place they are defined is in AAPO_Common.h, and I've have it guarded (pragma once).
I haven't touched any of my includes so why would this error be croping up now, and what is causing it?
Contents of AAPO_Common.h...
Code:
// ==============================================================
// ORBITER MODULE:
// Part of the ORBITER SDK
// Copyright (C) 2013 Greg Hlynka
// All rights reserved
//
// AAPO_Common.h
// Common values and functions for the Apollo Aplication Project for Orbiter
//
// Notes: This file exists
// ==============================================================
#pragma once
#define STRICT
// Orbiter SDK files
#include "orbitersdk.h"
// ==============================================================
// Physical Constants
// ==============================================================
const double METERS_AU = 149597870700; // Length of 1 Astronomical unit in meters
const double STEFANBOLTZMANN = 5.67e-8; // Stephan-Boltzman constant for radiance of black bodies
const double REGNAULT = 8.314462175; // Regnault (Ideal) gas constant
const double PA_TO_PSI = 0.000145037738; // Conversion rate of Pascals to PSI
const double PSI_TO_PA = 6894.75729; // Conversion rate of PSI to Pascals
const double H2_MOLAR_MASS = 2.0158 / 1000; // H2 molar mass [kg] 2 grams
const double H2_HEAT = 14.20; // Specific heat of H2 [kj/kg K]
const double N2_MOLAR_MASS = 28.01344 / 1000; // N2 molar mass [kg] 28 grams
const double N2_HEAT = 1.039; // Specific heat of N2 [kj/kg K]
const double O2_MOLAR_MASS = 31.99886 / 1000; // O2 molar mass [kg] 32 grams
const double O2_HEAT = 0.919; // Specific heat of O2 [kj/kg K]
const double CO2_MOLAR_MASS = 44.00964 / 1000; // CO2 Molar mass [kg] 44 grams
const double CO2_HEAT = 0.037; // Specific heat of CO2 [kj/kg K]
const double H2O_MOLAR_MASS = 18.01528 / 1000; // Water Molar mass [kg] 18 grams
const double H2O_HEAT = 4.187; // Specific heat of Water [kj/kg K]
// ==============================================================
// Enumerators
// ==============================================================
enum chutestate {STOWED, DROGUE, REEFED, UENREEFING, DEPLOYED, JETTISONED};
enum switchstate {DOWN, CENTER, UP};
enum doorstate {CLOSED, OPEN, CLOSING, OPENING};
// ==============================================================
// Functions
// ==============================================================
// --------------------------------------------------------------
// Convert axis/angle to quaternion form, angle is in radians.
// --------------------------------------------------------------
void to_quaternion (VECTOR3 axis, float angle, float result[4])
{
normalise (axis);
result[0] = axis.x * sin (angle / 2.0);
result[1] = axis.y * sin (angle / 2.0);
result[2] = axis.z * sin (angle / 2.0);
result[3] = cos(angle / 2.0);
}
// --------------------------------------------------------------
// Convert unit-length quaternion to axis / angle pair.
// --------------------------------------------------------------
void from_quaternion (float q[4], VECTOR3 axis, float *angle)
{
*angle = acos (q[3]) * 2.0;
axis.x = q[0] / sin (*angle / 2.0);
axis.y = q[1] / sin (*angle / 2.0);
axis.z = q[2] / sin (*angle / 2.0);
}
// --------------------------------------------------------------
// Multiply two quaternions together.
// --------------------------------------------------------------
void multiply_quaternions (float q1[4], float q2[4], float result[4])
{
result[0] = (q2[3] * q1[0]) + (q2[0] * q1[3]) + (q2[1] * q1[2]) - (q2[2] * q1[1]);
result[1] = (q2[3] * q1[1]) + (q2[1] * q1[3]) + (q2[2] * q1[0]) - (q2[0] * q1[2]);
result[2] = (q2[3] * q1[2]) + (q2[2] * q1[3]) + (q2[0] * q1[1]) - (q2[1] * q1[0]);
result[3] = (q2[3] * q1[3]) - (q2[0] * q1[0]) - (q2[1] * q1[1]) - (q2[2] * q1[2]);
}
// --------------------------------------------------------------
// To rotate a vector in 3d space, angle is in radians
// --------------------------------------------------------------
VECTOR3 RotateVector (const VECTOR3& input, double angle, const VECTOR3& rotationaxis)
{
// To rotate a vector in 3D space we'll need to build a matrix, these are the variables required to do so.
MATRIX3 rMatrix;
double c = cos(angle);
double s = sin(angle);
double t = 1.0 - c;
double x = rotationaxis.x;
double y = rotationaxis.y;
double z = rotationaxis.z;
// Build rotation matrix
rMatrix.m11 = (t * x * x + c);
rMatrix.m12 = (t * x * y - s * z);
rMatrix.m13 = (t * x * z + s * y);
rMatrix.m21 = (t * x * y + s * z);
rMatrix.m22 = (t * y * y + c);
rMatrix.m23 = (t * y * z - s * x);
rMatrix.m31 = (t * x * z - s * y);
rMatrix.m32 = (t * y * z + s * x);
rMatrix.m33 = (t * z * z + c);
// Perform Rotation
VECTOR3 output = mul(rMatrix, input); // multiply the input vector by our rotation matrix to get our output vector
return output; // Return rotated vector
} // End "RotateVector"
// --------------------------------------------------------------
// Spawn a new vessel object (adapted from the Atlantis' ET seperation routine)
// --------------------------------------------------------------
OBJHANDLE SpawnObject (VESSEL *parent, char* name, char* classname, VECTOR3 ofs, double rvel)
{
VESSELSTATUS vs;
parent->GetStatus (vs);
parent->Local2Rel (ofs, vs.rpos);
vs.eng_main = vs.eng_hovr = 0.0;
vs.status = 0;
VECTOR3 vel = { ofs.x, ofs.y, ofs.z}; // seperation vector
normalise (vel);
parent->Local2Rel (ofs, vs.rpos);
VECTOR3 rofs;
parent->GlobalRot (vel, rofs);
vs.rvel += rofs * rvel;
oapiCreateVessel (name, classname, vs);
return oapiGetObjectByName (name);
}