Stuck with header files

D

dave6502

Newbe C++ programmer.

I am trying to bug fix a simple KDE application that uses C++. There
is a main directory with .cpp & .h files in it. I need to write some
additional code and split it up into .cpp & .h files. The code - no
problem. The splitting into ,h & .cpp is the problem. Stripping the
problem to its very bare bones I have ...

ctallowdeny.h ...
/////////////////////////////////////////////////////////////////////

class ctallowdeny
{
public:
ctallowdeny();

~ctallowdeny();
}

/////////////////////////////////////////////////////////////////////////////
ctallowdeny.cpp ...
//////////////////////////////////////////////////////////////////////////////

#include "ctallowdeny.h"
using namespace std;

ctallowdeny::ctallowdeny() {};

ctallowdeny::~ctallowdeny() {};

///////////////////////////////////////////////////////////////////////

and called from KTApp with ...

#include "ctallowdeny.h"
ctallowdeny testbed

When I make I get ...


ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x28df): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2a4d): undefined reference to
`ctallowdeny::~ctallowdeny()'
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x2b49): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2cc4): undefined reference to
`ctallowdeny::~ctallowdeny()'
collect2: ld returned 1 exit status
make[2]: *** [kcron] Error 1
make[2]: Leaving directory `/home/ubuntu/Desktop/kdeadmin-3.5.5/kcron'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ubuntu/Desktop/kdeadmin-3.5.5'
make: *** [all] Error 2
ubuntu@ubuntu-desktop:~/Desktop/kdeadmin-3.5.5$

//////////////////////////////////////////////////////////////////////

Any ideas ? - I have been stuck on this for several hours :(

Dave
 
J

Jacek Dziedzic

Newbe C++ programmer.

I am trying to bug fix a simple KDE application that uses C++. There
is a main directory with .cpp & .h files in it. I need to write some
additional code and split it up into .cpp & .h files. The code - no
problem. The splitting into ,h & .cpp is the problem. Stripping the
problem to its very bare bones I have ...

ctallowdeny.h ...
/////////////////////////////////////////////////////////////////////

class ctallowdeny
{
public:
ctallowdeny();

~ctallowdeny();
}

/////////////////////////////////////////////////////////////////////////////
ctallowdeny.cpp ...
//////////////////////////////////////////////////////////////////////////////

#include "ctallowdeny.h"
using namespace std;

ctallowdeny::ctallowdeny() {};

ctallowdeny::~ctallowdeny() {};

///////////////////////////////////////////////////////////////////////

and called from KTApp with ...

#include "ctallowdeny.h"
ctallowdeny testbed

When I make I get ...


ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x28df): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2a4d): undefined reference to
`ctallowdeny::~ctallowdeny()'
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x2b49): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2cc4): undefined reference to
`ctallowdeny::~ctallowdeny()'
collect2: ld returned 1 exit status
make[2]: *** [kcron] Error 1
make[2]: Leaving directory `/home/ubuntu/Desktop/kdeadmin-3.5.5/kcron'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ubuntu/Desktop/kdeadmin-3.5.5'
make: *** [all] Error 2
ubuntu@ubuntu-desktop:~/Desktop/kdeadmin-3.5.5$

//////////////////////////////////////////////////////////////////////

Any ideas ? - I have been stuck on this for several hours :(

Yes, a missing semicolon after the class definition in the .h file.

HTH,
- J.
 
D

dave6502

Jacek said:
Newbe C++ programmer.

I am trying to bug fix a simple KDE application that uses C++. There
is a main directory with .cpp & .h files in it. I need to write some
additional code and split it up into .cpp & .h files. The code - no
problem. The splitting into ,h & .cpp is the problem. Stripping the
problem to its very bare bones I have ...

ctallowdeny.h ...
/////////////////////////////////////////////////////////////////////

class ctallowdeny
{
public:
ctallowdeny();

~ctallowdeny();
}

/////////////////////////////////////////////////////////////////////////////
ctallowdeny.cpp ...
//////////////////////////////////////////////////////////////////////////////

#include "ctallowdeny.h"
using namespace std;

ctallowdeny::ctallowdeny() {};

ctallowdeny::~ctallowdeny() {};

///////////////////////////////////////////////////////////////////////

and called from KTApp with ...

#include "ctallowdeny.h"
ctallowdeny testbed

When I make I get ...


ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x28df): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2a4d): undefined reference to
`ctallowdeny::~ctallowdeny()'
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x2b49): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2cc4): undefined reference to
`ctallowdeny::~ctallowdeny()'
collect2: ld returned 1 exit status
make[2]: *** [kcron] Error 1
make[2]: Leaving directory `/home/ubuntu/Desktop/kdeadmin-3.5.5/kcron'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/ubuntu/Desktop/kdeadmin-3.5.5'
make: *** [all] Error 2
ubuntu@ubuntu-desktop:~/Desktop/kdeadmin-3.5.5$

//////////////////////////////////////////////////////////////////////

Any ideas ? - I have been stuck on this for several hours :(

Yes, a missing semicolon after the class definition in the .h file.

HTH,
- J.


class ctallowdeny
{
public:
ctallowdeny();

~ctallowdeny();

} ;

Same result :(

Dave
 
V

Victor Bazarov

Jacek said:
Newbe C++ programmer.

[..]
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x28df): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2a4d): undefined reference to
`ctallowdeny::~ctallowdeny()'
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x2b49): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2cc4): undefined reference to
`ctallowdeny::~ctallowdeny()'
collect2: ld returned 1 exit status
make[2]: *** [kcron] Error 1
make[2]: Leaving directory
`/home/ubuntu/Desktop/kdeadmin-3.5.5/kcron' make[1]: ***

This is off-topic here (linking and make are not part of C++
specification), but have you added your 'cpp' file to the link
command in your makefile?

V
 
D

dave6502

Victor said:
Jacek said:
(e-mail address removed) wrote:
Newbe C++ programmer.

[..]
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x28df): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2a4d): undefined reference to
`ctallowdeny::~ctallowdeny()'
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x2b49): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2cc4): undefined reference to
`ctallowdeny::~ctallowdeny()'
collect2: ld returned 1 exit status
make[2]: *** [kcron] Error 1
make[2]: Leaving directory
`/home/ubuntu/Desktop/kdeadmin-3.5.5/kcron' make[1]: ***

This is off-topic here (linking and make are not part of C++
specification), but have you added your 'cpp' file to the link
command in your makefile?

V

err ... no I haven't. This is my first time. OK I am going to do
research on the makefile

many thanks

Dave
 
R

red floyd

Newbe C++ programmer.
[redacted]

ctallowdeny.h ...
/////////////////////////////////////////////////////////////////////

class ctallowdeny
{
public:
ctallowdeny();

~ctallowdeny();
}

/////////////////////////////////////////////////////////////////////////////
ctallowdeny.cpp ...
//////////////////////////////////////////////////////////////////////////////

#include "ctallowdeny.h"
using namespace std;

ctallowdeny::ctallowdeny() {};

ctallowdeny::~ctallowdeny() {};
Not really related to the problem you're having, but lose the semicolons
on the implementation of the constructor and destructor.
 
D

dave6502

Victor said:
Jacek Dziedzic wrote:
(e-mail address removed) wrote:
Newbe C++ programmer.

[..]
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x28df): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2a4d): undefined reference to
`ctallowdeny::~ctallowdeny()'
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x2b49): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2cc4): undefined reference to
`ctallowdeny::~ctallowdeny()'
collect2: ld returned 1 exit status
make[2]: *** [kcron] Error 1
make[2]: Leaving directory
`/home/ubuntu/Desktop/kdeadmin-3.5.5/kcron' make[1]: ***

This is off-topic here (linking and make are not part of C++
specification), but have you added your 'cpp' file to the link
command in your makefile?

V

err ... no I haven't. This is my first time. OK I am going to do
research on the makefile

many thanks

Dave

Thanks guys, makefile sorted it - just soooo much to learn

Dave
 
J

James Kanze

Jacek said:
(e-mail address removed) wrote:
Newbe C++ programmer.
[..]
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x28df): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2a4d): undefined reference to
`ctallowdeny::~ctallowdeny()'
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x2b49): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2cc4): undefined reference to
`ctallowdeny::~ctallowdeny()'
collect2: ld returned 1 exit status
make[2]: *** [kcron] Error 1
make[2]: Leaving directory
`/home/ubuntu/Desktop/kdeadmin-3.5.5/kcron' make[1]: ***
This is off-topic here (linking and make are not part of C++
specification), but have you added your 'cpp' file to the link
command in your makefile?

This is getting a bit ridiculous. The exact details on how to
invoke the linker (and how to ensure that it finds the specific
object file) may not be on topic, but the fact that you link,
and that you have to include the compiled .cpp file in your
program, definitly is. (Even the standard talks about it.)
 
A

Alf P. Steinbach

* James Kanze:
This is getting a bit ridiculous. The exact details on how to
invoke the linker (and how to ensure that it finds the specific
object file) may not be on topic, but the fact that you link,
and that you have to include the compiled .cpp file in your
program, definitly is. (Even the standard talks about it.)

I agree, it would be ridiculuous if we couldn't discuss the reality of
linking, or for that matter matching C++ code to machine
characteristics. But there we have an educational problem, because the
FAQ equates clc++ topicality with what can be answered by reference to
the standard, and only that.

So, herewith, Alf's proposal for clc++ topicality, guideline for clc++
topicality police (whenever one feels like putting that uniform on):

(
* Is of general interest to C++ programmers in general

-- and --

* Is not completely environment-specific (in particular, isn't about
how to use some library which usage problem could just as well be
expressed in terms of some other language than C++),

-- or --

* Is a follow-up in a thread, with at least some C++ related content.
)

-- and --

* Does not constitute a personal attack, is not spam, etc.

Is this OK? I just poured that out of my shirtsleeve. May have missed
something.
 
V

Victor Bazarov

James said:
Jacek Dziedzic wrote:
(e-mail address removed) wrote:
Newbe C++ programmer.
[..]
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x28df): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2a4d): undefined reference to
`ctallowdeny::~ctallowdeny()'
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x2b49): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2cc4): undefined reference to
`ctallowdeny::~ctallowdeny()'
collect2: ld returned 1 exit status
make[2]: *** [kcron] Error 1
make[2]: Leaving directory
`/home/ubuntu/Desktop/kdeadmin-3.5.5/kcron' make[1]: ***
This is off-topic here (linking and make are not part of C++
specification), but have you added your 'cpp' file to the link
command in your makefile?

This is getting a bit ridiculous. The exact details on how to
invoke the linker (and how to ensure that it finds the specific
object file) may not be on topic, but the fact that you link,
and that you have to include the compiled .cpp file in your
program, definitly is. (Even the standard talks about it.)

I think you're overreacting, James (carryover from c.l.c++.m?)
It's absolutely off-topic _how_ to add a 'cpp' file to the link
command in a makefile. Don't agree? Wanna fight on that?

V
 
J

James Kanze

* James Kanze:
I agree, it would be ridiculuous if we couldn't discuss the reality of
linking, or for that matter matching C++ code to machine
characteristics. But there we have an educational problem, because the
FAQ equates clc++ topicality with what can be answered by reference to
the standard, and only that.

The charter doesn't put it in those terms. The topic here is
C++, as opposed to Microsoft Windows, or whatever. The
classical test was simple: if the answer would be the same for
all languages, but not for different platforms, it's off topic.
If the answer would be the same for all platforms, but not for
other languages, it's on topic. Here, there were aspects of
both involved. Details as to how to invoke a specific linker,
etc., are not really on topic (although there are even fairly
portable aspects of that). The fact that C++ does statically
link to an executable (in all, or almost all
implementations---the standard doesn't require it), instead of
e.g. being delivered in the form of a jar file, or whatever, is
on topic.

For me, the question seemed on topic because 1) I use exactly
the same techniques for deploying C++ programs under Solaris,
Linux and Windows, and 2) I use different techniques for Java.
In sum, the answer depends on the language, and not the
platform or the compiler. (It's a bit less clear than some
cases, of course, because there is a large family of languages
which use the same techniques: C, Ada, Fortran, etc. But still,
the problem the OP had was that the technique he used in Basic
wasn't available.)
So, herewith, Alf's proposal for clc++ topicality, guideline for clc++
topicality police (whenever one feels like putting that uniform on):
(
* Is of general interest to C++ programmers in general
-- and --
* Is not completely environment-specific (in particular, isn't about
how to use some library which usage problem could just as well be
expressed in terms of some other language than C++),
* Is a follow-up in a thread, with at least some C++ related content.
)
-- and --
* Does not constitute a personal attack, is not spam, etc.
Is this OK? I just poured that out of my shirtsleeve. May have missed
something.

It looks fine to me. There will be borderline cases, of course,
but I'm sure you're aware of that.

There's also a question in my mind about specific compiler
invocation sequences, when a de facto standard has developped.
The issue came up in another thread: in 25 years of C/C++, I've
never encountered a compiler where -I couldn't be used to
specify an include path. Now, I agree that normally,
implementation specific details of how to invoke the compiler
are off topic (except maybe as examples), but I do rather feal
some exceptions are in order: when the option is
quasi-universal, like -I, or when it is related to handling a
more general problem, things like -ffloat-store with g++, for
example (which is an aspect of the more general problem of why
floating point arithmetic doesn't give the expected results).
 
J

James Kanze

James said:
(e-mail address removed) wrote:
Jacek Dziedzic wrote:
(e-mail address removed) wrote:
Newbe C++ programmer.
[..]
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x28df): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2a4d): undefined reference to
`ctallowdeny::~ctallowdeny()'
ktapp.o: In function `KTApp::KTApp()':
ktapp.cpp:(.text+0x2b49): undefined reference to
`ctallowdeny::ctallowdeny()'
ktapp.cpp:(.text+0x2cc4): undefined reference to
`ctallowdeny::~ctallowdeny()'
collect2: ld returned 1 exit status
make[2]: *** [kcron] Error 1
make[2]: Leaving directory
`/home/ubuntu/Desktop/kdeadmin-3.5.5/kcron' make[1]: ***
This is off-topic here (linking and make are not part of C++
specification), but have you added your 'cpp' file to the link
command in your makefile?
This is getting a bit ridiculous. The exact details on how to
invoke the linker (and how to ensure that it finds the specific
object file) may not be on topic, but the fact that you link,
and that you have to include the compiled .cpp file in your
program, definitly is. (Even the standard talks about it.)
I think you're overreacting, James (carryover from c.l.c++.m?)
It's absolutely off-topic _how_ to add a 'cpp' file to the link
command in a makefile. Don't agree? Wanna fight on that?

The original question had nothing to do with makefiles, at least
not directly. How you add a source file to the link command is
obviously off topic (I use vim:)). The fact that you do have
to explicitly specify all of the object files, etc., isn't.

Note that even in the moderated group, there have been
discussions about this, with the approval of the moderators.
And the C++ standard mentions it; it's one of the phases of
compilation. So I can't see how it could possibly be off topic.
 

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,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top