473,245 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,245 software developers and data experts.

what's the difference between #include "queue.h" and #include "queue.cpp"

Dear all,
When I use #include "queue.h", I can't link it.
The error message follows:
Linking...
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x136): In
function `main':
G:\Projects\Datastructure\Queue\main.cpp:16: undefined reference to
`Queue<char>::Queue()'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x394): In
function `Z10do_commandcR5QueueIcE':
G:\Projects\Datastructure\Queue\main.cpp:65: undefined reference to
`Queue<char>::retrieve(char&) const'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x473):G:\Projects\Datastructure\Queue\main.cpp:8 3:
undefined reference to `Queue<char>::append(char const&)'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x4e5):G:\Projects\Datastructure\Queue\main.cpp:9 2:
undefined reference to `Queue<char>::serve()'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x56b):G:\Projects\Datastructure\Queue\main.cpp:1 02:
undefined reference to `Queue<char>::empty() const'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x581):G:\Projects\Datastructure\Queue\main.cpp:1 03:
undefined reference to `Queue<char>::retrieve(char&) const'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x5b0):G:\Projects\Datastructure\Queue\main.cpp:1 05:
undefined reference to `Queue<char>::serve()'
collect2: ld returned 1 exit status

But when I use #include "queue.cpp", everything goes right.
Should we use #include "queue.h" when we use a class? Why it doesn't work?
Mar 13 '06 #1
3 5109
But when I use #include "queue.cpp", everything goes right.
Should we use #include "queue.h" when we use a class? Why it doesn't
work?

Yuck!

#include "queue.h" // now the compiler knows the definitions and
declarations required for Quele class.

Include the Queue.cpp into your project.
Mar 13 '06 #2
Kceiw wrote:
Dear all,
When I use #include "queue.h", I can't link it.
The error message follows:
Linking...
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x136): In
function `main':
G:\Projects\Datastructure\Queue\main.cpp:16: undefined reference to
`Queue<char>::Queue()'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x394): In
function `Z10do_commandcR5QueueIcE':
G:\Projects\Datastructure\Queue\main.cpp:65: undefined reference to
`Queue<char>::retrieve(char&) const'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x473):G \Projects\Datastructure\Queue\main.cpp:83: undefined reference to `Queue<char>::append(char const&)'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x4e5):G \Projects\Datastructure\Queue\main.cpp:92: undefined reference to `Queue<char>::serve()'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x56b):G \Projects\Datastructure\Queue\main.cpp:102: undefined reference to `Queue<char>::empty() const'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x581):G \Projects\Datastructure\Queue\main.cpp:103: undefined reference to `Queue<char>::retrieve(char&) const'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x5b0):G \Projects\Datastructure\Queue\main.cpp:105: undefined reference to `Queue<char>::serve()'
collect2: ld returned 1 exit status
Yes. You forgot to link your Queue implementation.
But when I use #include "queue.cpp", everything goes right.
Should we use #include "queue.h" when we use a class?
Yes.
Why it doesn't work?


Because you didn't tell your build system that queue.cpp contains something
that is needed. It must be compiled and linked to your program. How that is
done depends on your build system/IDE or whatever you use.

Mar 13 '06 #3
"Kceiw" <kc***@163.com> wrote in message news:dv**********@news.cn99.com...
Dear all,
When I use #include "queue.h", I can't link it.
The error message follows:
Linking...
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x136): In
function `main':
G:\Projects\Datastructure\Queue\main.cpp:16: undefined reference to
`Queue<char>::Queue()'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x394): In
function `Z10do_commandcR5QueueIcE':
G:\Projects\Datastructure\Queue\main.cpp:65: undefined reference to
`Queue<char>::retrieve(char&) const'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x473):G:\Projects\Datastructure\Queue\main.cpp:8 3:
undefined reference to `Queue<char>::append(char const&)'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x4e5):G:\Projects\Datastructure\Queue\main.cpp:9 2:
undefined reference to `Queue<char>::serve()'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x56b):G:\Projects\Datastructure\Queue\main.cpp:1 02:
undefined reference to `Queue<char>::empty() const'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x581):G:\Projects\Datastructure\Queue\main.cpp:1 03:
undefined reference to `Queue<char>::retrieve(char&) const'
G:\Projects\Datastructure\Queue\Debug\main.o(.text +0x5b0):G:\Projects\Datastructure\Queue\main.cpp:1 05:
undefined reference to `Queue<char>::serve()'
collect2: ld returned 1 exit status

But when I use #include "queue.cpp", everything goes right.
Should we use #include "queue.h" when we use a class? Why it doesn't work?


You need to #include "queue.h" and also add the queue.cpp to your project.
The step you are missing is adding queue.cpp to your project. It also needs
to be compiled into an object file.
Hmm. I see .o files and not .obj so it looks like you're using gpp. Not
sure how to add to gpp type projects (if there are even project files).
Mar 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Evan Simpson | last post by:
WEBoggle needs a new game board every three minutes. Boards take an unpredictable (much less than 3min, but non-trivial) amount of time to generate. The system is driven by web requests, and I...
5
by: Danny Anderson | last post by:
Hola! I am working on a program where I am including a library that came with my numerical methods textbook. The "util.h" simply includes a large number of files. I had to change the util.h...
7
by: mescaline | last post by:
Hi, Suppose a_file.cpp contains a function a_function() Now to include it in main_file.cpp I just do #include "a_file.cpp" and I'm all set. i recently came across this seemingly roundabout...
18
by: Tuckers | last post by:
My question is, if I have created my own library which lives in its own install directory, to refer to its header file is it better to use #include "MyLibrary.h" or #include <MyLibrary.h> ...
2
by: Zhaozhi Gao | last post by:
I'm doing a simple project for school. This is the first time I've ever used Access. Is there a way i can simulate a Circular Queue data structure for the datas in a table. I tried assign index...
1
by: Dominic | last post by:
Hi all, We've just migrated to IIS 6.0 / Windows Server 2003. We are now experiencing some stability problem what we did not experience in IIS 5.0 / Windows 2000 Server. Our ASP.NET application...
9
by: Richard Lionheart | last post by:
Hi All, I've got Visual Studio .Net installed, but I don't know it very well. So I tried to create a plain old Win32 using the command-line complier. I tried to compile: ************...
5
by: playagain | last post by:
Please help me to build a list of examples of stack and queue in real life situation... Conditions: The object concerned must only one object. And the object must be tangible. Example: Queue...
5
by: caicai | last post by:
Recently I'm doing a project on microcontroller, and I want use queue structure, but I found that phisical ram isn't enough for malloc() func, I hope to find a way using queue without malloc(), is...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.