Linking error in VC++ 6

S

sb

Hello. I have three files in a VC++6 project - a header file called
Schedule.h, an implementation class called Schedule.cpp and a test class
with main called TestSchedule1.cpp. It compiles fine in VC++ and in Unix,
but when I run it in VC++ 6, I get several linking errors (55 to be exact).
Can anyone tell me how to resolve this? Funny thing is, someone showed me
how to resolve this like a year ago and it was pretty simple, but I've
completely forgotten!! Also, in runs fine when compiling with g++.

I'm going to include how the files are laid from from a preprocessor/header
perspective as I believe that's where the problem is...

Schedule.h:
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

Schedule.cpp:
#include "Schedule.h"

TestSchedule1.cpp:
#include "Schedule.cpp"

This is really frustrating and would greatly appreciate some help. Thanks in
advance!
 
K

Karthik Kumar

sb said:
Hello. I have three files in a VC++6 project - a header file called
Schedule.h, an implementation class called Schedule.cpp and a test class
with main called TestSchedule1.cpp. It compiles fine in VC++ and in Unix,
but when I run it in VC++ 6, I get several linking errors (55 to be exact).
Can anyone tell me how to resolve this? Funny thing is, someone showed me
how to resolve this like a year ago and it was pretty simple, but I've
completely forgotten!! Also, in runs fine when compiling with g++.

I'm going to include how the files are laid from from a preprocessor/header
perspective as I believe that's where the problem is...

Schedule.h:
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

Schedule.cpp:
#include "Schedule.h"

TestSchedule1.cpp:
#include "Schedule.cpp"

You include only the *header files* and not the implementation (
read, C++ files).
Grab a good open source c++ project and look into the organization
of the source code to learn about file organization.
 
J

John Harrison

sb said:
Hello. I have three files in a VC++6 project - a header file called
Schedule.h, an implementation class called Schedule.cpp and a test class
with main called TestSchedule1.cpp. It compiles fine in VC++ and in Unix,
but when I run it in VC++ 6, I get several linking errors (55 to be
exact). Can anyone tell me how to resolve this? Funny thing is, someone
showed me how to resolve this like a year ago and it was pretty simple,
but I've completely forgotten!! Also, in runs fine when compiling with
g++.

I'm going to include how the files are laid from from a
preprocessor/header perspective as I believe that's where the problem
is...

Schedule.h:
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

Schedule.cpp:
#include "Schedule.h"

TestSchedule1.cpp:
#include "Schedule.cpp"

Never #include one .cpp file in another. Somehow you have to tell VC++ to
compile both your .cpp files seperately. There is probably an 'Add file to
Project..' type menu item somewhere. Thats is what you should do instead of
#include, #include is for header files only.

It's clear from this and other issues that you don't know how to organise
your source code. This is a very important topic, but also rather a big one.
Buy a good book that discusses this.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top