Error LNK2019: Unresolved External Symbol in Visual Studio [duplicate] - c++
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I've downloaded this C++ code from the SBIG website in order to control (take pictures and save them) the camera (model ST-401ME) which I purchased from them. I have a Matlab program which needs to call this so I'm trying to compile (with Visual Studio) this code with its headers and libraries into an executable. However, when I try I get the above mentioned error. Just to note I have added the files which contain the libraries to the directory path.
The exact wording of the output is this:
1>------ Build started: Project: CaptureImage, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>Linking...
1>csbigcam.obj : error LNK2019: unresolved external symbol _SBIGUnivDrvCommand#12 referenced in function "public: enum PAR_ERROR __thiscall CSBIGCam::SBIGUnivDrvCommand(short,void *,void *)" (?SBIGUnivDrvCommand#CSBIGCam##QAE?AW4PAR_ERROR##FPAX0#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffclos referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::SaveFITS(char const *)" (?SaveFITS#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffprec referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::SaveFITS(char const *)" (?SaveFITS#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffpky referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::SaveFITS(char const *)" (?SaveFITS#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffuky referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::SaveFITS(char const *)" (?SaveFITS#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffppr referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::SaveFITS(char const *)" (?SaveFITS#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffcrim referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::SaveFITS(char const *)" (?SaveFITS#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffinit referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::SaveFITS(char const *)" (?SaveFITS#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffphis referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::History2FITS(struct fitsfile *)" (?History2FITS#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PAUfitsfile###Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffmrhd referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::ReadFITSImage(char const *)" (?ReadFITSImage#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffgrec referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::ReadFITSImage(char const *)" (?ReadFITSImage#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffghsp referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::ReadFITSImage(char const *)" (?ReadFITSImage#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffghdn referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::ReadFITSImage(char const *)" (?ReadFITSImage#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffgkyj referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::ReadFITSImage(char const *)" (?ReadFITSImage#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffgkyd referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::ReadFITSImage(char const *)" (?ReadFITSImage#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffgkys referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::ReadFITSImage(char const *)" (?ReadFITSImage#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffgpxv referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::ReadFITSImage(char const *)" (?ReadFITSImage#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffgipr referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::ReadFITSImage(char const *)" (?ReadFITSImage#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>csbigimg.obj : error LNK2019: unresolved external symbol _ffopen referenced in function "public: enum SBIG_FILE_ERROR __thiscall CSBIGImg::ReadFITSImage(char const *)" (?ReadFITSImage#CSBIGImg##QAE?AW4SBIG_FILE_ERROR##PBD#Z)
1>I:\My Documents\Visual Studio 2008\Projects\CaptureImage\Debug\CaptureImage.exe : fatal error LNK1120: 19 unresolved externals
1>Build log was saved at "file://i:\My Documents\Visual Studio 2008\Projects\CaptureImage\CaptureImage\Debug\BuildLog.htm"
1>CaptureImage - 20 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I think this has to do with linking the libraries. I never learned how to do that in Visual Studio, and It doesn't help that the class I took in college was 5 years ago so I barely remember anything.
Because of the length of the code I'll only poast the parts where the errors occur. If you want more of it (like the main) just let me know.
Code:
csbigcam.cpp
#include "lpardrv.h"
#include "sbigudrv.h"
#include "csbigcam.h"
#include "csbigimg.h"
#include <string>
#include <math.h>
using namespace std;
#ifndef INVALID_HANDLE_VALUE
#define INVALID_HANDLE_VALUE -1
#endif
#define VERSION_STR "1.2" /* version of this class */
/*
Temperature Conversion Constants
Defined in the SBIG Universal Driver Documentation
*/
#define T0 25.0
#define R0 3.0
#define DT_CCD 25.0
#define DT_AMB 45.0
#define RR_CCD 2.57
#define RR_AMB 7.791
#define RB_CCD 10.0
#define RB_AMB 3.0
#define MAX_AD 4096
.
.
.
PAR_ERROR CSBIGCam::GetFullFrame(int &nWidth, int &nHeight)
{
GetCCDInfoResults0 gcir;
GetCCDInfoParams gcip;
unsigned short vertNBinning;
unsigned short rm;
// Get the image dimensions
vertNBinning = m_uReadoutMode >> 8;
if ( vertNBinning == 0 )
vertNBinning = 1;
rm = m_uReadoutMode & 0xFF;
gcip.request = (m_eActiveCCD == CCD_IMAGING ? CCD_INFO_IMAGING : CCD_INFO_TRACKING);
if ( SBIGUnivDrvCommand(CC_GET_CCD_INFO, &gcip, &gcir) != CE_NO_ERROR )
return m_eLastError;
if ( rm >= gcir.readoutModes )
return CE_BAD_PARAMETER;
nWidth = gcir.readoutInfo[rm].width;
if ( rm >=3 && rm <= 5 )
nHeight = gcir.readoutInfo[rm-3].height / vertNBinning;
else
nHeight = gcir.readoutInfo[rm].height / vertNBinning;
return CE_NO_ERROR;
}
.
.
.
csbigcam.h
#ifndef _CSBIGCAM_
#define _CSBIGCAM_
#ifndef _PARDRV_
#include "sbigudrv.h"
#endif
#ifndef _CSBIGIMG_
#include "csbigimg.h"
#endif
#include <string>
using namespace std;
typedef enum {RELAY_XPLUS, RELAY_XMINUS, RELAY_YPLUS, RELAY_YMINUS } CAMERA_RELAY;
typedef enum {SBDF_LIGHT_ONLY, SBDF_DARK_ONLY, SBDF_DARK_ALSO } SBIG_DARK_FRAME;
typedef enum {GS_IDLE, GS_DAWN, GS_EXPOSING_DARK, GS_DIGITIZING_DARK, GS_EXPOSING_LIGHT,
GS_DIGITIZING_LIGHT, GS_DUSK } GRAB_STATE;
class CSBIGCam {
private:
PAR_ERROR m_eLastError;
PAR_COMMAND m_eLastCommand;
short m_nDrvHandle;
CAMERA_TYPE m_eCameraType;
CCD_REQUEST m_eActiveCCD;
double m_dExposureTime;
unsigned short m_uReadoutMode;
ABG_STATE7 m_eABGState;
int m_nSubFrameLeft, m_nSubFrameTop, m_nSubFrameWidth, m_nSubFrameHeight;
GRAB_STATE m_eGrabState;
double m_dGrabPercent;
CFW_MODEL_SELECT m_eCFWModel;
CFW_ERROR m_eCFWError;
struct {
unsigned short vertNBinning, hBin, vBin;
unsigned short rm;
int left, top, width, height;
} m_sGrabInfo;
public:
// Constructors/Destructors
CSBIGCam();
CSBIGCam(OpenDeviceParams odp);
CSBIGCam(SBIG_DEVICE_TYPE dev);
~CSBIGCam();
void Init();
// Error Reporting Routines
PAR_ERROR GetError();
string GetErrorString();
string GetErrorString(PAR_ERROR err);
PAR_COMMAND GetCommand();
// Accessor Functions
double GetExposureTime(void) { return m_dExposureTime; }
void SetExposureTime(double exp) { m_dExposureTime = exp; }
CCD_REQUEST GetActiveCCD(void) { return m_eActiveCCD; }
void SetActiveCCD(CCD_REQUEST ccd) { m_eActiveCCD = ccd; }
unsigned short GetReadoutMode(void) { return m_uReadoutMode; }
void SetReadoutMode(unsigned short rm) { m_uReadoutMode = rm; }
CAMERA_TYPE GetCameraType(void) { return m_eCameraType; }
ABG_STATE7 GetABGState(void) { return m_eABGState; }
void SetABGState(ABG_STATE7 abgState) { m_eABGState = abgState; }
void SetSubFrame(int nLeft, int nTop, int nWidth, int nHeight);
void GetSubFrame(int &nLeft, int &nTop, int &nWidth, int &nHeight);
PAR_ERROR GetReadoutInfo(double &pixelWidth, double &pixelHeight, double &eGain);
// Driver/Device Routines
PAR_ERROR OpenDriver();
PAR_ERROR CloseDriver();
PAR_ERROR OpenDevice(OpenDeviceParams odp);
PAR_ERROR CloseDevice();
PAR_ERROR GetDriverInfo(DRIVER_REQUEST request, GetDriverInfoResults0 &gdir);
// High-Level Exposure Related Commands
PAR_ERROR GrabSetup(CSBIGImg *pImg, SBIG_DARK_FRAME dark);
PAR_ERROR GrabMain(CSBIGImg *pImg, SBIG_DARK_FRAME dark);
PAR_ERROR GrabImage(CSBIGImg *pImg, SBIG_DARK_FRAME dark);
void GetGrabState(GRAB_STATE &grabState, double &percentComplete);
// Low-Level Exposure Related Commands
PAR_ERROR StartExposure(SHUTTER_COMMAND shutterState);
PAR_ERROR EndExposure(void);
PAR_ERROR IsExposureComplete(MY_LOGICAL &complete);
PAR_ERROR StartReadout(StartReadoutParams srp);
PAR_ERROR EndReadout(void);
PAR_ERROR ReadoutLine(ReadoutLineParams rlp, MY_LOGICAL darkSubtract, unsigned short *dest);
PAR_ERROR DumpLines(unsigned short noLines);
//Temperature Related Commands
PAR_ERROR GetCCDTemperature(double &ccdTemp);
PAR_ERROR SetTemperatureRegulation(MY_LOGICAL enable, double setpoint);
PAR_ERROR QueryTemperatureStatus(MY_LOGICAL &enabled, double &ccdTemp,
double &setpointTemp, double &percentTE);
// Control Related Commands
PAR_ERROR ActivateRelay(CAMERA_RELAY relay, double time);
PAR_ERROR IsRelayActive(CAMERA_RELAY relay, MY_LOGICAL &active);
PAR_ERROR AOTipTilt(AOTipTiltParams attp);
PAR_ERROR CFWCommand(CFWParams cfwp, CFWResults &cfwr);
// General Purpose Commands
PAR_ERROR EstablishLink(void);
string GetCameraTypeString(void);
PAR_ERROR GetFullFrame(int &nWidth, int &nHeight);
PAR_ERROR GetFormattedCameraInfo(string &ciStr, MY_LOGICAL htmlFormat = TRUE);
// Utility functions
MY_LOGICAL CheckLink(void);
unsigned short DegreesCToAD(double degC, MY_LOGICAL ccd = TRUE);
double ADToDegreesC(unsigned short ad, MY_LOGICAL ccd = TRUE);
//CFW Functions
CFW_MODEL_SELECT GetCFWModel(void) { return m_eCFWModel; }
PAR_ERROR SetCFWModel(CFW_MODEL_SELECT cfwModel, CFW_COM_PORT comPort = CFWPORT_COM1);
PAR_ERROR SetCFWPosition(CFW_POSITION position);
PAR_ERROR GetCFWPositionAndStatus(CFW_POSITION &position, CFW_STATUS &status);
PAR_ERROR GetCFWMaxPosition(CFW_POSITION &position);
CFW_ERROR GetCFWError(void) { return m_eCFWError; }
string GetCFWErrorString(CFW_ERROR err);
string GetCFWErrorString(void);
// Allows access directly to driver
PAR_ERROR SBIGUnivDrvCommand(short command, void *Params, void *Results);
};
#endif /* #ifndef _CSBIGCAM_ */
csbigimg.ccp
#include "lpardrv.h"
#include "csbigimg.h"
#include <stdio.h>
#include <string.h>
#include <string>
/*
Local Constants
*/
#if TARGET == ENV_MACOSX
#define LONGLONG long long
#endif
#define FILE_VERSION 3 /* current header version written */
#define DATA_VERSION 1 /* current data version written */
#define HEADER_LEN 2048
#define VERSION_STR "1.2" /* version of this class */
static const char *HEADER_KEYWORDS[] =
{
"File_version = ",
"Data_version = ",
"Exposure = ",
"Focal_length = ",
"Aperture = ",
"Response_factor = ",
"Note = ",
"Background = ",
"Range = ",
"Height = ",
"Width = ",
"Date = ",
"Time = ",
"Exposure_state = ",
"Temperature = ",
"Number_exposures = ",
"Each_exposure = ",
"History = ",
"Observer = ",
"X_pixel_size = ",
"Y_pixel_size = ",
"Pedestal = ",
"E_gain = ",
"User_1 = ",
"User_2 = ",
"User_3 = ",
"User_4 = ",
"Filter = ",
"Readout_mode = ",
"Track_time = ",
"Sat_level = ",
"End"
};
typedef enum
{
HH_FILE_VERSION,
HH_DATA_VERSION,
HH_EXPOSURE,
HH_FOCAL_LENGTH,
HH_APERTURE,
HH_RESPONSE_FACTOR,
HH_NOTE,
HH_BACKGROUND,
HH_RANGE,
HH_HEIGHT,
HH_WIDTH,
HH_DATE,
HH_TIME,
HH_EXPOSURE_STATE,
HH_TEMPERATURE,
HH_NUMBER_EXPOSURES,
HH_EACH_EXPOSURE,
HH_HISTORY,
HH_OBSERVER,
HH_X_PIXEL_SIZE,
HH_Y_PIXEL_SIZE,
HH_PEDESTAL,
HH_E_GAIN,
HH_USER_1,
HH_USER_2,
HH_USER_3,
HH_USER_4,
HH_FILTER,
HH_READOUT_MODE,
HH_TRACK_TIME,
HH_SAT_LEVEL,
HH_END
} SBIG_HEADER_HEADING;
.
.
.
#if INCLUDE_FITSIO
/* save file in FITS format */
res = SaveFITS(pFullPath);
#else
.
.
.
SBIG_FILE_ERROR CSBIGImg::History2FITS(fitsfile *fptr)
{
int status = 0;
const char *msg, *p;
char c, *cp = (char*)m_cHistory.c_str();
int index;
MY_LOGICAL first = TRUE;
while (*cp) {
c = *cp++;
if ( (p=strchr(HISTORY_CHARS, c)) != NULL ) {
index = (p - HISTORY_CHARS)/sizeof(const char);
msg = HISTORY_PHRASES[index];
} else if ( c == '0' )
continue;
else
msg = "???";
if ( first )
fits_write_key(fptr, TSTRING, "SWMODIFY", (void *)m_cSoftware.c_str(), "", &status);
first = FALSE;
if (fits_write_history(fptr,msg,&status)) {
return SBFE_FITS_HEADER_ERROR;
}
}
return SBFE_NO_ERROR;
}
.
.
.
SBIG_FILE_ERROR CSBIGImg::ReadFITSImage(char const *pFullPath)
{
SBIG_FILE_ERROR err = SBFE_FORMAT_ERROR;
fitsfile *fptr; /* FITS file pointer, defined in fitsio.h */
char card[FLEN_CARD]; /* Standard string lengths defined in fitsio.h */
int status = 0; /* CFITSIO status value MUST be initialized to zero! */
int hdupos, nkeys, ii, jj;
int bitpix, naxis;
long naxes[2] = {1,1}, fpixel[2] = {1,1};
unsigned short *uip;
long l, l2;
double d;
char s[80];
MY_LOGICAL first = TRUE;
struct tm obs;
if (!fits_open_file(&fptr, pFullPath, READONLY, &status))
{
do { // Allow to break out
// get and check the dimensions
if ( fits_get_img_param(fptr, 2, &bitpix, &naxis, naxes, &status) ) break;
if ( bitpix != 16 || naxis != 2 ) break;
// allocate the buffer
err = SBFE_MEMORY_ERROR;
if ( !AllocateImageBuffer(naxes[1], naxes[0]) ) break;
uip = GetImagePointer();
// read the image data
err = SBFE_READ_ERROR;
if ( fits_read_pix(fptr, TUSHORT, fpixel, naxes[0]*naxes[1], NULL, uip, NULL, &status) ) break;
// try and read the SBIG keys
status = 0; if ( !fits_read_key_str(fptr, FITS_KEYS[FK_OBJ], s, NULL, &status) ) SetFITSObject(s);
status = 0; if ( !fits_read_key_str(fptr, FITS_KEYS[FK_SCOPE], s, NULL, &status) ) SetFITSTelescope(s);
status = 0; if ( !fits_read_key_str(fptr, FITS_KEYS[FK_INST], s, NULL, &status) ) SetCameraModel(s);
status = 0; if ( !fits_read_key_str(fptr, FITS_KEYS[FK_OBS], s, NULL, &status) ) SetObserver(s);
status = 0; if ( !fits_read_key_str(fptr, FITS_KEYS[FK_DATEOBS], s, NULL, &status) ) {
if ( sscanf(s,"%4d-%2d-%2dT%2d.%2d.%2d", &obs.tm_year, &obs.tm_mon, &obs.tm_mday,
&obs.tm_hour, &obs.tm_min, &obs.tm_sec) == 6 ) {
obs.tm_year -= 1900; obs.tm_mon -= 1;
memcpy(&m_sDecodedImageStartTime, &obs, sizeof(struct tm));
}
}
status = 0; if ( !fits_read_key_dbl(fptr, FITS_KEYS[FK_EXP], &d, NULL, &status) ) SetExposureTime(d);
status = 0; if ( !fits_read_key_dbl(fptr, FITS_KEYS[FK_CCDT], &d, NULL, &status) ) SetCCDTemperature(d);
status = 0; if ( !fits_read_key_dbl(fptr, FITS_KEYS[FK_PIXX], &d, NULL, &status) ) SetPixelWidth(d/1000.0);
status = 0; if ( !fits_read_key_dbl(fptr, FITS_KEYS[FK_PIXY], &d, NULL, &status) ) SetPixelHeight(d/1000.0);
status = 0; if ( !fits_read_key_lng(fptr, FITS_KEYS[FK_BINX], &l, NULL, &status) &&
!fits_read_key_lng(fptr, FITS_KEYS[FK_BINY], &l2, NULL, &status) ) SetBinning((unsigned short)l, (unsigned short)l2);
status = 0; if ( !fits_read_key_lng(fptr, FITS_KEYS[FK_ORGX], &l, NULL, &status) &&
!fits_read_key_lng(fptr, FITS_KEYS[FK_ORGY], &l2, NULL, &status) ) SetSubFrame((unsigned short)l, (unsigned short)l2);
status = 0; if ( !fits_read_key_dbl(fptr, FITS_KEYS[FK_EGAIN], &d, NULL, &status) ) SetEGain(d);
status = 0; if ( !fits_read_key_dbl(fptr, FITS_KEYS[FK_FL], &d, NULL, &status) ) SetFocalLength(d/25.4);
status = 0; if ( !fits_read_key_dbl(fptr, FITS_KEYS[FK_APTD], &d, NULL, &status) ) SetApertureDiameter(d/25.4);
status = 0; if ( !fits_read_key_dbl(fptr, FITS_KEYS[FK_APTA], &d, NULL, &status) ) SetApertureArea(d/25.4/25.4);
status = 0; if ( !fits_read_key_lng(fptr, FITS_KEYS[FK_BLACK], &l, NULL, &status) ) SetBackground(l);
status = 0; if ( !fits_read_key_lng(fptr, FITS_KEYS[FK_WHITE], &l, NULL, &status) ) SetRange(l - GetBackground());
status = 0; if ( !fits_read_key_lng(fptr, FITS_KEYS[FK_PED], &l, NULL, &status) ) SetPedestal((unsigned short)(l+100));
status = 0; if ( !fits_read_key_lng(fptr, FITS_KEYS[FK_MAX], &l, NULL, &status) ) SetSaturationLevel((unsigned short)l);
status = 0; if ( !fits_read_key_str(fptr, FITS_KEYS[FK_SWA], s, NULL, &status) ) SetSoftware(s);
status = 0; if ( !fits_read_key_str(fptr, FITS_KEYS[FK_FILT], s, NULL, &status) ) SetFilter(s);
status = 0; if ( !fits_read_key_lng(fptr, FITS_KEYS[FK_SNAP], &l, NULL, &status) ) SetNumberExposures((unsigned short)l);
SetEachExposure(GetExposureTime()/l);
status = 0; if ( !fits_read_key_lng(fptr, FITS_KEYS[FK_RES], &l, NULL, &status) ) SetReadoutMode((unsigned short)l);
status = 0; if ( !fits_read_key_str(fptr, FITS_KEYS[FK_EXPST], s, NULL, &status) && sscanf(s,"%lX", &l) == 1 ) SetExposureState((unsigned short)l);
status = 0; if ( !fits_read_key_dbl(fptr, FITS_KEYS[FK_RESP], &d, NULL, &status) ) SetResponseFactor(d);
status = 0; if ( !fits_read_key_str(fptr, FITS_KEYS[FK_NOTE], s, NULL, &status) ) SetImageNote(s);
status = 0; if ( !fits_read_key_dbl(fptr, FITS_KEYS[FK_TRAK], &d, NULL, &status) ) SetTrackExposure(d);
status = 0;
// read and filter out the parsed keywords
fits_get_hdu_num(fptr, &hdupos); /* Get the current HDU position */
for (; !status; hdupos++) /* Main loop through each extension */
{
fits_get_hdrspace(fptr, &nkeys, NULL, &status); /* get # of keywords */
for (ii = 1; ii <= nkeys; ii++) { /* Read and print each keywords */
if (fits_read_record(fptr, ii, card, &status)) break;
for (jj=0; jj<FK_NEXT; jj++) {
l = strlen(FITS_KEYS[jj]);
if ( strncmp(card, FITS_KEYS[jj], l) == 0 ) break;
}
if ( jj == FK_NEXT ) {
if ( !first ) m_cAdditionalFITSKeys += "\r";
m_cAdditionalFITSKeys += card ;
first = FALSE;
}
}
fits_movrel_hdu(fptr, 1, NULL, &status); /* try to move to next HDU */
}
if (status == END_OF_FILE) status = 0; /* Reset after normal error */
if ( status ) break;
// got here so there was no error
err = SBFE_NO_ERROR;
m_nDefaultImageFormat = SBIF_FITS;
} while ( FALSE );
fits_close_file(fptr, &status);
}
if (err == SBFE_NO_ERROR && status)
err = SBFE_FORMAT_ERROR;
if ( err != SBFE_NO_ERROR )
DeleteImageData();
return(err);
}
#endif
csbigimg.h
#ifndef _CSBIGIMG_
#define _CSBIGIMG_
/*
Compile Time Options
*/
#define INCLUDE_FITSIO 1 /* set to 1 to compile and link with FITSIO Library */
#ifndef _LPARDRV_
#include "lpardrv.h"
#endif
#include <time.h>
#include <string>
using namespace std;
#if INCLUDE_FITSIO
#include "fitsio.h"
#endif /* INCLUDE_FITSIO */
#ifndef PI
#define PI 3.1415926535
#endif
/*
Exposure State Field Defines
*/
#define ES_ABG_MASK 0x0003
#define ES_ABG_UNKNOWN 0x0000
#define ES_ABG_LOW 0x0001
#define ES_ABG_CLOCKED 0x0002
#define ES_ABG_MID 0x0003
#define ES_ABG_RATE_MASK 0x00C0
#define ES_ABG_RATE_FIXED 0x0000
#define ES_ABG_RATE_LOW 0x0040
#define ES_ABG_RATE_MED 0x0080
#define ES_ABG_RATE_HI 0x00C0
#define ES_DCS_MASK 0x000c
#define ES_DCS_UNKNOWN 0x0000
#define ES_DCS_ENABLED 0x0004
#define ES_DCS_DISABLED 0x0008
#define ES_DCR_MASK 0x0030
#define ES_DCR_UNKNOWN 0x0000
#define ES_DCR_ENABLED 0x0010
#define ES_DCR_DISABLED 0x0020
#define ES_AUTOBIAS_MASK 0x0100
#define ES_AUTOBIAS_ENABLED 0x0100
#define ES_AUTOBIAS_DISABLED 0x0000
typedef enum { SBIF_COMPRESSED,
SBIF_UNCOMPRESSED,
SBIF_FITS,
SBIF_DEFAULT } SBIG_IMAGE_FORMAT;
typedef enum
{
SBFE_NO_ERROR,
SBFE_OPEN_ERROR,
SBRE_CLOSE_ERROR,
SBFE_READ_ERROR,
SBFE_WRITE_ERROR,
SBFE_FORMAT_ERROR,
SBFE_MEMORY_ERROR,
SBFE_FITS_HEADER_ERROR,
SBFE_WRONG_SIZE,
SBFE_NEXT_ERROR
} SBIG_FILE_ERROR;
class CSBIGImg
{
/* */
private:
int m_nHeight, m_nWidth; // image size in pixels
int m_nSubFrameTop, m_nSubFrameLeft;// for partial frames the top-left pixel
unsigned short *m_pImage; // pointer to image data
double m_dCCDTemperature; // CCD Temp at start of exposure
double m_dExposureTime; // Exposure time in seconds
double m_dTrackExposure; // Exposure when tracking
double m_dEachExposure; // Snapshot time in seconds
double m_dFocalLength; // Lens/Telescope Focal Length in inches
double m_dApertureArea; // Lens/Telescope Aperture Are in Sq-Inches
double m_dResponseFactor; // Magnitude Calibration Factor
double m_dPixelHeight, m_dPixelWidth; // Pixel Dimensions in mm
double m_dEGain; // Electronic Gain, e-/ADU
long m_lBackground, m_lRange; // Display Background and Range
unsigned short m_uNumberExposures; // Number of exposures co-added
unsigned short m_uSaturationLevel; // Pixels at this level are saturated
unsigned short m_uPedestal; // Image Pedestal
unsigned short m_uExposureState; // Exposure State
unsigned short m_uReadoutMode; // Camera Readout Mode use to acquire image
unsigned short m_uHorizontalBinning; // Binning used in X
unsigned short m_uVerticalBinning; // Binning used in Y
string m_cImageNote; // Note attached to image
string m_cObserver; // Observer name
string m_cHistory; // Image History string of modification chars
string m_cFilter; // Filter name imaged through
string m_cSoftware; // Software App Name and Version
string m_cCameraModel; // Model of camera used to acquire image
int m_isCompressed; // clc
MY_LOGICAL m_bImageModified; // True when modified and not saved
SBIG_IMAGE_FORMAT m_nDefaultImageFormat; // default image format for Saves
struct tm m_sDecodedImageStartTime; // Decoded time light exposure started
MY_LOGICAL m_bImageCanClose; // TRUE when image can be closed, FALSE if owned by
// a CSBIGCam object and acquiring data
/* */
public:
/* Constructors/Destructor */
CSBIGImg(void);
CSBIGImg(int height, int width);
~ CSBIGImg(void);
void Init(void);
void DeleteImageData(void);
.
.
.
/* More Accessor Functions */
void SetImageStartTime(void);
void SetImageStartTime(time_t startTime);
void SetImageStartTime(int mon, int dd, int yy, int hr, int min, int sec);
void SetImageStartTime(struct tm *pStartTime);
void SetSubFrame(int nLeft, int nTop);
void GetSubFrame(int &nLeft, int &nTop);
void SetBinning(unsigned short nHoriz, unsigned short nVert);
void GetBinning(unsigned short &nHoriz, unsigned short &nVert);
void AddHistory(string str);
/* File IO Routines */
SBIG_FILE_ERROR SaveImage(const char *pFullPath, SBIG_IMAGE_FORMAT fmt = SBIF_DEFAULT);
SBIG_FILE_ERROR OpenImage(const char *pFullPath);
/* Utility Functions */
MY_LOGICAL AllocateImageBuffer(int height, int width);
void CreateSBIGHeader(char *pHeader, MY_LOGICAL isCompressed);
MY_LOGICAL ParseHeader(char *pHeader, MY_LOGICAL &isCompressed);
SBIG_FILE_ERROR SaveCompressedImage(const char *pFullPath, char *pHeader);
SBIG_FILE_ERROR ReadCompressedImage(FILE *fh);
SBIG_FILE_ERROR SaveUncompressedImage(const char *pFullPath, char *pHeader);
SBIG_FILE_ERROR ReadUncompressedImage(FILE *fh);
int CompressSBIGData(unsigned char *pCmpData, int imgRow);
void IntelCopyBytes(unsigned char *pRevData, int imgRow);
void AutoBackgroundAndRange(void);
string GetFileErrorString(SBIG_FILE_ERROR err);
unsigned short GetAveragePixelValue(void);
unsigned short GetAveragePixelValue(int left, int top, int width, int height);
void GetFormattedImageInfo(string &iiStr, MY_LOGICAL htmlFormat = TRUE);
/* Image Processing Funcions */
void VerticalFlip(void);
void HorizontalFlip(void);
SBIG_FILE_ERROR DarkSubtract(CSBIGImg *pImg);
SBIG_FILE_ERROR FlatField(CSBIGImg *pImg);
/* Color Image Processing */
void RemoveBayerColor(void);
#if INCLUDE_FITSIO
private:
string m_cFITSObject; // Name of object in FITS header
string m_cFITSTelescope; // Name of telescope in FITS header
double m_dApertureDiameter; // Diameter of telescope
string m_cAdditionalFITSKeys; // additional FITS keywords
public:
/* FITS Accessor functions */
void SetFITSObject(string str) { m_cFITSObject = str; }
string GetFITSObject(void) { return m_cFITSObject;}
void SetFITSTelescope(string str) { m_cFITSTelescope = str; }
string GetFITSTelescope(void) { return m_cFITSTelescope;}
void SetApertureDiameter(double ap) { m_dApertureDiameter = ap; }
double GetApertureDiameter(void) { return m_dApertureDiameter; }
void SetAdditionalFITSKeys(string str) { m_cAdditionalFITSKeys = str; }
string GetAdditionalFITSKeys(void) { return m_cAdditionalFITSKeys; }
/* FITS file format utilities */
SBIG_FILE_ERROR SaveFITS(const char *pFullPath);
SBIG_FILE_ERROR History2FITS(fitsfile *fptr);
SBIG_FILE_ERROR ReadFITSImage(const char *pFullPath);
#endif
};
#endif /* #ifndef _CSBIGIMG_ */
I was getting this error after adding the include files and linking the library. It was because the lib was built with non-unicode and my application was unicode. Matching them fixed it.
When you have everything #included, an unresolved external symbol is often a missing * or & in the declaration or definition of a function.
Related
VS 2010: error LNK2019: unresolved external symbol "extern "C" void * __cdecl
I'm new in C++, I tried to copy this code and run in visual studio 2010. But it is giving unresolved extern 'c' error and another unresolved token "extern "C" as listed below the code. This is the code causing the errors : #ifdef _MANAGED // Works only with managed C++ #pragma once #pragma managed(push, on) #include <stdlib.h> //free typedef void (__cdecl *_PVFV)(void); extern "C" void * __cdecl _decode_pointer(void *); extern "C" void * __cdecl _encoded_null(); // crtdll.c extern "C" _PVFV *__onexitbegin; extern "C" _PVFV *__onexitend; void CrtDestroyStatics(void) { _PVFV * onexitbegin = (_PVFV *)_decode_pointer(__onexitbegin); if (onexitbegin) { _PVFV * onexitend = (_PVFV *)_decode_pointer(__onexitend); _PVFV function_to_call = NULL; /* save the start and end for later comparison */ _PVFV * onexitbegin_saved = onexitbegin; _PVFV * onexitend_saved = onexitend; while (1) { _PVFV * onexitbegin_new = NULL; _PVFV * onexitend_new = NULL; /* find the last valid function pointer to call. */ while (--onexitend >= onexitbegin && (*onexitend == NULL || *onexitend == _encoded_null())) { /* keep going backwards. */ } if (onexitend < onexitbegin) { /* there are no more valid entries in the list, we are done. */ break; } /* cache the function to call. */ function_to_call = (_PVFV)_decode_pointer(*onexitend); /* mark the function pointer as visited. */ *onexitend = (_PVFV)_encoded_null(); /* call the function, which can eventually change __onexitbegin and __onexitend */ (*function_to_call)(); onexitbegin_new = (_PVFV *)_decode_pointer(__onexitbegin); onexitend_new = (_PVFV *)_decode_pointer(__onexitend); if ( ( onexitbegin_saved != onexitbegin_new ) || ( onexitend_saved != onexitend_new ) ) { /* reset only if either start or end has changed */ __onexitbegin = onexitbegin_saved = onexitbegin_new; __onexitend = onexitend_saved = onexitend_new; } break; } /* * free the block holding onexit table to * avoid memory leaks. Also zero the ptr * variables so that they are clearly cleaned up. */ free ( onexitbegin ) ; __onexitbegin = __onexitend = (_PVFV *)_encoded_null(); } } //CrtDestroyStatics #pragma managed(pop) #endif And here is the linker errors: Error 4 error LNK2019: unresolved external symbol "extern "C" void * __cdecl _decode_pointer(void *)" (?_decode_pointer##$$J0YAPEAXPEAX#Z) referenced in function "void __cdecl CrtDestroyStatics(void)" (?CrtDestroyStatics##$$FYAXXZ) Error 3 error LNK2028: unresolved token (0A000F2F) "extern "C" void * __cdecl _decode_pointer(void *)" (?_decode_pointer##$$J0YAPEAXPEAX#Z) referenced in function "void __cdecl CrtDestroyStatics(void)" (?CrtDestroyStatics##$$FYAXXZ) Although I have those libraries values inherited for Additional Dependencies in Linker->Input kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib Please tell me what wrong I have committed?
If _decode_poiner is not available in your kernel32, it seems that your configuration is not correctly setup. If you had an older version of VS and upgraded, make sure that the linker doesn't point to the old environment. You can check here for additional information on how to solve this.
Unable to link with libx264.lib static library
I'm building custom video encoder using x264 as a static library. I've followed this guide in order to build static library. Trying to compile this: x264_t * setup_encoder(int width, int height){ x264_param_t param; x264_param_default_preset(¶m, "veryfast", "zerolatency"); param.i_threads = 1; param.i_width = width; param.i_height = height; param.i_fps_num = 26; param.i_fps_den = 1; // Intra refres: param.i_keyint_max = 26; param.b_intra_refresh = 1; //Rate control: param.rc.i_rc_method = X264_RC_CRF; param.rc.f_rf_constant = 25; param.rc.f_rf_constant = 25; param.rc.f_rf_constant_max = 35; //For streaming: param.b_repeat_headers = 1; param.b_annexb = 1; x264_param_apply_profile(¶m, "baseline"); return x264_encoder_open(¶m); } Results in: main.obj : error LNK2019: unresolved external symbol "int __cdecl x264_param_default_preset(struct x264_param_t *,char const *,char const *)" main.obj : error LNK2019: unresolved external symbol "int __cdecl x264_param_apply_profile(struct x264_param_t *,char const *)" main.obj : error LNK2019: unresolved external symbol "struct x264_t * __cdecl x264_encoder_open_136(struct x264_param_t *)" %PROJECT_DIR%: fatal error LNK1120: 3 unresolved externals Linker scans libx264.lib, but can't find anything inside. Searching .\lib\libx264.lib: With dumpbin /HEADERS I can actually find the declaration I need, but linker is unable to do it. SECTION HEADER #38 .text name 0 physical address 0 virtual address E60 size of raw data 930C file pointer to raw data (0000930C to 0000A16B) D219 file pointer to relocation table 0 file pointer to line numbers 40 number of relocations 0 number of line numbers 60501020 flags Code COMDAT; sym= x264_param_default_preset 16 byte align Execute Read Enviroment is Visual Studio 2012 with Intel Compiler 14 on Windows 8 64-bit.
try including using C style bindings. extern "C" { #include <x264.h> }
error LNK2019: unresolved external symbol
I'm fresh in c++ and I'm facing a problem in including C++ code in Matlab C Mex-file. I have 5 files: RTIFederate.h, RTIFederate.cpp, RTIFedAmb.cpp, RTIFedAmb.h, RTI3.cpp. RTI3.cpp contains the MEX modules. I'm getting the following errors while compiling with MEX command and libraries: Creating library C:\Users\Nudel\AppData\Local\Temp\mex_DBx_sv\templib.x and object C:\Users\Nudel\AppData\Local\Temp\mex_DBx_sv\templib.exp RTI3.obj : error LNK2019: unresolved external symbol "class rti1516e::ObjectInstanceHandle DistributedParametersLine" (?DistributedParametersLine##3VObjectInstanceHandle#rti1516e##A) referenced in function "void __cdecl mdlOutputs(struct SimStruct_tag *,int)" (?mdlOutputs##YAXPAUSimStruct_tag##H#Z) RTI3.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * IEC_Model" (?IEC_Model##3PAV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##A) referenced in function "void __cdecl mdlOutputs(struct SimStruct_tag *,int)" (?mdlOutputs##YAXPAUSimStruct_tag##H#Z) RTI3.obj : error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * IEC_Attribute" (?IEC_Attribute##3PAV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##A) referenced in function "void __cdecl mdlOutputs(struct SimStruct_tag *,int)" (?mdlOutputs##YAXPAUSimStruct_tag##H#Z) RTI3.obj : error LNK2019: unresolved external symbol "class rti1516e::ObjectInstanceHandle PowerResource" (?PowerResource##3VObjectInstanceHandle#rti1516e##A) referenced in function "void __cdecl mdlOutputs(struct SimStruct_tag *,int)" (?mdlOutputs##YAXPAUSimStruct_tag##H#Z) RTI3.obj : error LNK2019: unresolved external symbol "class rti1516e::AttributeHandle * _classattribute" (?_classattribute##3PAVAttributeHandle#rti1516e##A) referenced in function "void __cdecl mdlOutputs(struct SimStruct_tag *,int)" (?mdlOutputs##YAXPAUSimStruct_tag##H#Z) RTI3.obj : error LNK2019: unresolved external symbol "public: __thiscall RTIFedAmb::RTIFedAmb(void)" (??0RTIFedAmb##QAE#XZ) referenced in function "public: void __thiscall RTIFederate::run(void)" (?run#RTIFederate##QAEXXZ) RTI3.mexw32 : fatal error LNK1120: 6 unresolved externals C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'RTI3.mexw32' failed My RTI3.cpp has the following piece of code: #include "RTIFederate.cpp" static void mdlOutputs(SimStruct *S, int_T tid) { RTIFederate *c = (RTIFederate*) ssGetPWork(S)[0]; // LĂȘ a porta de entrada correspondente time_T offset = ssGetOffsetTime(S,0); time_T timeOfNextHit = ssGetT(S) + offset ; ssSetTNext(S, timeOfNextHit); for(int_T i=0;i<NUM_INPUTS;i++) { int *dims = ssGetInputPortDimensions(S, i); int frameSize = dims[0]; // Tamanho do campo (se for trifasico sera 3 , por ex int numChannels = dims[1]; if((ssGetInputPortWidth(S,i)<1) ||(ssGetInputPortWidth(S,i)>1)|| (frameSize>1)) { InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S, i); real_T *y = ssGetOutputPortRealSignal(S,i); int_T width = ssGetOutputPortWidth(S,i); mexPrintf("%s%d%s%s%d\n","Num da entrada ->",i," ","Num largura > ",width); for (int_T j=0;j<width;j++){ *y++ =*uPtrs[j]; mexPrintf("%s%u%s\n","IEC_Model[",i,"]--",IEC_Attribute[i].c_str()); if(IEC_Model[i].compare("DistributedParametersLine")!=0) { if(IEC_Attribute[i].compare("Voltage")) { mexPrintf("%s%u%s%f\n","Voltage[",j,"]-->",*uPtrs[j]); c->AtualizaValoresdeAtributos(DistributedParametersLine,_classattribute[0],*uPtrs[j],timeOfNextHit); } else if(IEC_Attribute[i].compare("Current")) { mexPrintf("%s%u%s%f\n","Current[",j,"]-->",*uPtrs[j]); c->AtualizaValoresdeAtributos(DistributedParametersLine,_classattribute[0],*uPtrs[j],timeOfNextHit); } } // end if IEC_Model mexPrintf("%s%f\n","Avanco de tempo1->",timeOfNextHit); } // end for } else { double *u1=(double *) ssGetInputPortSignal(S, i); real_T *y1 = ssGetOutputPortRealSignal(S,i); (*y1) =(*u1); //copia entrada para saida mexPrintf("%s%f\n","Avanco de tempo2->",timeOfNextHit); c->AtualizaValoresdeAtributos(PowerResource,_classattribute[0],*u1,timeOfNextHit); } // end else } // end for i } /* Function: mdlTerminate */ static void mdlStart(SimStruct *S) { char *buf; size_t buflen; int status; buflen = mxGetN((ssGetSFcnParam(S, 2)))*sizeof(mxChar)+1 ; // read 3rd param buf = (char *)mxMalloc(buflen); //alloc mem status = mxGetString((ssGetSFcnParam(S, 2)), buf,(mwSize)buflen); ssGetPWork(S)[0] = (void *) new RTIFederate; // store new C++ object in the RTIFederate *c = (RTIFederate *) ssGetPWork(S)[0]; c->InterpretaArqMDL(buf); // Rotina que trata da interpretacao dos objetos da norma IEC 61968 c->run(); ... } On top of RTIFederate.cpp I have declared the following: #include "RTIFedAmb.h" #include "RTIFederate.h" and in the file RTIFederate.h I declared: class RTIFederate { public: RTIambassador *rtiamb; RTIFedAmb *fedamb; // variables // ObjectClassHandle _ClassObject[300]; AttributeHandle _classattribute[300]; string IEC_Model[29],IEC_Attribute[20];// // public methods // RTIFederate(); virtual ~RTIFederate(); ... } extern ObjectClassHandle _ClassObject[300]; extern AttributeHandle _classattribute[300]; extern AttributeHandleSet attributeSet[300]; extern ObjectInstanceHandle ProtectedSwitch,Recloser,ThreePhaseBreaker,ACLineSegment,DistributedParametersLine; extern RTIambassador *rtiamb; extern RTIFedAmb *fedamb; Also there is a piece of code in RTIFedAmb.h: //methods RTIFedAmb(); virtual ~RTIFedAmb() throw(); Can anyone help me to explain what am I missing ?
So, you want to include c-lib in your c ++ project. That's fine but you should note one thing: c ++ differs a bit from c. And you found a good illustration. c ++ "deforms" function names in lib while c does not. Nevertheless you still can use c libraries. Do it so: extern "C" ObjectClassHandle _ClassObject[300]; extern "C" AttributeHandle _classattribute[300]; extern "C" AttributeHandleSet attributeSet[300]; extern "C" ObjectInstanceHandle ProtectedSwitch,Recloser,ThreePhaseBreaker,ACLineSegment,DistributedParametersLine; extern "C" RTIambassador *rtiamb; extern "C" RTIFedAmb *fedamb; Hope it will help you.
MSVS2010 C++ Console Code Ported to MSVS2010 C++ GUI is Failing. Why?
I just completed a proof of concept, or so I thought, of feeding Microsoft Visual Studio 2010 some C++ code as a console program. The C++ code that compiled is given below: #include "stdafx.h" #include <stdio.h> #include <Windows.h> #include <stdlib.h> #include <sndfile.h> //The following libraries are related to parsing the text files #include <iostream> //Open the file #include <fstream> //Reading to and from files //The following libraries are for conducting the DTW analysis #include "dtw.h" using namespace std; int _tmain(int argc, _TCHAR* argv[]) { printf("This is a test\n"); //This will be the length of the buffer used to hold samples while the program processes them. //A SNDFILE is like FILE in a standard C library. Consequently, the sf_open_read and sf_open_write functions will return an //SNDFILE* pointer when they successfully open the specified file. SNDFILE* sf = NULL; /*SF_INFO will obtain information of the file we wish to load into our program. */ SF_INFO info; /*The following is descriptive information to obtain from wave files. These are declarations*/ int num_channels; double num, num_items;S double *buf; int f, sr, c; int i,j; FILE *out; /*This is where the program will open the WAV file */ info.format = 0; sf = sf_open("C:\\Users\\GeekyOmega\\Desktop\\gameon.wav", SFM_READ, &info); if(sf == NULL) { printf("Failed to open the file.\n"); getchar(); exit(-1); } /*Print some file information */ f = info.frames; sr = info.samplerate; c = info.channels; /*Print information related to file*/ printf("frames = %d\n",f); printf("sample rate = %d\n",sr); printf("channels = %d\n",c); /*Calculate and print the number of items*/ num_items = f*c; printf("Read %lf items\n", num_items); /*Allocate space for the data to be read*/ buf = (double *) malloc(num_items*sizeof(double)); num = sf_read_double(sf,buf,num_items); sf_close(sf); /*print the information*/ printf("Read %lf items\n", num); /*Write the data to the filedata.out*/ out = fopen("filedata.txt", "w"); for(i = 0; i < num; i+=c) { for(j = 0; j < c; ++j) { fprintf(out, "%lf ", buf[i +j]); } fprintf(out,"\n"); } fclose(out); } So next, and this is critical, I want this to work with a GUI. That is, I load in any file I want and it converts that wav file to text. I provide that code below: #pragma once //Libraries required for libsndfile #include <sndfile.h> #include <stdlib.h> #include <stdio.h> #include <iostream> #include <fstream> namespace WaveGui { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace System::Runtime::InteropServices; using namespace std; /// <summary> /// Summary for Form1 /// </summary> I edited this for readability. It was a standard MSVS2010 form. I only added a button and open file dialog. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK) { //Note: Ask Gustafson how we might free the memory for this strign // http://support.microsoft.com/?id=311259 char* str2 = (char*)(void*)Marshal::StringToHGlobalAnsi(openFileDialog1->FileName); SNDFILE* sf = NULL; SF_INFO info; /*The following is descriptive information to obtain from wave files. These are declarations*/ int num_channels; double num, num_items; double *buf; int f, sr, c; int i,j; FILE *out; /*This is where the program will open the WAV file */ info.format = 0; sf = sf_open(str2, SFM_READ, &info); if(sf == NULL) { exit(-1); } /*Print some file information */ f = info.frames; sr = info.samplerate; c = info.channels; /*Calculate and print the number of items*/ num_items = f*c; /*Allocate space for the data to be read*/ buf = (double *) malloc(num_items*sizeof(double)); num = sf_read_double(sf,buf,num_items); sf_close(sf); /*Write the data to the filedata.out*/ out = fopen("filedata.txt", "w"); for(i = 0; i < num; i+=c) { for(j = 0; j < c; ++j) { fprintf(out, "%lf ", buf[i +j]); } fprintf(out,"\n"); } fclose(out); } } }; } In the code for the button, I convert from a system string to regular string and then try to use the C++ code above to convert my wave file to txt information. I know the conversion code works, and I know the button code works as I have tested them separately. However, my library sndfile.h really dies when I try to use it now. The error it gives me when I added the libraries stdio.h, Windows.H, stdlib.h, iostream, fstream is as follows: 1>WaveGui.obj : error LNK2031: unable to generate p/invoke for "extern "C" int __clrcall sf_close(struct SNDFILE_tag *)" (?sf_close##$$J0YMHPAUSNDFILE_tag###Z); calling convention missing in metadata 1>WaveGui.obj : error LNK2031: unable to generate p/invoke for "extern "C" __int64 __clrcall sf_read_double(struct SNDFILE_tag *,double *,__int64)" (?sf_read_double##$$J0YM_JPAUSNDFILE_tag##PAN_J#Z); calling convention missing in metadata 1>WaveGui.obj : error LNK2031: unable to generate p/invoke for "extern "C" struct SNDFILE_tag * __clrcall sf_open(char const *,int,struct SF_INFO *)" (?sf_open##$$J0YMPAUSNDFILE_tag##PBDHPAUSF_INFO###Z); calling convention missing in metadata 1>WaveGui.obj : warning LNK4248: unresolved typeref token (01000027) for 'SNDFILE_tag'; image may not run 1>WaveGui.obj : error LNK2028: unresolved token (0A000022) "extern "C" int __clrcall sf_close(struct SNDFILE_tag *)" (?sf_close##$$J0YMHPAUSNDFILE_tag###Z) referenced in function "private: void __clrcall WaveGui::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click#Form1#WaveGui##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z) 1>WaveGui.obj : error LNK2028: unresolved token (0A000023) "extern "C" __int64 __clrcall sf_read_double(struct SNDFILE_tag *,double *,__int64)" (?sf_read_double##$$J0YM_JPAUSNDFILE_tag##PAN_J#Z) referenced in function "private: void __clrcall WaveGui::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click#Form1#WaveGui##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z) 1>WaveGui.obj : error LNK2028: unresolved token (0A000025) "extern "C" struct SNDFILE_tag * __clrcall sf_open(char const *,int,struct SF_INFO *)" (?sf_open##$$J0YMPAUSNDFILE_tag##PBDHPAUSF_INFO###Z) referenced in function "private: void __clrcall WaveGui::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click#Form1#WaveGui##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z) 1>WaveGui.obj : error LNK2019: unresolved external symbol "extern "C" int __clrcall sf_close(struct SNDFILE_tag *)" (?sf_close##$$J0YMHPAUSNDFILE_tag###Z) referenced in function "private: void __clrcall WaveGui::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click#Form1#WaveGui##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z) 1>WaveGui.obj : error LNK2019: unresolved external symbol "extern "C" __int64 __clrcall sf_read_double(struct SNDFILE_tag *,double *,__int64)" (?sf_read_double##$$J0YM_JPAUSNDFILE_tag##PAN_J#Z) referenced in function "private: void __clrcall WaveGui::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click#Form1#WaveGui##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z) 1>WaveGui.obj : error LNK2019: unresolved external symbol "extern "C" struct SNDFILE_tag * __clrcall sf_open(char const *,int,struct SF_INFO *)" (?sf_open##$$J0YMPAUSNDFILE_tag##PBDHPAUSF_INFO###Z) referenced in function "private: void __clrcall WaveGui::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click#Form1#WaveGui##$$FA$AAMXP$AAVObject#System##P$AAVEventArgs#4##Z) 1>c:\users\geekyomega\documents\visual studio 2010\Projects\WaveGui\Debug\WaveGui.exe : fatal error LNK1120: 6 unresolved externals As near as I can tell, I installed the library right. After all, it works perfectly fine with these libraries in a console situation. However, when I try to use the exact same code and libraries with my GUI form, it seems that the libraries are not playing nice with each other and as a result, I can't read my .h file right and access structs like SNDFILE. Can someone please let me know what is going wrong? I have spent hours on this and I hope I don't have to scrap the libsndfile library. I really want to get it to work with MSVS2010, with the GUI and as far as I can tell, there is no reason this shouldn't be working. But you know what they say, computers don't lie. As always, thanks for your patient help. GeekyOmega
So, your console app is native code, but your GUI app is managed C++. Was that intentional, or did you intend for your GUI app to be native (Win32) code too? I think you'll have better luck if you either go with 100% native code, or perhaps create a DLL to encapsulate your native code and call that via P/Invoke from your .NET GUI. Here's an example of using P/Invoke: http://manski.net/2012/05/29/pinvoke-tutorial-basics-part-1/
link time error in vc++ when using confuse library
I am trying to use confuse library on windows. I get a link time error when confuse is compiled in vc++. how to resolve it. Please note that libConfuse is a configuration file parser library and written in C. 1>Linking... 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_opt_getnint referenced in function "void __cdecl print_ask(struct cfg_opt_t *,unsigned int,struct _iobuf *)" (?print_ask##YAXPAUcfg_opt_t##IPAU_iobuf###Z) 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_title referenced in function "int __cdecl cb_validate_bookmark(struct cfg_t *,struct cfg_opt_t *)" (?cb_validate_bookmark##YAHPAUcfg_t##PAUcfg_opt_t###Z) 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_getstr referenced in function "int __cdecl cb_validate_bookmark(struct cfg_t *,struct cfg_opt_t *)" (?cb_validate_bookmark##YAHPAUcfg_t##PAUcfg_opt_t###Z) 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_opt_getnsec referenced in function "int __cdecl cb_validate_bookmark(struct cfg_t *,struct cfg_opt_t *)" (?cb_validate_bookmark##YAHPAUcfg_t##PAUcfg_opt_t###Z) 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_opt_size referenced in function "int __cdecl cb_validate_bookmark(struct cfg_t *,struct cfg_opt_t *)" (?cb_validate_bookmark##YAHPAUcfg_t##PAUcfg_opt_t###Z) 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_free referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_print referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_set_print_func referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_getnint referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_getnfloat referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_getnstr referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_getsec referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_getbool referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_getnsec referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_size referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_setstr referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_getint referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_parse referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_set_validate_func referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_init referenced in function _main 1>main.obj : error LNK2019: unresolved external symbol __imp__cfg_include referenced in function _main 1>F:\products\testconfuse\testconfuse\Debug\testconfuse.exe : fatal error LNK1120: 21 unresolved externals 1>Build log was saved at "file://f:\products\testconfuse\testconfuse\testconfuse\Debug\BuildLog.htm" 1>testconfuse - 22 error(s), 0 warning(s) The program has two file main.cpp and test.conf . Also not that we need to download http://bzero.se/confuse/confuse-2.6.zip and give use library libConfuse.lib which is present inside confuse-2.6\windows\msvc6\libConfuse ///// main.cpp extern "C" { #include <confuse.h> } #include <string.h> void print_func(cfg_opt_t *opt, unsigned int index, FILE *fp) { fprintf(fp, "%s(foo)", opt->name); } void print_ask(cfg_opt_t *opt, unsigned int index, FILE *fp) { int value = cfg_opt_getnint(opt, index); switch(value) { case 1: fprintf(fp, "yes"); break; case 2: fprintf(fp, "no"); break; case 3: default: fprintf(fp, "maybe"); break; } } /* function callback */ int cb_func(cfg_t *cfg, cfg_opt_t *opt, int argc, const char **argv) { int i; /* at least one parameter is required */ if(argc == 0) { cfg_error(cfg, "Too few parameters for the '%s' function", opt->name); return -1; } printf("cb_func() called with %d parameters:\n", argc); for(i = 0; i < argc; i++) printf("parameter %d: '%s'\n", i, argv[i]); return 0; } /* value parsing callback * * VALUE must be "yes", "no" or "maybe", and the corresponding results * are the integers 1, 2 and 3. */ int cb_verify_ask(cfg_t *cfg, cfg_opt_t *opt, const char *value, void *result) { if(strcmp(value, "yes") == 0) *(long int *)result = 1; else if(strcmp(value, "no") == 0) *(long int *)result = 2; else if(strcmp(value, "maybe") == 0) *(long int *)result = 3; else { cfg_error(cfg, "Invalid value for option %s: %s", opt->name, value); return -1; } return 0; } int cb_validate_bookmark(cfg_t *cfg, cfg_opt_t *opt) { /* only validate the last bookmark */ cfg_t *sec = cfg_opt_getnsec(opt, cfg_opt_size(opt) - 1); if(!sec) { cfg_error(cfg, "section is NULL!?"); return -1; } if(cfg_getstr(sec, "machine") == 0) { cfg_error(cfg, "machine option must be set for bookmark '%s'", cfg_title(sec)); return -1; } return 0; } int main(int argc, char **argv) { unsigned int i; cfg_t *cfg; unsigned n; int ret; static cfg_opt_t proxy_opts[] = { CFG_INT("type", 0, CFGF_NONE), CFG_STR("host", 0, CFGF_NONE), CFG_STR_LIST("exclude", "{localhost, .localnet}", CFGF_NONE), CFG_INT("port", 21, CFGF_NONE), CFG_END() }; static cfg_opt_t bookmark_opts[] = { CFG_STR("machine", 0, CFGF_NONE), CFG_INT("port", 21, CFGF_NONE), CFG_STR("login", 0, CFGF_NONE), CFG_STR("password", 0, CFGF_NONE), CFG_STR("directory", 0, CFGF_NONE), CFG_BOOL("passive-mode", cfg_false, CFGF_NONE), CFG_SEC("proxy", proxy_opts, CFGF_NONE), CFG_END() }; cfg_opt_t opts[] = { CFG_INT("backlog", 42, CFGF_NONE), CFG_STR("probe-device", "eth2", CFGF_NONE), CFG_SEC("bookmark", bookmark_opts, CFGF_MULTI | CFGF_TITLE), CFG_FLOAT_LIST("delays", "{3.567e2, 0.2, -47.11}", CFGF_NONE), CFG_FUNC("func", &cb_func), CFG_INT_CB("ask-quit", 3, CFGF_NONE, &cb_verify_ask), CFG_INT_LIST_CB("ask-quit-array", "{maybe, yes, no}", CFGF_NONE, &cb_verify_ask), CFG_FUNC("include", &cfg_include), CFG_END() }; #ifndef _WIN32 /* for some reason, MS Visual C++ chokes on this (?) */ printf("Using %s\n\n", confuse_copyright); #endif cfg = cfg_init(opts, CFGF_NOCASE); /* set a validating callback function for bookmark sections */ cfg_set_validate_func(cfg, "bookmark", &cb_validate_bookmark); ret = cfg_parse(cfg, argc > 1 ? argv[1] : "test.conf"); printf("ret == %d\n", ret); if(ret == CFG_FILE_ERROR) { perror("test.conf"); return 1; } else if(ret == CFG_PARSE_ERROR) { fprintf(stderr, "parse error\n"); return 2; } printf("backlog == %ld\n", cfg_getint(cfg, "backlog")); printf("probe device is %s\n", cfg_getstr(cfg, "probe-device")); cfg_setstr(cfg, "probe-device", "lo"); printf("probe device is %s\n", cfg_getstr(cfg, "probe-device")); n = cfg_size(cfg, "bookmark"); printf("%d configured bookmarks:\n", n); for(i = 0; i < n; i++) { cfg_t *pxy; cfg_t *bm = cfg_getnsec(cfg, "bookmark", i); printf(" bookmark #%u (%s):\n", i+1, cfg_title(bm)); printf(" machine = %s\n", cfg_getstr(bm, "machine")); printf(" port = %d\n", (int)cfg_getint(bm, "port")); printf(" login = %s\n", cfg_getstr(bm, "login")); printf(" passive-mode = %s\n", cfg_getbool(bm, "passive-mode") ? "true" : "false"); printf(" directory = %s\n", cfg_getstr(bm, "directory")); printf(" password = %s\n", cfg_getstr(bm, "password")); pxy = cfg_getsec(bm, "proxy"); if(pxy) { int j, m; if(cfg_getstr(pxy, "host") == 0) { printf(" no proxy host is set, setting it to 'localhost'...\n"); /* For sections without CFGF_MULTI flag set, there is * also an extended syntax to get an option in a * subsection: */ cfg_setstr(bm, "proxy|host", "localhost"); } printf(" proxy host is %s\n", cfg_getstr(pxy, "host")); printf(" proxy type is %ld\n", cfg_getint(pxy, "type")); printf(" proxy port is %ld\n", cfg_getint(pxy, "port")); m = cfg_size(pxy, "exclude"); printf(" got %d hosts to exclude from proxying:\n", m); for(j = 0; j < m; j++) { printf(" exclude %s\n", cfg_getnstr(pxy, "exclude", j)); } } else printf(" no proxy settings configured\n"); } printf("delays are (%d):\n", cfg_size(cfg, "delays")); for(i = 0; i < cfg_size(cfg, "delays"); i++) printf(" %G\n", cfg_getnfloat(cfg, "delays", i)); printf("ask-quit == %ld\n", cfg_getint(cfg, "ask-quit")); /* Using cfg_setint(), the integer value for the option ask-quit * is not verified by the value parsing callback. * * cfg_setint(cfg, "ask-quit", 4); printf("ask-quit == %ld\n", cfg_getint(cfg, "ask-quit")); */ /* The following commented line will generate a failed assertion * and abort, since the option "foo" is not declared * * printf("foo == %ld\n", cfg_getint(cfg, "foo")); */ cfg_addlist(cfg, "ask-quit-array", 2, 1, 2); for(i = 0; i < cfg_size(cfg, "ask-quit-array"); i++) printf("ask-quit-array[%d] == %ld\n", i, cfg_getnint(cfg, "ask-quit-array", i)); /* print the parsed values to another file */ { FILE *fp = fopen("test.conf.out", "w"); cfg_set_print_func(cfg, "func", print_func); cfg_set_print_func(cfg, "ask-quit", print_ask); cfg_set_print_func(cfg, "ask-quit-array", print_ask); cfg_print(cfg, fp); fclose(fp); } cfg_free(cfg); return 0; } // test.conf # test config file # this is a one line comment // this is a C++-style one line comment /* * This is a C-style multi-line comment */ BackLog = 2147483647 bookmark heimdal { login = "anonymous" password = ${ANONPASS:-anonymous#} directory = "/pub/heimdal/src" machine = "ftp://ftp.pdc.kth.se:21" proxy { type = 1 host = ${HOST:-localhost} # environment variable substitution #port = 21 #exclude = {"localhost" , ".localnet" , "fu.bar.net"} exclude += {.aol.com , .sf.net} } } probe-device = "eth1" # probe-device += "eth3" # error, probe-device is not a list bookmark gazonk { machine = "ssh://localhost" login = joe passive-mode = true directory = '/pub/dir with spaces/\ more' # continued on next line port = 022 # in octal mode proxy {} /* use default proxy */ } bookmark ftp.du.se { machine = "ftp.du.se" // port = 0x21 /* hexadecimal */ login = ftp proxy { exclude = {.com.net} } } /* functions can be called with variable number of arguments */ func( "one", "two", 'three',four ) func( 1, 2 ) //delays = {145.12345, .6,42, 4.987e2} //delays += {0.1, 0.2, 0.3} ask-quit = maybe #ask-quit-array = {"maybe", "maybe", "maybe"} ask-quit-array += {"no", "yes", "yes"} include(inc.conf) ///////////////////////////////// I have added libconfuse.lib inside linker->input->"additional depenendencies" and also given path of lib linker->General ->"additional link directory" I have added libconfuse 2.6 and extracted it. I have used lib in it also config.h from its src dir. I have then compiled example program from libconfuse home page.
I think you didnt add a reference to a lib that is needed for the "confuselib" to work. Can you check your compiler linker includes and see if you added all the relevant confuse libraries ?
those methods are all defined in confuse.c; either you are not linking with the confuse library, or with another version, or you built the confuse library with an erroneous configuration.
The issue is fixed now . it was resolved when i gave lib path from F:\confuse-2.6\windows\msvc6\libConfuse to F:\confuse-2.6\windows\msvs.net\libConfuse\Release