linking problem

  • Thread starter Thomas Matthews
  • Start date
T

Thomas Matthews

Dave said:
Hi

I have a vc++ project with 2 source files and 2 headers. In File1.cpp, I
#include File1.h. In File1.h, I #include File2.h. In File2.cpp, I #include
File2.h. But I'm getting LNK2001 errors still. How do i tell the compiler
that when I build File1.cpp, it will also need File2.cpp? I think it is only
getting as far as including File2.h.

Any help is appreciated
dave

By asking the experts in a Visual C++ newsgroup. Linking is beyond
the scope of the C++ language and not discussed here.

Read the C++ FAQ and welcome.txt below.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
V

Victor Bazarov

Dave said:
I have a vc++ project with 2 source files and 2 headers. In File1.cpp, I
#include File1.h. In File1.h, I #include File2.h. In File2.cpp, I #include
File2.h. But I'm getting LNK2001 errors still. How do i tell the compiler
that when I build File1.cpp, it will also need File2.cpp? I think it is only
getting as far as including File2.h.

This is answered (in a way) in FAQ 5.8. Please take a look. Also,
setting up projects is beyond the language, perhaps you could ask
in microsoft.public.vc.ide_general. Also, _linking_ is not specified
(strictly speaking) by the language, so any linking problems are not
language issues, they are compiler-specific... HTH
 
M

Moonlit

Hi,

Create a (empty) project (or solution) and add all those files to it.

Regards, Ron AF Greve.
 
D

Dave

Hi

I have a vc++ project with 2 source files and 2 headers. In File1.cpp, I
#include File1.h. In File1.h, I #include File2.h. In File2.cpp, I #include
File2.h. But I'm getting LNK2001 errors still. How do i tell the compiler
that when I build File1.cpp, it will also need File2.cpp? I think it is only
getting as far as including File2.h.

Any help is appreciated
dave
 
C

Cy Edmunds

Dave said:
Hi

I have a vc++ project with 2 source files and 2 headers. In File1.cpp, I
#include File1.h. In File1.h, I #include File2.h. In File2.cpp, I #include
File2.h. But I'm getting LNK2001 errors still. How do i tell the compiler
that when I build File1.cpp, it will also need File2.cpp? I think it is only
getting as far as including File2.h.

Any help is appreciated
dave

Does your linker error say that some symbol cannot be found? Or does it say
that it has found it twice?

Remember that headers should not contain actual code or data:

// File2.h
void frammis(); // prototype: ok
template <typename T> T max(T x, T y) {return (x > y) ? x : y;} // template:
ok
double square(double x) {return x * x;} // bad form!
int trouble; // not good either
 
D

Dave

ahh found the error. didn't define a virtual function as pure virtual!

stupid me!

thanks all for your help
dave
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top