Problem with Boost::Test - c++

Why this (copied from boost site ) gives me an error?! in VS 2010 Ultimate:
#include <boost\test\unit_test.hpp>
#define BOOST_TEST_MODULE MyTest
int add( int i, int j ) { return i+j; }
BOOST_AUTO_TEST_CASE( my_test )
{
// seven ways to detect and report the same error:
BOOST_CHECK( add( 2,2 ) == 4 ); // #1 continues on error
BOOST_REQUIRE( add( 2,2 ) == 4 ); // #2 throws on error
if( add( 2,2 ) != 4 )
BOOST_ERROR( "Ouch..." ); // #3 continues on error
if( add( 2,2 ) != 4 )
BOOST_FAIL( "Ouch..." ); // #4 throws on error
if( add( 2,2 ) != 4 ) throw "Ouch..."; // #5 throws on error
BOOST_CHECK_MESSAGE( add( 2,2 ) == 4, // #6 continues on error
"add(..) result: " << add( 2,2 ) );
BOOST_CHECK_EQUAL( add( 2,2 ), 4 ); // #7 continues on error
}
Error
Error 1 error LNK2019: unresolved external symbol "class boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char * * const)" (?init_unit_test_suite##YAPAVtest_suite#unit_test#boost##HQAPAD#Z) referenced in function _main

Try defining BOOST_TEST_MODULE before you include the header.

Related

How to reuse test case in Boost test framework?

For example I have following test case:
#include <MyClass.hpp>
#define BOOST_TEST_MODULE MyTest
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE( my_test )
{
MyClass o1(42), o2(21);
BOOST_CHECK( o1.is_valid() );
BOOST_CHECK_EQUAL( o1 == o2 * 2 );
BOOST_CHECK_EQUAL ...
...
}
There are several similar classes that had implemented same methods, would like to test them by the same logic, test cases might be like following:
BOOST_AUTO_TEST_CASE( my_test1 )
{
MyClass1 o1(42), o2(21);
BOOST_CHECK( o1.is_valid() );
BOOST_CHECK_EQUAL( o1 == o2 * 2 );
BOOST_CHECK_EQUAL ...
...
}
BOOST_AUTO_TEST_CASE( my_test2 )
{
MyClass2 o1(42), o2(21);
BOOST_CHECK( o1.is_valid() );
BOOST_CHECK_EQUAL( o1 == o2 * 2 );
BOOST_CHECK_EQUAL ...
...
}
BOOST_AUTO_TEST_CASE( my_test3 )
{
MyClass3 o1(42), o2(21);
BOOST_CHECK( o1.is_valid() );
BOOST_CHECK_EQUAL( o1 == o2 * 2 );
BOOST_CHECK_EQUAL ...
...
}
...
Is there a way to reuse logic in the test case?
Check out template test cases.
#include <MyClass.hpp>
#define BOOST_TEST_MODULE MyTest
#include <boost/test/included/unit_test.hpp>
#include <boost/mpl/list.hpp>
typedef boost::mpl::list<MyClass1,MyClass2,MyClass3> test_types;
BOOST_AUTO_TEST_CASE_TEMPLATE( my_test, T, test_types )
{
T o1(42), o2(21);
BOOST_CHECK( o1.is_valid() );
BOOST_CHECK_EQUAL( o1 == o2 * 2 );
BOOST_CHECK_EQUAL ...
...
}

Error LNK2019: Unresolved External Symbol in Visual Studio [duplicate]

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.

Boost tests in Visual Studio

I am trying to compile trivial unit test project in Visual Studio 2010. I have a testrunner.cpp:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE "BaumWelch Unit Tests"
#include <boost/test/unit_test.hpp>
and exampletests.cpp
#include <boost/test/unit_test.hpp>
int add( int i, int j ) { return i+j; }
BOOST_AUTO_TEST_CASE( my_test )
{
// seven ways to detect and report the same error:
BOOST_CHECK( add( 2,2 ) == 4 ); // #1 continues on error
BOOST_REQUIRE( add( 2,2 ) == 4 ); // #2 throws on error
if( add( 2,2 ) != 4 )
BOOST_ERROR( "Ouch..." ); // #3 continues on error
if( add( 2,2 ) != 4 )
BOOST_FAIL( "Ouch..." ); // #4 throws on error
if( add( 2,2 ) != 4 ) throw "Ouch..."; // #5 throws on error
BOOST_CHECK_MESSAGE( add( 2,2 ) == 4, // #6 continues on error
"add(..) result: " << add( 2,2 ) );
BOOST_CHECK_EQUAL( add( 2,2 ), 4 ); // #7 continues on error
}
This example worked fine in Linux, however here it fails to compile:
1>------ Build started: Project: Test, Configuration: Release Win32 ------
1>Build started 30/01/2013 14:47:48.
1>InitializeBuildStatus:
1> Touching "Release\Test.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>boost_unit_test_framework-vc100-mt-1_46_1.lib(boost_unit_test_framework-vc100-mt-1_46_1.dll) : error LNK2005: "class boost::unit_test::master_test_suite_t & __cdecl boost::unit_test::framework::master_test_suite(void)" (?master_test_suite#framework#unit_test#boost##YAAAVmaster_test_suite_t#23#XZ) already defined in libboost_unit_test_framework-vc100-mt-1_46_1.lib(framework.obj)
1>MSVCRT.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain#16
1>C:\Users\ga1009\Documents\dev\Oasis\Release\Test.exe : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
What am I doing wrong and how can I fix it?
EDIT: After applying the answer from Arne Mertz, I get:
1>------ Build started: Project: Test, Configuration: Release Win32 ------
1>Build started 30/01/2013 15:09:54.
1>InitializeBuildStatus:
1> Touching "Release\Test.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>boost_unit_test_framework-vc100-mt-1_46_1.lib(boost_unit_test_framework-vc100-mt-1_46_1.dll) : error LNK2005: "class boost::unit_test::master_test_suite_t & __cdecl boost::unit_test::framework::master_test_suite(void)" (?master_test_suite#framework#unit_test#boost##YAAAVmaster_test_suite_t#23#XZ) already defined in libboost_unit_test_framework-vc100-mt-1_46_1.lib(framework.obj)
1>C:\Users\ga1009\Documents\dev\Oasis\Release\Test.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
Check your project's linker properties: There is a property System/SubSystem that should be set to /SUBSYSTEM:CONSOLE.
Edit:
For the multiple definition error it seems you have the following situation:
In your testrunner.cpp, you define BOOST_TEST_DYN_LINK wich leads to a dynamic linking of boost_unit_test_framework-vc100-mt-1_46_1.dll which contains a definition of the master_test_suite function. In the other .cpp, you do NOT define that symbol, so that one gets linked statically against boost_unit_test_framework-vc100-mt-1_46_1.lib which, together with the dll gives two definitions.
Solution: use the #define in every source before including the header.

Using llvm::Linker to programatically find unresolved externals

I'm using clang/llvm to programmatically compile and link bits of C source. I'm finding that the llvm Linker doesn't seem to report the fact that unresolved externals exist in a module as an error.
I've the following code (forgive the length, but this really is the minimum required):
int CompileAndLink()
{
llvm::InitializeNativeTarget();
std::string code = "int UnresolvedFunction();\n"
"int main() { return UnresolvedFunction(); }";
clang::DiagnosticOptions diagnosticOptions;
clang::TextDiagnosticPrinter tdp( llvm::outs(), diagnosticOptions );
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagIDs( new clang::DiagnosticIDs );
clang::Diagnostic diag( diagIDs, &tdp, false );
clang::FileSystemOptions fsOptions;
clang::FileManager fm( fsOptions );
clang::SourceManager sm( diag, fm );
clang::HeaderSearch hs( fm );
clang::TargetOptions targetOptions;
targetOptions.Triple = llvm::sys::getHostTriple();
clang::TargetInfo* ti = clang::TargetInfo::CreateTargetInfo( diag, targetOptions );
clang::HeaderSearchOptions headerSearchOptions;
clang::LangOptions langOptions;
clang::ApplyHeaderSearchOptions( hs, headerSearchOptions, langOptions, ti->getTriple() );
clang::PreprocessorOptions ppo;
clang::Preprocessor pp( diag, langOptions, *ti, sm, hs );
clang::FrontendOptions frontendOptions;
clang::InitializePreprocessor( pp, ppo, headerSearchOptions, frontendOptions );
pp.getBuiltinInfo().InitializeBuiltins( pp.getIdentifierTable(), langOptions );
llvm::MemoryBuffer* sourceBuffer = llvm::MemoryBuffer::getMemBufferCopy( code );
sm.createMainFileIDForMemBuffer( sourceBuffer );
clang::Builtin::Context bic( *ti );
clang::ASTContext astc( langOptions, sm, *ti,
pp.getIdentifierTable(),
pp.getSelectorTable(),
bic,
0 );
llvm::LLVMContext lc;
clang::CodeGenOptions codeGenOptions;
llvm::OwningPtr<clang::CodeGenerator> cg;
cg.reset( clang::CreateLLVMCodeGen( diag, "clang_test", codeGenOptions, lc ) );
if( cg == NULL ) {
printf( "could not create CodeGenerator\n" );
return -1;
}
clang::ParseAST( pp, cg.get(), astc );
if( tdp.getNumErrors() ) {
printf( "error parsing AST\n" );
return -2;
}
llvm::Module* new_module = cg->ReleaseModule();
if( !new_module ) {
printf( "error generating code\n" );
return -2;
}
llvm::Linker linker( "clang_test", "clang_test", lc, llvm::Linker::Verbose );
std::string error;
if( linker.LinkInModule( new_module, &error ) || !error.empty() ) {
printf( "link error\n" );
return -3;
}
llvm::Module* composite_module = linker.getModule();
if( composite_module == NULL ) {
printf( "link error\n" );
return -3;
}
llvm::ExecutionEngine *pEngine = llvm::ExecutionEngine::create( composite_module,
false,
&error );
if( !error.empty() || pEngine == NULL ) {
printf( "error creating ExecutionEngine\n" );
return -4;
}
llvm::Function* f = composite_module->getFunction( "main" );
if( f == NULL ) {
printf( "couldn't find main function\n" );
return -5;
}
// This will abort with the message:
// LLVM ERROR: Program used external function 'UnresolvedFunction' which could not be resolved!
std::vector<llvm::GenericValue> params;
llvm::GenericValue result = pEngine->runFunction( f, params );
printf( "function main returned %llu\n", result.IntVal.getZExtValue() );
return 0;
}
No errors happen anywhere until we call runFunction near the end, which gives the error "LLVM ERROR: Program used external function 'UnresolvedFunction' which could not be resolved!" before aborting.
I kinda expected LinkInModule or getModule to fail with some error, but this isn't the case. My question is: is there some way to determine that a module has unresolved externals, so as not to crash and burn when trying to execute the code? I've been spelunking through the llvm source for quite a while, and so far can't find what I'm looking for.
I'm using llvm/clang 2.9 on Mac OS X (x86_64), if that matters.
Edit: I've found a private function called GetAllUndefinedSymbols in the llvm sources (llvm-2.9/lib/Linker/LinkArchives.cpp), which appears to do what I want. I guess I was hoping there was an actual API for this, something I missed?
IIRC, nobody has ever asked for such an API, so none exists. I'm not entirely sure what you would do with such an API, anyway... any non-trivial program will reference symbols not defined in any .bc file, like malloc.
If you really want to check, something like the following should work:
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
if (I->isDeclaration())
UndefGlobals.insert(&*I);
for (Module::global_iterator I = M->global_begin(),
E = M->global_end();
I != E; ++I)
if (I->isDeclaration())
UndefGlobals.insert(&*I);
LLVM linker is used to link the Modules. Given that it's perfectly valid for Module to have the external declarations no errors should be given. So it's up to you to decide whether you need to error in such situation (some externals e.g. to C library functions in some situtation might be automagically resolved by JIT)
So, servn's code is what you have to do here.

problem with boost.test with old version

I'm trying to use boost.test on a remote system with boost 1.33.1. On my pc this little example from http://www.boost.org/doc/libs/1_42_0/libs/test/doc/html/tutorials/hello-the-testing-world.html works:
#define BOOST_TEST_MODULE MyTest
#include <boost/test/included/unit_test.hpp> // I've changed here
int add( int i, int j ) { return i+j; }
BOOST_AUTO_TEST_CASE( my_test ) // <--- line 7
{
// seven ways to detect and report the same error:
BOOST_CHECK( add( 2,2 ) == 4 ); // #1 continues on error
BOOST_REQUIRE( add( 2,2 ) == 4 ); // #2 throws on error
if( add( 2,2 ) != 4 )
BOOST_ERROR( "Ouch..." ); // #3 continues on error
if( add( 2,2 ) != 4 )
BOOST_FAIL( "Ouch..." ); // #4 throws on error
if( add( 2,2 ) != 4 ) throw "Ouch..."; // #5 throws on error
BOOST_CHECK_MESSAGE( add( 2,2 ) == 4, // #6 continues on error
"add(..) result: " << add( 2,2 ) );
BOOST_CHECK_EQUAL( add( 2,2 ), 4 ); // #7 continues on error
}
but on the remote system the file unit_test.hpp doesn't exist. On my pc the file unit_test_framework.hpp is simply:
// deprecated
#include <boost/test/included/unit_test.hpp>
and it is present on the main system. So I tried to change the include to:
#include <boost/test/included/unit_test_framework.hpp>
but the compiler says:
main.cpp:7: error: expected constructor, destructor, or type conversion before ‘(’ token
what's this? How to solve it?
On Boost 1.33 use:
#include <boost/test/auto_unit_test.hpp>
in place of:
#include <boost/test/unit_test.hpp>
and also before the #include add:
#define BOOST_AUTO_TEST_MAIN
or you'll get a linker error
If your version of boost is older than 1.33, you should try renaming BOOST_AUTO_TEST_CASE to BOOST_AUTO_UNIT_TEST, and it shouldn't break compilation on newer versions of boost.
See these Boost.Test 1.33 Release Notes :
BOOST_AUTO_UNIT_TEST renamed to
BOOST_AUTO_TEST_CASE. Old name still
provided but deprecated
What's the boost version on your target platform? Are you using an old version there?
Since you are using a header only version of boost.test (you include the boost/test/included/unit_test.hpp header and not boost/test/unit_test.hpp), can't you just copy the working boost installation from your PC to the target machine and instruct your compiler to use it?