473,395 Members | 1,637 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,395 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 5124
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.