Boreland - Linking Error

This is a discussion on Boreland - Linking Error within the C++ Programming forums, part of the General Programming Boards category; I am using Boreland 5.02 and am having difficulty compiling and linking a project. This is the first time I ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    7

    Lightbulb Boreland - Linking Error

    I am using Boreland 5.02 and am having difficulty compiling and linking a project. This is the first time I am trying this, prior to this all my programming was done in one .c file. I have only written in c so far, no c++.

    I have 3 .cpp files and 2 header files in my project, the programs compile ok, but I receive an error when it tries to link. The files I have came from my instructor, who uses microsoft visual C++.

    Here is the output when I try to compile and link the code. The last section is what is giving me trouble, the errrors are at the bottom. I have also included the .cpp and .h files below, there is not much to them, just the beginning of a program. but it does compile and link for my instructor.

    Info :Making...
    Info :atm.cpp: rebuild due to dependency atm.cpp
    Info : atm.cpp: cache age 9:39:00 PM 9/13/01, disk age 9:40:21 PM 9/13/01
    Info :Compiling C:\paul\csu\cis569 _obj_or_prog_with_c++\misc\atm example\atm.cpp
    Warn : string.h(549,3):Functions containing for are not expanded inline
    Warn : string.h(557,3):Functions containing while are not expanded inline
    Warn : string.h(563,3):Functions containing for are not expanded inline
    Warn : string.h(575,3):Functions containing for are not expanded inline
    Warn : string.h(742,96):Conversion may lose significant digits
    Warn : string.h(768,96):Conversion may lose significant digits
    Warn : string.cc(658,2):Cannot create pre-compiled header: code in header
    Warn : atm.cpp(24,2):Parameter 'argc' is never used
    Warn : atm.cpp(24,2):Parameter 'argv' is never used
    Info :account.cpp: rebuild due to dependency account.cpp
    Info : account.cpp: cache age 10:52:08 PM 9/12/01, disk age 9:40:23 PM 9/13/01
    Info :Compiling C:\paul\csu\cis569 _obj_or_prog_with_c++\misc\atm example\account.cpp
    Warn : string.h(549,3):Functions containing for are not expanded inline
    Warn : string.h(557,3):Functions containing while are not expanded inline
    Warn : string.h(563,3):Functions containing for are not expanded inline
    Warn : string.h(575,3):Functions containing for are not expanded inline
    Warn : string.h(742,96):Conversion may lose significant digits
    Warn : string.h(768,96):Conversion may lose significant digits
    Warn : string.cc(658,2):Cannot create pre-compiled header: code in header
    Info :Transferring to C:\BC5\BIN\tlink.exe @c:\PAUL\CSU\CIS569~1\MISC\ATMEXA~1\TEST.R$P
    Error: (1,1):std:perator <<(ostream near&,const std::basic_string<char,std::string_char_traits<cha r>>near&) defined in module error.cpp is duplicated in module atm.cpp
    Error: (1,1):std:perator >>(istream near&,std::basic_string<char,std::string_char_trai ts<char>>near&) defined in module error.cpp is duplicated in module atm.cpp
    Fatal: (1,1):Bad object file record in module atm.cpp near module file offset 0x00011DC4


    Code for ATM example

    atm.cpp

    // ATM.cpp : Defines the entry point for the console application.
    //

    //#include "stdafx.h"
    #include "account.h"


    #include <iostream>

    using namespace std;

    int main(int argc, char* argv[])
    {
    Account acct1("123");

    acct1.Deposit(100.0);
    acct1.CurrentBalance();
    cout << "Balance: " << acct1.CurrentBalance() << endl;

    acct1.Withdraw(50.0);
    cout << "Balance: " << acct1.CurrentBalance() << endl;

    return 0;
    }

    account.cpp

    // ATM.cpp : Defines the entry point for the console application.
    //

    //#include "stdafx.h"
    #include "account.h"


    #include <iostream>

    using namespace std;

    int main(int argc, char* argv[])
    {
    Account acct1("123");

    acct1.Deposit(100.0);
    acct1.CurrentBalance();
    cout << "Balance: " << acct1.CurrentBalance() << endl;

    acct1.Withdraw(50.0);
    cout << "Balance: " << acct1.CurrentBalance() << endl;

    return 0;
    }

    Error.cpp

    // Error.cpp: implementation of the CError class.
    //
    //////////////////////////////////////////////////////////////////////

    //#include "stdafx.h"

    #include <iostream>
    #include "Error.h"

    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////

    CError::CError()
    {

    }

    CError::CError(string strError)
    {

    }
    CError::~CError()
    {

    }

    void CError::ShowReason() {
    cout << m_ErrorMsg.c_str();
    }

    void CError::ShowReason(string strError) {
    cout << strError.c_str();
    }

    account.h

    // Account.h: interface for the Account class.
    //
    //////////////////////////////////////////////////////////////////////

    //#if !defined(AFX_ACCOUNT_H__7A3FE7A0_9661_4A17_865B_D9 9F043A66BC__INCLUDED_)
    //#define AFX_ACCOUNT_H__7A3FE7A0_9661_4A17_865B_D99F043A66B C__INCLUDED_

    #if !defined(account_incl)
    #define account_incl

    //#if _MSC_VER > 1000
    //#pragma once
    //#endif // _MSC_VER > 1000


    #include <string>

    using namespace std;

    class Account
    {
    public:

    Account();
    Account(string AcctNo);
    virtual ~Account();

    bool Deposit( double Amount );
    double CurrentBalance( void );
    bool Withdraw ( double Amount );

    private:
    string m_AccountNo;
    double m_Balance;

    };

    #endif // !defined(AFX_ACCOUNT_H__7A3FE7A0_9661_4A17_865B_D9 9F043A66BC__INCLUDED_)



    error.h

    // Error.h: interface for the CError class.
    //
    //////////////////////////////////////////////////////////////////////

    #if !defined(AFX_ERROR_H__2E7F9FFC_68D8_4D87_896D_25BA 04F40EEB__INCLUDED_)
    #define AFX_ERROR_H__2E7F9FFC_68D8_4D87_896D_25BA04F40EEB_ _INCLUDED_

    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000

    #include <string>

    using namespace std;

    class CError
    {
    public:
    CError();
    CError(string strError);
    virtual ~CError();
    void ShowReason();
    void ShowReason(string strError);

    private:
    string m_ErrorMsg;
    };

    #endif // !defined(AFX_ERROR_H__2E7F9FFC_68D8_4D87_896D_25BA 04F40EEB__INCLUDED_)

  2. #2
    unregistered
    Guest
    I suspect you are getting blindsided by compiler incompatability. Some compilers are more pickiunish than others.

    Firt, Borland 5.02 may not have STL in it and may not be namespace compliant. If you know for sure that it is, fine, but that can cause some of your errors.

    Second, I suggest you always be sure the header files are compiled before the pertinent .cpp files.

    Third, I think console programs use a default argc and argv meaning they can't be specified. I believe only true DOS programs can use command line arguments. Console programs are not true DOS programs.

    Fourth you can only have one main() function per program. No
    cpp file brought in by an included file should have a main() function in it. (see your account.cpp and your atm.cpp)

    Here's a brief outline for your program:

    Driver file---atm--- where the one and only main() is.
    includes are iostream, account.h, and error.h.

    ///////////////////////////////////////////////////////////////////////////////////

    // ATM : Defines the entry point for the console application.

    #include "account.h"
    #include "error.h"
    #include <iostream>

    using namespace std;

    int main()
    {
    Account acct1("123");

    acct1.Deposit(100.0);
    acct1.CurrentBalance();
    cout << "Balance: " << acct1.CurrentBalance() << endl;

    acct1.Withdraw(50.0);
    cout << "Balance: " << acct1.CurrentBalance() << endl;

    return 0;
    }
    ////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

    //account.h

    // Account.h: interface for the Account class.
    //
    //////////////////////////////////////////////////////////////////////

    #if !defined(account_h)
    #define account_h
    #include <string>

    using namespace std;

    class Account
    {
    public:

    Account();
    Account(string AcctNo);
    virtual ~Account();

    bool Deposit( double Amount );
    double CurrentBalance( void );
    bool Withdraw ( double Amount );

    private:
    string m_AccountNo;
    double m_Balance;

    };

    #endif

    /////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////

    //account.cpp
    ///////////////////////////////////////////////////////////
    #include "account.h"
    #include <iostream>

    using namespace std;

    //code for member functions of account.h go here

    /////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////

    error.h

    // Error.h: interface for the CError class.
    //
    //////////////////////////////////////////////////////////////////////

    #if !defined(error_h)
    #define error_h

    //code for error members goes here

    #endif;

    //////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    //Error.cpp

    // Error.cpp: implementation of the CError class.
    //
    /////////////////////////////////////////////////////////////////////

    #include <iostream>
    #include "Error.h"

    CError::CError()
    {

    }

    CError::CError(string strError)
    {

    }

    CError::~CError()
    {

    }

    void CError::ShowReason() {
    cout << m_ErrorMsg.c_str();
    }

    void CError::ShowReason(string strError) {
    cout << strError.c_str();
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 10:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 02:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21