I'm trying to compile using the command "mex MEXIrradiation.cpp"
Matlab is returning this error:
Error using mex
/tmp/mex_17281680784358282_33076/MEXIrradiation.o: In function `mdlOutputs(SimStruct_tag*, int)':
MEXIrradiation.cpp:(.text+0x3a0): undefined reference to `PVLCLR::PVL_Utils::irradiation(long, PVLCLR::PVL_Location const&,
PVLCLR::PVL_Orientation const&, double, double&, double&, double&, double&, double&, double&, double&)'
collect2: error: ld returned 1 exit status
Does anyone know how I can fix this?

답변 (1개)

Walter Roberson
Walter Roberson 2016년 1월 15일

0 개 추천

Well we can tell you to define
PVLCLR::PVL_Utils::irradiation(long, PVLCLR::PVL_Location const&,
PVLCLR::PVL_Orientation const&, double, double&, double&, double&, double&, double&, double&, double&)
Perhaps you have defined that routine with a different signature that is not compatible with how it was called.
We cannot give you more then very generic advice as we have never seen your code, and the routine names you mention do not appear to be part of any code indexed anywhere by Google.

댓글 수: 3

Stacey
Stacey 2016년 1월 15일
편집: Stacey 2016년 1월 19일
This is the function where it's being called:
/*
* sfuntmpl_basic.c: Basic 'C' template for a level 2 S-function.
*
* Copyright 1990-2013 The MathWorks, Inc.
*/
/* * You must specify the S_FUNCTION_NAME as the name of your S-function * (i.e. replace sfuntmpl_basic with the name of your S-function). */
#define S_FUNCTION_NAME MEXIrradiation #define S_FUNCTION_LEVEL 2
/* * Need to include simstruc.h for the definition of the SimStruct and * its associated macro definitions. */ #include "simstruc.h" #include "PVL_Location.h" #include "PVL_Orientation.h" #include "PVL_Utils.h"
typedef enum { UTCTIMEBASE = 0, LATITUDE = 1, LONGITUDE = 2, ELEVATION = 3, TILT = 4, AZIMUTH = 5, TURBIDITY = 6, NUMPARAMS = 7, } Params;
typedef enum { TIMEOFF = 0, RESULT = 1, TIMEBASE = 2, UTCTIME = 3, LOC_LATITUDE = 4, LOC_LONGITUDE = 5, LOC_ELEVATION = 6, ORIENT_TILT = 7, ORIENT_AZ = 8, GHI = 9, DNI = 10, DHI = 11, SUN_ZENITH = 12, SUN_AZIMUTH = 13, SUN_ELEVATION = 14, AOI = 15, NUMDIAGS = 16, } Diags;
typedef enum { LOC_IDX = 0, ORIENT_IDX = 1, NUM_PWORK = 2, } Pwork;
typedef enum { BASETIME_IDX = 0, TURBIDITY_IDX = 1, NUM_RWORK = 2, } Rwork;
/* Error handling * -------------- * * You should use the following technique to report errors encountered within * an S-function: * * ssSetErrorStatus(S,"Error encountered due to ..."); * return; * * Note that the 2nd argument to ssSetErrorStatus must be persistent memory. * It cannot be a local variable. For example the following will cause * unpredictable errors: * * mdlOutputs() * { * char msg[256]; {ILLEGAL: to fix use "static char msg[256];"} * sprintf(msg,"Error due to %s", string); * ssSetErrorStatus(S,msg); * return; * } * */
/*====================* * S-function methods ====================*/
/* Function: mdlInitializeSizes =============================================== * Abstract: * The sizes information is used by Simulink to determine the S-function * block's characteristics (number of inputs, outputs, states, etc.). / static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, NUMPARAMS); / Number of expected parameters / if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { / Return if number of expected != number of actual parameters */ return; }
ssSetNumContStates(S, 0); ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 1)) return; ssSetInputPortWidth(S, 0, 1); ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/ /* * Set direct feedthrough flag (1=yes, 0=no). * A port has direct feedthrough if the input is used in either * the mdlOutputs or mdlGetTimeOfNextVarHit functions. */ ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S, 2)) return; ssSetOutputPortWidth(S, 0, 1); ssSetOutputPortWidth(S, 1, NUMDIAGS);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, NUM_RWORK); ssSetNumIWork(S, 0); ssSetNumPWork(S, NUM_PWORK); ssSetNumModes(S, 0); ssSetNumNonsampledZCs(S, 0);
/* Specify the sim state compliance to be same as a built-in block */ ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
ssSetOptions(S, 0); }
/* Function: mdlInitializeSampleTimes ========================================= * Abstract: * This function is used to specify the sample time(s) for your * S-function. You must register the same number of sample times as * specified in ssSetNumSampleTimes. */ static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_PROCESS_PARAMETERS #if defined(MDL_PROCESS_PARAMETERS) /* * Process any changes to parameters */ static void mdlProcessParameters(SimStruct *S) { if (ssGetPWork(S)[0] != nullptr) { PVLCLR::PVL_Location *loc = (PVLCLR::PVL_Location *)ssGetPWork(S)[LOC_IDX]; ssGetPWork(S)[LOC_IDX] = nullptr; delete loc;
PVLCLR::PVL_Orientation *or = (PVLCLR::PVL_Orientation *)ssGetPWork(S)[ORIENT_IDX]; ssGetPWork(S)[LOC_IDX] = nullptr; delete loc; }
real_T timeBase = (mxGetPr(ssGetSFcnParam(S, UTCTIMEBASE)))[0]; real_T latitude = (mxGetPr(ssGetSFcnParam(S, LATITUDE)))[0]; real_T longitude = (mxGetPr(ssGetSFcnParam(S, LONGITUDE)))[0]; real_T elevation = (mxGetPr(ssGetSFcnParam(S, ELEVATION)))[0]; real_T tilt = (mxGetPr(ssGetSFcnParam(S, TILT)))[0]; real_T azimuth = (mxGetPr(ssGetSFcnParam(S, AZIMUTH)))[0]; real_T turbidity = (mxGetPr(ssGetSFcnParam(S, TURBIDITY)))[0];
PVLCLR::PVL_Location *loc = new PVLCLR::PVL_Location(latitude, longitude, elevation); PVLCLR::PVL_Orientation *or = new PVLCLR::PVL_Orientation(tilt, azimuth);
ssGetRWork(S)[BASETIME_IDX] = timeBase; ssGetRWork(S)[TURBIDITY_IDX] = turbidity; ssGetPWork(S)[LOC_IDX] = loc; ssGetPWork(S)[ORIENT_IDX] = or;
} #endif
#define MDL_INITIALIZE_CONDITIONS /* Change to #undef to remove function / #if defined(MDL_INITIALIZE_CONDITIONS) / Function: mdlInitializeConditions ======================================== * Abstract: * In this function, you should initialize the continuous and discrete * states for your S-function block. The initial states are placed * in the state vector, ssGetContStates(S) or ssGetRealDiscStates(S). * You can also perform any other initialization activities that your * S-function may require. Note, this routine will be called at the * start of simulation and if it is present in an enabled subsystem * configured to reset states, it will be call when the enabled subsystem * restarts execution to reset the states. / static void mdlInitializeConditions(SimStruct *S) { } #endif / MDL_INITIALIZE_CONDITIONS */
#define MDL_START /* Change to #undef to remove function / #if defined(MDL_START) / Function: mdlStart ======================================================= * Abstract: * This function is called once at start of model execution. If you * have states that should be initialized once, this is the place * to do it. / static void mdlStart(SimStruct *S) { mdlProcessParameters(S); } #endif / MDL_START */
/* Function: mdlOutputs ======================================================= * Abstract: * In this function, you compute the outputs of your S-function * block. */ static void mdlOutputs(SimStruct *S, int_T tid) { double timebase = ssGetRWork(S)[BASETIME_IDX]; double turbidity = ssGetRWork(S)[TURBIDITY_IDX]; PVLCLR::PVL_Location *loc = (PVLCLR::PVL_Location *)ssGetPWork(S)[LOC_IDX]; PVLCLR::PVL_Orientation *or = (PVLCLR::PVL_Orientation *)ssGetPWork(S)[ORIENT_IDX];
const real_T inVals = (const real_T)ssGetInputPortSignal(S, 0); real_T *resOut = (real_T *)ssGetOutputPortSignal(S, 0); real_T *diagOut = (real_T *)ssGetOutputPortSignal(S, 1);
real_T timeoff = inVals[0]; time_t UTCTime = (time_t)(timebase + timeoff);
double clearskyGHI; double clearskyDNI; double clearskyDHI; double sunZen; double sunAz; double sunEl; double aoi;
real_T irr = PVLCLR::PVL_Utils::irradiation(UTCTime, *loc, *or, turbidity, clearskyGHI, clearskyDNI, clearskyDHI, sunZen, sunAz, sunEl, aoi);
resOut[0] = irr;
diagOut[TIMEOFF] = timeoff; diagOut[RESULT] = irr; diagOut[TIMEBASE] = timebase; diagOut[UTCTIME] = UTCTime; diagOut[LOC_LATITUDE] = loc->getLatitude(); diagOut[LOC_LONGITUDE] = loc->getLongitude(); diagOut[LOC_ELEVATION] = loc->getAltitude(); diagOut[ORIENT_TILT] = or->getTilt(); diagOut[ORIENT_AZ] = or->getAzimuth(); diagOut[GHI] = clearskyGHI; diagOut[DNI] = clearskyDNI; diagOut[DHI] = clearskyDHI; diagOut[SUN_ZENITH] = sunZen; diagOut[SUN_AZIMUTH] = sunAz; diagOut[SUN_ELEVATION] = sunEl; diagOut[AOI] = aoi; }
#define MDL_UPDATE /* Change to #undef to remove function / #if defined(MDL_UPDATE) / Function: mdlUpdate ====================================================== * Abstract: * This function is called once for every major integration time step. * Discrete states are typically updated here, but this function is useful * for performing any tasks that should only take place once per * integration step. / static void mdlUpdate(SimStruct *S, int_T tid) { } #endif / MDL_UPDATE */
#define MDL_DERIVATIVES /* Change to #undef to remove function / #if defined(MDL_DERIVATIVES) / Function: mdlDerivatives ================================================= * Abstract: * In this function, you compute the S-function block's derivatives. * The derivatives are placed in the derivative vector, ssGetdX(S). / static void mdlDerivatives(SimStruct *S) { } #endif / MDL_DERIVATIVES */
/* Function: mdlTerminate ===================================================== * Abstract: * In this function, you should perform any actions that are necessary * at the termination of a simulation. For example, if memory was * allocated in mdlStart, this is the place to free it. */ static void mdlTerminate(SimStruct *S) { }
/*=============================* * Required S-function trailer =============================*/
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? / #include "simulink.c" / MEX-file interface mechanism / #else #include "cg_sfun.h" / Code generation registration function */ #endif
Here is PVUtils.h:
/*
* PVL_Utils.h
*
* Created on: Mar 20, 2015
* Author: dugganj
*/
#ifndef DOMAINOBJECTS_PVL_INCLUDE_PVL_UTILS_H_
#define DOMAINOBJECTS_PVL_INCLUDE_PVL_UTILS_H_
#include <stdint.h>
#include <cmath>
#include "PVL_Location.h"
#include "PVL_Orientation.h"
namespace PVLCLR
{
class PVL_Utils
{
public:
const static double PI;
const static double DEGREES;
const static double DEGREE_TO_RAD;
const static double RAD_TO_DEGREE;
static double degreeToRadian(double degrees){ return degrees * DEGREE_TO_RAD; };
static double radianToDegree(double radians){ return radians * RAD_TO_DEGREE; };
static double extraTerrestrialRadiation(double doy);
static double altitudeToPressure(double altitude);
typedef enum
{
DEFAULT,
kastenyoung1989,
kasten1966,
simple,
pickering2002,
youngirvine1967,
young1994,
gueymard1993,
} AirMassModel;
static double absoluteAirMass(double seaLevelAirmass, double pressure = 0.0);
static double relativeAirMass(double z, AirMassModel model = DEFAULT);
static double cosd(double angleInDegrees) { return cos(degreeToRadian(angleInDegrees)); };
static double acosd(double cosVal){ return radianToDegree(acos(cosVal)); };
static double sind(double angleInDegrees) { return sin(degreeToRadian(angleInDegrees)); };
static double secd(double angleInDegrees) { return 1.0 / cosd(angleInDegrees); };
static double mod(double arg, double div);
static double sign(double arg);
static double angleOfIncidence(double surfTilt, double surfAz, double sunZen, double sunAz);
static double groundDiffuseRadiation(double surfTilt, double GHI, double albedo);
static double kingModelSkyDiffuse(double surfTilt, double DHI, double GHI, double sunZen);
static double beamIrradiance(double DNI, double angleOfIncidence);
static double irradiation(double DNI, double GHI, double DHI,
double angleOfIncidence, double surfTilt, double sunZenith, double albedo = 0.2);
static double irradiation(time_t UTCTime, const PVL_Location &location, const PVL_Orientation &orientation, double turbidity);
static double irradiation(time_t UTCTime, const PVL_Location &location, const PVL_Orientation &orientation, double turbidity,
double &clearskyGHI, double &clearskyDNI, double &clearskyDHI,
double &sunZen, double &sunAz, double &sunEl, double &aoi
); // version for diagnostics
};
};
#endif /* DOMAINOBJECTS_PVL_INCLUDE_PVL_UTILS_H_ */
Walter Roberson
Walter Roberson 2016년 1월 15일
You copied your .cpp file twice instead of showing the .h
You do not show a #include of the .h file.
Stacey
Stacey 2016년 1월 19일
Ok. I just updated it. Sorry about that.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Language Fundamentals에 대해 자세히 알아보기

태그

질문:

2016년 1월 15일

댓글:

2016년 1월 19일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by