User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,620 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,667 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:

Linker Error

Join Date: Feb 2007
Posts: 5
Reputation: Caped Sam is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Caped Sam Caped Sam is offline Offline
Newbie Poster

Linker Error

  #1  
Feb 2nd, 2007
Hi, I'm very new to C++ and I am getting the following error when I try to compile:

[Linker error] undefined reference to `CSerial::CSerial()'
[Linker error] undefined reference to `CSerial::Open(char const*, unsigned long, unsigned long, bool)'
[Linker error] undefined reference to `CSerial::~CSerial()'
.
.
.
etc.

This is the code that I am trying to compile:
 
#define STRICT
#include <tchar.h>
#include <windows.h>
#include "Serial.h"


int ShowError (LONG lError, LPCTSTR lptszMessage)
{
    // Generate a message text
    TCHAR tszMessage[256];
    wsprintf(tszMessage,_T("%s\n(error code %d)"), lptszMessage, lError);

    // Display message-box and return with an error-code
    ::MessageBox(0,tszMessage,_T("Hello world"), MB_ICONSTOP|MB_OK);
    return 1;
}

int WINAPI _tWinMain (HINSTANCE /*hInst*/, HINSTANCE /*hInstPrev*/, LPTSTR /*lptszCmdLine*/, int /*nCmdShow*/)
{
    CSerial serial;
    LONG    lLastError = ERROR_SUCCESS;

    // Attempt to open the serial port (COM1)
    lLastError = serial.Open(_T("COM1"),0,0,false);
    if (lLastError != ERROR_SUCCESS)
        return ::ShowError(serial.GetLastError(), _T("Unable to open COM-port"));

    // Setup the serial port (9600,N81) using hardware handshaking
    lLastError = serial.Setup(CSerial::EBaud9600,CSerial::EData8,CSerial::EParNone,CSerial::EStop1);
    if (lLastError != ERROR_SUCCESS)
        return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port setting"));

    // Setup handshaking
    lLastError = serial.SetupHandshaking(CSerial::EHandshakeHardware);
    if (lLastError != ERROR_SUCCESS)
        return ::ShowError(serial.GetLastError(), _T("Unable to set COM-port handshaking"));

    // The serial port is now ready and we can send/receive data. If
    // the following call blocks, then the other side doesn't support
    // hardware handshaking.
    lLastError = serial.Write("Hello world\n");
    if (lLastError != ERROR_SUCCESS)
        return ::ShowError(serial.GetLastError(), _T("Unable to send data"));

    // Close the port again
    serial.Close();
    return 0;
}

The 'Serial.h' header file can be downloaded (along with the code) here:

http://www.codeproject.com/system/Se...erial_demo.zip
or
http://www.codeproject.com/system/serial.asp

I am using DevC++

Basically I am trying to write a program to control an external power supply using a serial port. I can tell the power supply what to do using hyperterminal, so I know the connection is working. I'm just inexperienced in doing the serial communications port stuff with C++ so I'm trying to learn through this guy's demo project.

Any help with this Linker Error or this application would be amazing!

-Sam Cape
Last edited by Caped Sam : Feb 2nd, 2007 at 11:56 am. Reason: typo
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 12:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC