Undefined Reference to Header Functions For Hardware Programming

Hi, I am looking to program a digital to analog converter to output voltage on 12 of the available analog channels. I am an novice-intermediate programmer but cannot seem to solve a problem with undefined references.

I downloaded Measurement Computing's "DAQ" and "Instacal" programs to allow for the USB-3105 board to be recognized. Included with instillation is the Universal Library example programs for the USB-3105 DAC.

I am running windows 7 and using Code::Blocks with a GNU GCC compiler to try and run this sample program on the board. The program is also written in C/C++

When I load the VOut01.C file from the examples it reads:


/*VOut01.C****************************************************************

File: VOut01.C

Library Call Demonstrated: cbVOut()

Purpose: Writes to a D/A Output Channel.

Demonstration: Sends a digital output to D/A 0
until a key is pressed.

Other Library Calls: cbErrHandling()
cbFromEngUnits()

Special Requirements: Board 0 must have a D/A output port.

Copyright (c) 1995-2007, Measurement Computing Corp.
All Rights Reserved.
***************************************************************************/


/* Include files */
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include "..cbw.h"


/* Prototypes */
void ClearScreen (void);
void GetTextCursor (int *x, int *y);
void MoveCursor (int x, int y);


void main ()
{
/* Variable Declarations */
int ch;
int Row, Col;
int BoardNum = 0;
int ULStat = 0;
int Gain = BIP10VOLTS;
int Options = DEFAULTOPTION;
int Chan;
float DataValue;
int UDStat = 0;
float min, max;

float RevLevel = (float)CURRENTREVNUM;

/* Declare UL Revision Level */
ULStat = cbDeclareRevision(&RevLevel);

/* Initiate error handling
Parameters:
PRINTALL :all warnings and errors encountered will be printed
DONTSTOP :program will continue even if error occurs.
Note that STOPALL and STOPFATAL are only effective in
Windows applications, not Console applications.
*/
cbErrHandling (PRINTALL, DONTSTOP);

/* set up the display screen */
ClearScreen();
printf ("Demonstration of cbVOut()\n\n");

/* get the D/A channel to sample */
printf ("Enter the channel to display: ");
scanf("%i", &Chan);


printf ("\n\nNote: Please make certain that the board you are using supports\n");
printf (" the gain you are choosing and if it is not a programmable\n");
printf (" gain that the switches on the board are set correctly.\n\n");
GetTextCursor (&Col, &Row);

while (Gain > 0 && !kbhit())
{
do
{ /* select gain */
MoveCursor(Col,Row);
printf("Please select one of the following ranges(1 to 4):\n\n");
printf(" 10 VOLTS UNIPOLAR --> 1\n");
printf(" 10 VOLTS BIPOLAR ---> 2\n");
printf(" 5 VOLTS UNIPOLAR --> 3\n");
printf(" 5 VOLTS BIPOLAR ---> 4\n");
printf(" Quit ---> 0\n\n");
printf(" Your Choice ---> ");
scanf ("%i",&Gain);
} while ((Gain < 0) || (Gain > 4));

/* Set Gain, MaxVal, and MinVal */
switch (Gain)
{
case 0:
exit(1);
case 1:
Gain = UNI10VOLTS;
min=0.0;
max=10.0;
break;
case 2:
Gain = BIP10VOLTS;
min=-10.0;
max=10.0;
break;
case 3:
Gain = UNI5VOLTS;
min=0.0;
max=5.0;
break;
case 4:
Gain = BIP5VOLTS;
min=-5.0;
max=5.0;
break;
default:
break;
}

UDStat = NOERRORS;

while (UDStat == NOERRORS)
{
printf ("\n\nEnter a voltage between %.1f and +%.1f: ", min, max);
scanf ("%f", &DataValue);

ULStat = cbVOut (BoardNum, Chan, Gain, DataValue, Options);
if(UDStat == NOERRORS)
{
printf ("\n %.2f volts has been sent to D/A %d.\n\n", DataValue, Chan);
printf ("Press Q to quit , any other key to continue:\n ");
while (!kbhit()){}
ch=getch();
if (ch=='q' || ch=='Q')
exit(1);
}
}
}
}



/***************************************************************************
*
* Name: ClearScreen
* Arguments: ---
* Returns: ---
*
* Clears the screen.
*
***************************************************************************/

#define BIOS_VIDEO 0x10

void
ClearScreen (void)
{
COORD coordOrg = {0, 0};
DWORD dwWritten = 0;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (INVALID_HANDLE_VALUE != hConsole)
FillConsoleOutputCharacter(hConsole, ' ', 80 * 50, coordOrg, &dwWritten);

MoveCursor(0, 0);

return;
}


/***************************************************************************
*
* Name: MoveCursor
* Arguments: x,y - screen coordinates of new cursor position
* Returns: ---
*
* Positions the cursor on screen.
*
***************************************************************************/


void
MoveCursor (int x, int y)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

if (INVALID_HANDLE_VALUE != hConsole)
{
COORD coordCursor;
coordCursor.X = (short)x;
coordCursor.Y = (short)y;
SetConsoleCursorPosition(hConsole, coordCursor);
}

return;
}


/***************************************************************************
*
* Name: GetTextCursor
* Arguments: x,y - screen coordinates of new cursor position
* Returns: *x and *y
*
* Returns the current (text) cursor position.
*
***************************************************************************/

void
GetTextCursor (int *x, int *y)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;

*x = -1;
*y = -1;
if (INVALID_HANDLE_VALUE != hConsole)
{
GetConsoleScreenBufferInfo(hConsole, &csbi);
*x = csbi.dwCursorPosition.X;
*y = csbi.dwCursorPosition.Y;
}

return;
}



The main function has trouble referencing three of the functions included in the header file cbw.h

The undefine references to the functions state:
"undefined reference to cbDelareRevision@4"
"undefined reference to cbErrHandling@8"
"undefined reference to cbVOut@20"

I do not know how to solve this problem. I have tried including the entire header file location in the quotations at the beginning but that does not seem to solve the problem. I have also tried moving the header file's directory but that also does not seem to work.

All of the functions that have undefined references are dimmed in the header file after the statements:

/*
* Universal Library Function Prototypes.
* 3 flavors: WIN32, WIN16, LabWindows/CVI
*
*/

#if !defined (NT_DRIVER) && ! defined (WIN95_DRIVER)

#if defined (__cplusplus)
extern "C"
{
#endif

#if defined (_WIN32)
/* Win32 prototypes */

#ifdef EVENTCALLBACK
#undef EVENTCALLBACK
#endif



Afterwards all three functtions are declared as:

int EXTCCONV cbDeclareRevision(float *RevNum);
int EXTCCONV cbErrHandling (int ErrReporting, int ErrHandling);
int EXTCCONV cbVOut (int BoardNum, int Chan, int Gain, float DataValue, int Options);


The program Instacal in combination with the header file is supposed to recognize the "BoardNum" and allows for the "int Chan", "int Gain", "float DataValue", and all other subsequent dependent variables to exist.

However, I am still retaining these undefined reference errors even when I used Instacal to define the variables of the board (BoardNum, int Chan, ...ect) and added the full location of the header file.

My questions are:

-Why is this section of the header file dimmed after the endif statements?
-Is this reference problem a problem with the header files directory?
-Do the declarations of the function in the header file prevent them from being access due to their names and or symbolism?
-Why are the reference errors @4, @8, or @20, and what does this mean?
-Is this a problem with my compiler?

If anyone can help or know about this problem please help. Thanks.

-Robert


http://www.cplusplus.com/forum/general/113904/

> Why is this section of the header file dimmed after the endif statements?
you can declare a function as many times as you want. But it should only be 1 definition

> Is this reference problem a problem with the header files directory?
No, the problem is with the source, or with the libraries, that are not linked

> Do the declarations of the function in the header file prevent them from being access due to their names and or symbolism?
No, your program compiles. It knows about the existence of the function and how they should be used, but couldn't find a body for the functions.
Topic archived. No new replies allowed.