473,748 Members | 10,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\Dat astructure\Queu e\Debug\main.o( .text+0x136): In
function `main':
G:\Projects\Dat astructure\Queu e\main.cpp:16: undefined reference to
`Queue<char>::Q ueue()'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x394): In
function `Z10do_commandc R5QueueIcE':
G:\Projects\Dat astructure\Queu e\main.cpp:65: undefined reference to
`Queue<char>::r etrieve(char&) const'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x473):G: \Projects\Datas tructure\Queue\ main.cpp:83:
undefined reference to `Queue<char>::a ppend(char const&)'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x4e5):G: \Projects\Datas tructure\Queue\ main.cpp:92:
undefined reference to `Queue<char>::s erve()'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x56b):G: \Projects\Datas tructure\Queue\ main.cpp:102:
undefined reference to `Queue<char>::e mpty() const'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x581):G: \Projects\Datas tructure\Queue\ main.cpp:103:
undefined reference to `Queue<char>::r etrieve(char&) const'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x5b0):G: \Projects\Datas tructure\Queue\ main.cpp:105:
undefined reference to `Queue<char>::s erve()'
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 5152
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\Dat astructure\Queu e\Debug\main.o( .text+0x136): In
function `main':
G:\Projects\Dat astructure\Queu e\main.cpp:16: undefined reference to
`Queue<char>::Q ueue()'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x394): In
function `Z10do_commandc R5QueueIcE':
G:\Projects\Dat astructure\Queu e\main.cpp:65: undefined reference to
`Queue<char>::r etrieve(char&) const'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x473):G \Projects\Datas tructure\Queue\ main.cpp:83: undefined reference to `Queue<char>::a ppend(char const&)'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x4e5):G \Projects\Datas tructure\Queue\ main.cpp:92: undefined reference to `Queue<char>::s erve()'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x56b):G \Projects\Datas tructure\Queue\ main.cpp:102: undefined reference to `Queue<char>::e mpty() const'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x581):G \Projects\Datas tructure\Queue\ main.cpp:103: undefined reference to `Queue<char>::r etrieve(char&) const'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x5b0):G \Projects\Datas tructure\Queue\ main.cpp:105: undefined reference to `Queue<char>::s erve()'
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.co m> wrote in message news:dv******** **@news.cn99.co m...
Dear all,
When I use #include "queue.h", I can't link it.
The error message follows:
Linking...
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x136): In
function `main':
G:\Projects\Dat astructure\Queu e\main.cpp:16: undefined reference to
`Queue<char>::Q ueue()'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x394): In
function `Z10do_commandc R5QueueIcE':
G:\Projects\Dat astructure\Queu e\main.cpp:65: undefined reference to
`Queue<char>::r etrieve(char&) const'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x473):G: \Projects\Datas tructure\Queue\ main.cpp:83:
undefined reference to `Queue<char>::a ppend(char const&)'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x4e5):G: \Projects\Datas tructure\Queue\ main.cpp:92:
undefined reference to `Queue<char>::s erve()'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x56b):G: \Projects\Datas tructure\Queue\ main.cpp:102:
undefined reference to `Queue<char>::e mpty() const'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x581):G: \Projects\Datas tructure\Queue\ main.cpp:103:
undefined reference to `Queue<char>::r etrieve(char&) const'
G:\Projects\Dat astructure\Queu e\Debug\main.o( .text+0x5b0):G: \Projects\Datas tructure\Queue\ main.cpp:105:
undefined reference to `Queue<char>::s erve()'
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
2371
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 don't want the request that happens to trigger the need for the new board to have to pay the time cost of generating it. I set up a producer thread that does nothing but generate boards and put them into a length-two Queue (blocking). At the rate...
5
6096
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 slightly to adjust path names and also take into account I am working with a case-sensitive OS. My program is below. The sticky point is that adding (#include "util.h") seems to negate the (#include <string>) statement somehow. How can I get...
7
3550
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 way to do this in 3 steps: 1. Add in main_file.cpp
18
2633
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> Assume that this library will be used by other groups. I think the answer
2
2798
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 and use sorting, but the problem is that i will have new data enqueued very often, and the sorting will not simulate the CIRCULAR Queue. Can any one suggest a way of doing it with query, VB, or SQL?
1
3306
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 is running in a web-farm environment of multiple web servers. We have been using "Performance Monitor" to monitor the "Requests in Application Queue" counter of "ASP.NET Apps v.1.1.4322" object. We have found the following pattern.
9
6078
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: ************ HelloWorld.cpp ************* #include "stdafx.h" void main()
5
39928
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 (FIFO): The bullet in a machine gun..(you cannot fire 2 bullets at the same time) Stack (LIFO): The tennis balls in their container.. (you cannot remove 2 balls at the same time)
5
3128
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 that possible, thanks. rgs
0
8831
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.