2
votes

I know Turbo C++ is oudated as hell, but so is the curriculum of our central board in my country (India). And I am doing a school project. And I don't have the freedom to choose my own IDE and compiler. Go figure.

NOTE: I am using Turbo C++ 3.0 in DOSBox in Win10

Anyway, here is the project directory I made to test TC++'s linking:

TC/BIN

-MAIN.CPP

#include <iostream.h>
#include <conio.h>
#include "CL.H"

int main()
{
    clrscr();
    cout<<"HW";
    cl c;
    c.set(5);
    cout<<c.get();
    getch();
    return 0;
}

-CL.CPP

#include "CL.H"

void cl::set( int i )
{
    a = i;
}

int cl::get()
{
    return a;
}

-CL.H

#ifndef CL_H
#define CL_H

class cl
{
    int a;
public:
    void set( int i);
    int get();
};

#endif

All of these compile fine. Upon trying to link, I get the following linker error:

LINKER ERROR: Undefined symbol cl::get() in module MAIN.CPP

LINKER ERROR: Undefined symbol cl::set( int ) in module MAIN.CPP

2
Comments are not for extended discussion; this conversation has been moved to chat. - Andy♦
Please don't add the solution to the question, and don't add "(Solved)" to the title. You can post an answer to your own question. The way to indicate that your problem has been solved is to accept an answer. - Keith Thompson
I had the .h files also added to the project. That caused all the trouble. Removing the .h files from the project seems to make it work. Please add that as an answer. This is interesting to me since in Visual Studio you add header files to the project so they show you in the solution view. I expect the header you had in the project was cl.h and that trashed the object file created for cl.cpp. - drescherjm

2 Answers

3
votes

You can do that:

1- Open TC.exe

2- From project select Open Project

3- Enter the name of project eg: MyProj.prj and Press ok.

4- From project select Add item

5- Locate all the source files and add them.

6- compile and build.

-1
votes

(Posted on behalf of the question author).

I had the .h files also added to the project. That caused all the trouble. Removing the .h files from the project seems to make it work.