[NEWBIE] C++ linking problems (Undefined symbols)
From: zapro (zaproheeks_at_yahoo.it)
Date: 12/27/04
- Next message: infobahn: "Re: question re: goto statement"
- Previous message: Jonathan Mcdougall: "Re: question about <memory>"
- Next in thread: Jack Klein: "Re: [NEWBIE] C++ linking problems (Undefined symbols)"
- Reply: Jack Klein: "Re: [NEWBIE] C++ linking problems (Undefined symbols)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 27 Dec 2004 03:33:57 GMT
Hi, I am learning C++ and I have a very newbie question about some
linking issues.
You can see a demostration of my problem using the code below. When I
try to build it, the compile phase completes correctly but I get the
following error on linking:
Ld /Users/newt/devel/_builds/essentialcpp/essentialcpp
cd /Users/newt/devel/tutorials_mine/essentialcpp
/usr/bin/g++-3.3 -o
/Users/newt/devel/_builds/essentialcpp/essentialcpp
-L/Users/newt/devel/_builds/essentialcpp
-F/Users/newt/devel/_builds/essentialcpp -filelist
/Users/newt/devel/_builds/essentialcpp/essentialcpp.build/LessThan_Inline_operator.build/Objects-normal/essentialcpp.LinkFileList
-lstdc++ -arch ppc -Wl,-no_arch_warnings
ld: Undefined symbols:
LessThan::operator()(int) const
The code will build if I remove the inline keyword from the definition
of the operator() or if I remove the call. I can't understand why:
anybody can turn on the light for me? Any insight would be greatly
appreciated.
I am also not sure if this is a linker bug, but since I am new to C++,
I find it difficult to believe that. I am using Apple's Xcode IDE on
Mac OS X 10.3.6 (gcc 3.3). For those of you who are familiar with
Xcode, I am using a "Deployment" build style just to be sure everything
is linked (Zerolink is disabled).
Thank you, and pardon me for the stupidity of this question.
--zapro
ps.
the code below is taken from Stan Lippman's Essential C++ book.
-------------------
//
// LessThan.h
//
#ifndef LESSTHAN_H_
#define LESSTHAN_H_
class LessThan
{
public:
LessThan(int val) : _val(val) {}
int comp_val() const { return _val; }
void comp_val(int nval){ _val = nval; }
bool operator()(int value) const;
private:
int _val;
};
#endif
//
// LessThan.cpp
//
#include "LessThan.h"
using namespace std;
inline // #### removing this will link correctly
bool LessThan::operator()(int value) const
{
return value < _val;
}
//
// main.cpp
//
#include "LessThan.h"
using namespace std;
// invoking overloaded call operator () by applying it to a class object
int main(int argc, char *argv[])
{
LessThan lt(10);
lt(5); // #### removing this will link correctly
}
- Next message: infobahn: "Re: question re: goto statement"
- Previous message: Jonathan Mcdougall: "Re: question about <memory>"
- Next in thread: Jack Klein: "Re: [NEWBIE] C++ linking problems (Undefined symbols)"
- Reply: Jack Klein: "Re: [NEWBIE] C++ linking problems (Undefined symbols)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|