help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"undefined reference" error message when using mkoctfile to create oct f


From: Yan Zhang
Subject: "undefined reference" error message when using mkoctfile to create oct file
Date: Thu, 16 Feb 2017 10:45:03 -0800

Hi Folks,

 

I’m a new user of Octave and trying to make a oct file so that I can control a Newport Power Meter in my octave program. I have a c++ code file “PowerMeter.cc”, and I also have a header file “NewpDll.h” and a dll file “usbdll.dll” which are obtained from Newport driver examples.  When I tried to create the OCT file, I got the following messages:

 

----------------------------------------------------------------

>> mkoctfile PowerMeter.cc -usbdll.dll

PowerMeter.o: In function `Z12CloseDevicesv':

C:\Users\yan.zhang\Desktop\TestCam_Project\Oct_Src\cc/PowerMeter.cc:19: undefined reference to address@hidden'

PowerMeter.o: In function `Z11OpenDevicesi':

C:\Users\yan.zhang\Desktop\TestCam_Project\Oct_Src\cc/PowerMeter.cc:29: undefined reference to address@hidden'

C:\Users\yan.zhang\Desktop\TestCam_Project\Oct_Src\cc/PowerMeter.cc:30: undefined reference to address@hidden'

PowerMeter.o: In function `Z4ReadiPciPm':

C:\Users\yan.zhang\Desktop\TestCam_Project\Oct_Src\cc/PowerMeter.cc:40: undefined reference to address@hidden'

PowerMeter.o: In function `Z5WriteiPc':

C:\Users\yan.zhang\Desktop\TestCam_Project\Oct_Src\cc/PowerMeter.cc:66: undefined reference to address@hidden'

collect2.exe: error: ld returned 1 exit status

warning: mkoctfile exited with failure status

warning: called from

    mkoctfile at line 171 column 5

----------------------------------------------------------------

 

The functions “newp_usb_uninit_system”, “newp_usb_init_product”, etc are already declared in the “NewpDll.h”, and they should be implemented in the usbdll.dll (I checked the dll file using “depends”, a program that can look into dll files). I don’t understand why I still got the above error messages.

 

I’m wondering if anyone in this list can help me fix this. The content of “PowerMeter.cc” and “newpdll.h” is as follows:

 

*****************************************

PowerMeter.cc

*****************************************

#include <octave/oct.h>

#include <windows.h>

#include <string.h>

#include <winuser.h>

#include "newpdll.h"

 

bool m_bOpen=false;

char szDevInfo[1024];

 

void CloseDevices()

{

   if (m_bOpen)

   {

     m_bOpen = false;

     try

      {newp_usb_uninit_system ();}

     catch (...) {}

   }

}

 

bool OpenDevices(int nProductID)

{

  if (m_bOpen) return true;

  try

   {

     m_bOpen = newp_usb_init_product (nProductID) == 0;

     if (m_bOpen && (newp_usb_get_device_info (&szDevInfo[0]) != 0)) CloseDevices ();

   }

  catch (...)  {CloseDevices ();}

  return m_bOpen;

}

 

int Read (int nDeviceID, char* lpBuffer, int nLength, unsigned long* lBytesRead)

{

  try

  {

    int nStatus = newp_usb_get_ascii (nDeviceID, lpBuffer, nLength, lBytesRead);

    int i = *lBytesRead;

    // Search from the end of the response string

    if (i==0) lpBuffer[0]=0;

    while (--i >= 0)

    {

                // If a linefeed is found

                if (lpBuffer[i] == '\n')

                {

                 // If a return is found

                  if (lpBuffer[i - 1] == '\r') i--;

                  *lBytesRead = i;

                  // Add a string terminator

                  lpBuffer[i] = 0; //(char) NULL;

                  break;

                }

    }

 

    return nStatus;

  }

  catch (...) {return -1;}

}

 

int Write (int nDeviceID, char* lpBuffer)

{

  try

    {return newp_usb_send_ascii (nDeviceID, lpBuffer, (unsigned long) strlen (lpBuffer));}

  catch (...)

    {return -1;}

}

 

DEFUN_DLD (PowerMeterConnect, args,,"Connect to Newport Powermeter via USB inteface")

{

   if (args.length()<1) error("Newport Product ID is missing");

 

   if (OpenDevices(args(0).int_value()))

   { 

    for (int i=0;i<1024;i++)

      if (szDevInfo[i]==13) {szDevInfo[i]=0;break;}

    charMatrix retval((char *) &szDevInfo[0]);

    return octave_value(retval);

   }

   else error("Cannot connect to Power Meter device");

   return octave_value(0);

}

 

DEFUN_DLD (PowerMeterWrite, args,,"Send command to Newport Powermeter via USB inteface")

{

   if (args.length()<2) error("Not enough parameters");

   int devID=args(0).int_value();

   const octave_base_value& data = "">

 

   if (data.is_string() )

     {

       std::string s = data.string_value();      

       return octave_value((Write(devID,  &s[0])==0));      

     }

   else  error("Command must be a string");

   return octave_value_list();

}

 

DEFUN_DLD (PowerMeterRead, args,,"Read data from Newport Powermeter via USB inteface")

{

   if (args.length()<1) error("Device ID is missing");

   int devID=args(0).int_value();

   char buf[256]; buf[0]=0;

 

   unsigned long lBytesRead;

   if (Read (devID, &buf[0], 255,&lBytesRead)==0)

   buf[lBytesRead]=0;

  

   charMatrix retval(&buf[0]);

   return octave_value(retval);

}

 

DEFUN_DLD (PowerMeterDisconnect, args,,"Close connection to Pwer Meter")

{

  CloseDevices(); 

  return octave_value(1);

}

 

*****************************************

NewpDll.h (with comments deleted)

*****************************************

#ifndef __usbdll_h__

#define __usbdll_h__

 

#ifdef __cplusplus

extern "C"

{

#undef  EXPORT

#define EXPORT _stdcall

#else

#define EXPORT EXTERN_C _stdcall

#endif

 

#define USBDUPLICATEADDRESS 1          // More than one device on the bus has the same device ID

#define USBADDRESSNOTFOUND -2       // The device ID cannot be found among the open devices on the bus

#define USBINVALIDADDRESS -3              // The device ID is outside the valid range of 0 - 31

 

typedef void (__stdcall *DeviceStateChanged)(int handle, int nState);

extern DeviceStateChanged g_lpDeviceStateChangedCB;

 

long EXPORT newp_usb_init_system (void);

 

long EXPORT newp_usb_init_product (int nProductID);

 

long EXPORT newp_usb_open_devices (int nProductID, bool bUseUSBAddress, int* nNumDevices);

 

void EXPORT newp_usb_uninit_system (void);

 

long EXPORT newp_usb_event_init (int nProductID, DeviceStateChanged lpDeviceStateChangedCB);

 

long EXPORT newp_usb_event_assign_key (char* DeviceKey, int handle);

 

long EXPORT newp_usb_event_remove_key (char* DeviceKey);

 

long EXPORT newp_usb_event_get_attached_devices (char** ppDeviceKeys, int* pDeviceHandles);

 

long EXPORT newp_usb_event_get_key_from_handle (int handle, char* DeviceKey);

 

long EXPORT newp_usb_get_device_info (char* Buffer);

 

long EXPORT newp_usb_get_model_serial_keys (char** ppBuffer);

 

long EXPORT GetInstrumentList (int* arInstruments, int* arInstrumentsModel, int* arInstrumentsSN, int* nArraySize);

 

long EXPORT newp_usb_read_by_key (char* DeviceKey, char* Buffer, unsigned long Length, unsigned long* BytesRead);

 

long EXPORT newp_usb_get_ascii (long DeviceID, char* Buffer, unsigned long Length, unsigned long* BytesRead);

 

long EXPORT newp_usb_write_by_key (char* DeviceKey, char* Command, unsigned long Length);

 

long EXPORT newp_usb_send_ascii (long DeviceID, char* Command, unsigned long Length);

 

long EXPORT newp_usb_write_binary_by_key (char* DeviceKey, char* Command, unsigned long Length);

 

long EXPORT newp_usb_send_binary (long DeviceID, char* Command, unsigned long Length);

 

#ifdef __cplusplus

}

#endif

 

#endif //#ifndef __espdll_h__

 

 

Thanks a lot,

 

YanZ

 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]