Skip to main content
gamedev.net
🔒 Locked 🤖 Godot

boost::python troubles

Started by telmarc 3 replies 1.3k views
Original Post
telmarc
telmarc
So i've been playing with boost::python and for the most part its working great. But when i try to expose a class with a virtual function, everything falls apart. I get an "unresolved external symbol" when i use get_override(). I'm linking with boost_python_debug.lib so I can't figure out why linker can't find it. Here's the code that's breaking and the specific error i'm getting.

#include <string>
#include <iostream>

#include <boost/python.hpp>
using namespace boost::python;


class MyClass
{
public:
	MyClass() {}
	virtual ~MyClass() {}

	virtual void Print() = 0;
};

struct MyClassWrapper : MyClass, wrapper<MyClass>
{
	void Print()
	{
		this->get_override("Print")();
	}
};


BOOST_PYTHON_MODULE(pythonTest)
{
	class_<MyClassWrapper, boost::noncopyable>("MyClass")
		.def("Print", pure_virtual(&MyClass::Print));
}

the error message:

error LNK2019: unresolved external symbol "__declspec(dllimport) protected: class boost::python::override __thiscall boost::python::detail::wrapper_base::get_override(char const *,struct _typeobject *)const " (__imp_?get_override@wrapper_base@detail@python@boost@@IBE?AVoverride@34@PBDPAU_typeobject@@@Z) referenced in function "protected: class boost::python::override __thiscall boost::python::wrapper<class MyClass>::get_override(char const *)const " (?get_override@?$wrapper@VMyClass@@@python@boost@@IBE?AVoverride@23@PBD@Z)

It acts like i'm not linking the boost::python lib, but i am. What else could I be missing? Oh, and i'm trying to build this with visual studio.net 2003. somebody save my sanity
Fruny
Fruny
Did you enable RTTI in your project settings?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
SiCrane
SiCrane
Which version of boost are you using and did you use bjam to build the boost::python library?
telmarc
telmarc
yes, i did enable RTTI.

I'm using 1.32.0 and i used the included vs project to build the boost::python library. I would imagine the vs proj would produce the same result as bjam, but should i rebuild the library with bjam anyway?

and for the sake of being thorough, here's the compiler and linker commandline my project is using (copied from the build log).

Creating temporary file "d:\projects\pythonTest\Debug\RSP000056.rsp" with contents
[
/Od /I "D:\boost\boost_1_32_0" /I "D:\Python24\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "PYTHONTEST_EXPORTS" /D "_WINDLL" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /GS /GR /Yu"stdafx.h" /Fp"Debug/pythonTest.pch" /Fo"Debug/" /Fd"Debug/vc70.pdb" /W3 /c /Wp64 /Zi /TP
pythonTest.cpp
]
Creating command line "cl.exe @d:\projects\pythonTest\Debug\RSP000056.rsp /nologo"
Creating temporary file "d:\projects\pythonTest\Debug\RSP000057.rsp" with contents
[
/OUT:"Debug/pythonTest.dll" /INCREMENTAL:NO /NOLOGO /LIBPATH:"D:\Python24\libs" /DLL /DEBUG /PDB:"Debug/pythonTest.pdb" /SUBSYSTEM:WINDOWS /IMPLIB:"Debug/pythonTest.lib" /MACHINE:IX86 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib "\boost\boost_1_32_0\libs\python\build\bin-stage\boost_python_debug.lib"
Debug\stdafx.obj
Debug\pythonTest.obj
]
Creating command line "link.exe @d:\projects\pythonTest\Debug\RSP000057.rsp"
telmarc
telmarc
Ok, I got it to build. All it took was rebuilding the library using bjam. Apparently the visual studio project is out of date and/or broken. I suppose the fact it was a vc6 project should have tipped me off.

Thanks for the help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.