Hi,
Im running Gentoo over here and I installed boost from gentoo's
portage tree. I then tried to compile a program that included
boost/python.hpp. It completely failed:
/usr/include/boost/python/detail/wrap_python.hpp:41:24: patchlevel.h: No
such file or directory
/usr/include/boost/python/detail/wrap_python.hpp:121:21: Python.h: No
such file or directory
Looks like I don't have some local variables set to tell things im
trying to build where to find these files. Im compiling this absurdly
simple program (pretty much just an #include
Noah Schwartz wrote:
Hi,
Im running Gentoo over here and I installed boost from gentoo's portage tree. I then tried to compile a program that included boost/python.hpp. It completely failed:
/usr/include/boost/python/detail/wrap_python.hpp:41:24: patchlevel.h: No such file or directory /usr/include/boost/python/detail/wrap_python.hpp:121:21: Python.h: No such file or directory
Did you read the docs? Especially http://boost.org/libs/python/doc/tutorial/doc/html/python/hello.html, which says We shall use the build tool that comes bundled with every boost distribution: bjam. ...... Experience shows that 90% of the "I can't build Boost.Python" problems come from people who had to use a different tool. ;-) Maybe you can try with bjam?
Looks like I don't have some local variables set to tell things im trying to build where to find these files. Im compiling this absurdly simple program (pretty much just an #include
and a main that returns 0) using a Makefile. Do I need to export some paths?
You need to pass include path to Python to g++. This is something like /usr/include/python2.3/ - Volodya
Vladimir Prus wrote:
Noah Schwartz wrote:
Hi,
Im running Gentoo over here and I installed boost from gentoo's portage tree. I then tried to compile a program that included boost/python.hpp. It completely failed:
/usr/include/boost/python/detail/wrap_python.hpp:41:24: patchlevel.h: No such file or directory /usr/include/boost/python/detail/wrap_python.hpp:121:21: Python.h: No such file or directory
Did you read the docs? Especially http://boost.org/libs/python/doc/tutorial/doc/html/python/hello.html, which says
We shall use the build tool that comes bundled with every boost distribution: bjam. ...... Experience shows that 90% of the "I can't build Boost.Python" problems come from people who had to use a different tool.
;-) Maybe you can try with bjam?
Looks like I don't have some local variables set to tell things im trying to build where to find these files. Im compiling this absurdly simple program (pretty much just an #include
and a main that returns 0) using a Makefile. Do I need to export some paths? You need to pass include path to Python to g++. This is something like /usr/include/python2.3/
- Volodya
so youre saying that if i want to use boost i cant realistically use mak to compil my projects?
Hi, I am new to C++ and I am converting a Java project to C++. Here is the error I got: g++ main.cpp /tmp/ccraQoXW.o(.gnu.linkonce.t._ZN12OperatorTypeC1ERKS_+0x8): In function `OperatorType::OperatorType[in-charge](OperatorType const&)': : undefined reference to `vtable for OperatorType' /tmp/ccraQoXW.o(.gnu.linkonce.t._ZN12OperatorTypeC2Ev+0x8): In function `OperatorType::OperatorType[not-in-charge]()': : undefined reference to `vtable for OperatorType' /tmp/ccraQoXW.o(.gnu.linkonce.r._ZTI17BasicOperatorType+0x8): undefined reference to `typeinfo for OperatorType' /tmp/ccraQoXW.o(.gnu.linkonce.r._ZTI13BasicOperator+0x8): undefined reference to `typeinfo for Operator' collect2: ld returned 1 exit status The source file is attached as main.cpp. I guess this is an inheritence/polymorphism/runtime type kind of problem, but I don't know how to make it right.
On Wed, 2005-02-09 at 20:02 -0700, Welson Sun wrote:
Hi,
I am new to C++ and I am converting a Java project to C++. Here is the error I got:
I believe I see your problem here. You want OperatorType to be a pure virtual class. Well you cannot use a class that has a pure virtual function you cannot create an object of that type. The purpose of a class with pure virtual functions is to be a base class like you are using with OperatorType. So we need to change your code ignore to make it say that OperatorType is a base class which BasicOperatorType inherits from: <BEFORE> class OperatorType { public: virtual string getMnemonic(void); }; <AFTER> class OperatorType { public: virtual string getMnemonic(void) = 0; }; Quote from: http://www.firststep.com.au/jlc/javacc/virtual.html While we're on the subject of virtual functions ... Java, like C++, supports pure virtual, or abstract, functions (Base class functions which must be defined in derived classes). In C++, the cryptic notation "=0" is used at the end of the function declaration. Java uses the more sensible abstract keyword. If your class has any abstract member functions, Java also insists that you declare the class as abstract. This advertises that it's an abstract class (In C++, you have to look through the member functions and notice that there's at least one pure virtual function). So we repeat this change for class Operator as well. So we are not done yet changing your code. We need to change the OperatorType and Operator declarations to be pointer types, e.g. OperatorType*. Since you cannot define a Operator type because a function is declared pure virtual you can still use it as a pointer. What you are saying is that the pointer is of type Operator but in fact is a class that supports the Operator interface. <BEFORE> // NOTE: This is what the class Operator would look like after making // the change described above. Its function getOperatorType is // now a pure virtual function which anything wanting to support // the Operator interface must define. class Operator{ public: virtual OperatorType getOperatorType() = 0; }; <AFTER> class Operator{ public: virtual OperatorType* getOperatorType() = 0; }; So anything wanting to support the Operator interface must have a function called getOperatorType that returns a pointer to a class which supports the OperatorType interface. Does that make sense? The final step after making these changes is to use these new classes. static OperatorType* portType = new BasicOperatorType("Port"); Here is a variable that is a OperatorType pointer called portType. Since BasicOperatorType supports the OperatorType we can assign a pointer on the heap of type BasicOperatorType to the portType variable. The only operations supported on portType is the getMnemonic() function. I would recommend two books: C++ Primer Plus - 4th Edition (or latest) from Stephen Prata. The C++ Programming Language (Special 3rd Edition) by Bjarne Stroustrup. I use the first one but a good friend of my likes the other. Both are good guides for getting into the C++ programming language. Cheers! Stephen
Thanks guys, I now understand the problem and it is fixed. It is harder than I have expected converting from Java to C++, expecially when C++ has more features than Java. -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Stephen torri Sent: Wednesday, February 09, 2005 9:03 PM To: boost Subject: Re: [Boost-users] Probably a C++ problem On Wed, 2005-02-09 at 20:02 -0700, Welson Sun wrote:
Hi,
I am new to C++ and I am converting a Java project to C++. Here is the error I got:
I believe I see your problem here. You want OperatorType to be a pure virtual class. Well you cannot use a class that has a pure virtual function you cannot create an object of that type. The purpose of a class with pure virtual functions is to be a base class like you are using with OperatorType. So we need to change your code ignore to make it say that OperatorType is a base class which BasicOperatorType inherits from: <BEFORE> class OperatorType { public: virtual string getMnemonic(void); }; <AFTER> class OperatorType { public: virtual string getMnemonic(void) = 0; }; Quote from: http://www.firststep.com.au/jlc/javacc/virtual.html While we're on the subject of virtual functions ... Java, like C++, supports pure virtual, or abstract, functions (Base class functions which must be defined in derived classes). In C++, the cryptic notation "=0" is used at the end of the function declaration. Java uses the more sensible abstract keyword. If your class has any abstract member functions, Java also insists that you declare the class as abstract. This advertises that it's an abstract class (In C++, you have to look through the member functions and notice that there's at least one pure virtual function). So we repeat this change for class Operator as well. So we are not done yet changing your code. We need to change the OperatorType and Operator declarations to be pointer types, e.g. OperatorType*. Since you cannot define a Operator type because a function is declared pure virtual you can still use it as a pointer. What you are saying is that the pointer is of type Operator but in fact is a class that supports the Operator interface. <BEFORE> // NOTE: This is what the class Operator would look like after making // the change described above. Its function getOperatorType is // now a pure virtual function which anything wanting to support // the Operator interface must define. class Operator{ public: virtual OperatorType getOperatorType() = 0; }; <AFTER> class Operator{ public: virtual OperatorType* getOperatorType() = 0; }; So anything wanting to support the Operator interface must have a function called getOperatorType that returns a pointer to a class which supports the OperatorType interface. Does that make sense? The final step after making these changes is to use these new classes. static OperatorType* portType = new BasicOperatorType("Port"); Here is a variable that is a OperatorType pointer called portType. Since BasicOperatorType supports the OperatorType we can assign a pointer on the heap of type BasicOperatorType to the portType variable. The only operations supported on portType is the getMnemonic() function. I would recommend two books: C++ Primer Plus - 4th Edition (or latest) from Stephen Prata. The C++ Programming Language (Special 3rd Edition) by Bjarne Stroustrup. I use the first one but a good friend of my likes the other. Both are good guides for getting into the C++ programming language. Cheers! Stephen _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi, here is another problem I met:
$ g++ main.cpp
main.cpp: In member function `void
schedule_vertex_writer<Graph>::operator()(std::ostream&, const Vertex&)
const [with Vertex = unsigned int, Graph =
boost::adjacency_list
Well, I found out that this is not a problem related to inheritence nor
polymorphism, it is a problem with the BGL
1. Even if I make BasicOperator not inherit from Operator, the problem is
the same.
Here is the modified BasicOperator:
class BasicOperator /* : public Operator */{
public:
BasicOperator() {};
BasicOperator(OperatorType* type) : _type(type) {toString =
_type->getMnemonic();};
BasicOperator(OperatorType* type, string cust) : _type(type), _cust(cust)
{toString = _type->getMnemonic() + "&" + _cust;};
OperatorType* getOperatorType() { return _type; }
string toString() { return toString; }
string toString;
private:
OperatorType* _type;
string _cust;
};
And the vertex property writer is:
void operator()(std::ostream& out, const Vertex& v) const {
out << "[label=\""
<< "(" << g[v].toString() << ")"
<< "\"]";
}
The error is:
main.cpp:52: error: passing `const BasicOperator' as `this' argument of `
std::string BasicOperator::toString()' discards qualifiers
So it looks like that the problem is related to the "const" BasicOperator I
passed into std::string BasicOperator::toString(). How can I fix this? Which
means if the property of a vertex is a Class, how can I call its member
function in the vertex writer?
2. If I changes the vertex property writer as:
void operator()(std::ostream& out, const Vertex& v) const {
out << "[label=\""
<< "(" << g[v].toString << ")"
<< "\"]";
}
Everything is OK. Which mean in the vertex property writer, I can access the
data member without any problem, but I cannot access the member function.
-----Original Message-----
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Welson Sun
Sent: Thursday, February 10, 2005 4:42 PM
To: boost-users@lists.boost.org
Subject: [Boost-users] Another C++ inheritence/polymorphism problem
Hi, here is another problem I met:
$ g++ main.cpp
main.cpp: In member function `void
schedule_vertex_writer<Graph>::operator()(std::ostream&, const Vertex&)
const [with Vertex = unsigned int, Graph =
boost::adjacency_list
On Feb 10, 2005, at 10:25 PM, Welson Sun wrote:
Well, I found out that this is not a problem related to inheritence nor polymorphism, it is a problem with the BGL
1. Even if I make BasicOperator not inherit from Operator, the problem is the same. Here is the modified BasicOperator:
class BasicOperator /* : public Operator */{ public: BasicOperator() {}; BasicOperator(OperatorType* type) : _type(type) {toString = _type->getMnemonic();}; BasicOperator(OperatorType* type, string cust) : _type(type), _cust(cust) {toString = _type->getMnemonic() + "&" + _cust;}; OperatorType* getOperatorType() { return _type; } string toString() { return toString; } string toString; private: OperatorType* _type; string _cust; };
And the vertex property writer is: void operator()(std::ostream& out, const Vertex& v) const { out << "[label=\"" << "(" << g[v].toString() << ")" << "\"]"; }
The error is: main.cpp:52: error: passing `const BasicOperator' as `this' argument of ` std::string BasicOperator::toString()' discards qualifiers
Looking at the code you previously posted and mapping that to what you've written here, here's what happens: schedule_vertex_writer stores a _copy_ of the graph (called g) inside it. Since operator() is marked "const", g[v] returns a reference to a const BasicOperator. But, when you call toString(), it is not marked const, so you get the error above. I have two suggestions: (1) Pass and store the graph g as a "const Graph&" in schedule_vertex_writer. Copying graphs can be really expensive. (2) Make toString() const. If you absolutely cannot do this, then you'll need to store a non-const reference to the graph instead of a const one.
So it looks like that the problem is related to the "const" BasicOperator I passed into std::string BasicOperator::toString(). How can I fix this? Which means if the property of a vertex is a Class, how can I call its member function in the vertex writer?
2. If I changes the vertex property writer as: void operator()(std::ostream& out, const Vertex& v) const { out << "[label=\"" << "(" << g[v].toString << ")" << "\"]"; } Everything is OK. Which mean in the vertex property writer, I can access the data member without any problem, but I cannot access the member function.
Right, because data members can be accessed irrespective of the cv-qualifiers on the object type. You'll just get a const std::string& back. Doug
Yeah, if I change the vertex property writer to be: void operator()(std::ostream& out, Vertex& v) It works fine. -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Douglas Gregor Sent: Friday, February 11, 2005 6:23 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] BGL problem,originally [Another C++ inheritence/polymorphism problem] On Feb 10, 2005, at 10:25 PM, Welson Sun wrote:
Well, I found out that this is not a problem related to inheritence nor polymorphism, it is a problem with the BGL
1. Even if I make BasicOperator not inherit from Operator, the problem is the same. Here is the modified BasicOperator:
class BasicOperator /* : public Operator */{ public: BasicOperator() {}; BasicOperator(OperatorType* type) : _type(type) {toString = _type->getMnemonic();}; BasicOperator(OperatorType* type, string cust) : _type(type), _cust(cust) {toString = _type->getMnemonic() + "&" + _cust;}; OperatorType* getOperatorType() { return _type; } string toString() { return toString; } string toString; private: OperatorType* _type; string _cust; };
And the vertex property writer is: void operator()(std::ostream& out, const Vertex& v) const { out << "[label=\"" << "(" << g[v].toString() << ")" << "\"]"; }
The error is: main.cpp:52: error: passing `const BasicOperator' as `this' argument of ` std::string BasicOperator::toString()' discards qualifiers
Looking at the code you previously posted and mapping that to what you've written here, here's what happens: schedule_vertex_writer stores a _copy_ of the graph (called g) inside it. Since operator() is marked "const", g[v] returns a reference to a const BasicOperator. But, when you call toString(), it is not marked const, so you get the error above. I have two suggestions: (1) Pass and store the graph g as a "const Graph&" in schedule_vertex_writer. Copying graphs can be really expensive. (2) Make toString() const. If you absolutely cannot do this, then you'll need to store a non-const reference to the graph instead of a const one.
So it looks like that the problem is related to the "const" BasicOperator I passed into std::string BasicOperator::toString(). How can I fix this? Which means if the property of a vertex is a Class, how can I call its member function in the vertex writer?
2. If I changes the vertex property writer as: void operator()(std::ostream& out, const Vertex& v) const { out << "[label=\"" << "(" << g[v].toString << ")" << "\"]"; } Everything is OK. Which mean in the vertex property writer, I can access the data member without any problem, but I cannot access the member function.
Right, because data members can be accessed irrespective of the cv-qualifiers on the object type. You'll just get a const std::string& back. Doug _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Now another question arises:
The vertex property writer is working, but if I add the edge property
writer, it compiles error again:
$ g++ main.cpp
/usr/local/include/boost/graph/graphviz.hpp: In function `void
boost::write_graphviz(std::ostream&, const Graph&,
VertexPropertiesWriter,
EdgePropertiesWriter, GraphPropertiesWriter) [with Graph =
boost::adjacency_list
Well, I found out that this is not a problem related to inheritence nor polymorphism, it is a problem with the BGL
1. Even if I make BasicOperator not inherit from Operator, the problem is the same. Here is the modified BasicOperator:
class BasicOperator /* : public Operator */{ public: BasicOperator() {}; BasicOperator(OperatorType* type) : _type(type) {toString = _type->getMnemonic();}; BasicOperator(OperatorType* type, string cust) : _type(type), _cust(cust) {toString = _type->getMnemonic() + "&" + _cust;}; OperatorType* getOperatorType() { return _type; } string toString() { return toString; } string toString; private: OperatorType* _type; string _cust; };
And the vertex property writer is: void operator()(std::ostream& out, const Vertex& v) const { out << "[label=\"" << "(" << g[v].toString() << ")" << "\"]"; }
The error is: main.cpp:52: error: passing `const BasicOperator' as `this' argument of ` std::string BasicOperator::toString()' discards qualifiers
Looking at the code you previously posted and mapping that to what you've written here, here's what happens: schedule_vertex_writer stores a _copy_ of the graph (called g) inside it. Since operator() is marked "const", g[v] returns a reference to a const BasicOperator. But, when you call toString(), it is not marked const, so you get the error above. I have two suggestions: (1) Pass and store the graph g as a "const Graph&" in schedule_vertex_writer. Copying graphs can be really expensive. (2) Make toString() const. If you absolutely cannot do this, then you'll need to store a non-const reference to the graph instead of a const one.
So it looks like that the problem is related to the "const" BasicOperator I passed into std::string BasicOperator::toString(). How can I fix this? Which means if the property of a vertex is a Class, how can I call its member function in the vertex writer?
2. If I changes the vertex property writer as: void operator()(std::ostream& out, const Vertex& v) const { out << "[label=\"" << "(" << g[v].toString << ")" << "\"]"; } Everything is OK. Which mean in the vertex property writer, I can access the data member without any problem, but I cannot access the member function.
Right, because data members can be accessed irrespective of the cv-qualifiers on the object type. You'll just get a const std::string& back. Doug _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Feb 11, 2005, at 6:00 PM, Welson Sun wrote:
template <typename Vertex> void operator()(std::ostream& out, Vertex& v) { out << "[label=\"" << g[v].toString() << "\"]"; [snip] template <typename Edge> void operator()(std::ostream& out, Edge& v) { out << "[label=\"" << "E" << "\"]"; }
I think it's a problem with the reference... typically, you just accept vertex and edge descriptors by-value (not by-reference), because they're small and cheap to copy. So the second operator() would start with: template<typename Edge> void operator()(std::ostream& out, Edge v) { Doug
Thanks, you are right. Now both the vertex property writer and edge property writer works. But I don't understand why "reference" will cause this problem? Isn't it just an alias of an object? -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Douglas Gregor Sent: Friday, February 11, 2005 8:49 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] BGL problem,originally [Another C++inheritence/polymorphism problem] On Feb 11, 2005, at 6:00 PM, Welson Sun wrote:
template <typename Vertex> void operator()(std::ostream& out, Vertex& v) { out << "[label=\"" << g[v].toString() << "\"]"; [snip] template <typename Edge> void operator()(std::ostream& out, Edge& v) { out << "[label=\"" << "E" << "\"]"; }
I think it's a problem with the reference... typically, you just accept vertex and edge descriptors by-value (not by-reference), because they're small and cheap to copy. So the second operator() would start with: template<typename Edge> void operator()(std::ostream& out, Edge v) { Doug _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Feb 12, 2005, at 8:48 PM, Welson Sun wrote:
Thanks, you are right. Now both the vertex property writer and edge property writer works.
Great!
But I don't understand why "reference" will cause this problem? Isn't it just an alias of an object?
It's a C++ quirk... when you have a temporary value, you can't pass it to a non-const reference. The intent is to help you avoid accidentally making changes to a temporary that will never be seen elsewhere, but sometimes it's a little weird. Doug
participants (6)
-
Bill Lear
-
Douglas Gregor
-
Noah Schwartz
-
Stephen torri
-
Vladimir Prus
-
Welson Sun