[C++-sig] Embedding...

Beau Sapach beau.sapach at ualberta.ca
Wed Oct 25 23:31:41 CEST 2006


Hi everyone,

I've downloaded the CVS version of boost(following instructions from
http://www.boost.org/more/getting_started.html#CVS) and built using bjam.

I built with the following command:

	C:\boost\libs\python\build>bjam -sPYTHON_VERSION=2.5
-sPYTHON_ROOT=c:\python25 -sPYTHON_LIB_PATH=c:\python25\libs -sTOOLS=vc-7_1
-sBUILD=debug

I then copied all the resulting lib and dll files (from bin-stage) to
c:\boost\dll which is on my system's PATH and is also listed in visual
studio under "library files".  I've also explicitly added
boost_python_debug.lib and python25.lib to my linker command line. My test
program compiles fine but when it comes to linking it says:

	boostapp error LNK2019: unresolved external symbol "class
boost::python::api::object __cdecl boost::python::exec(class
boost::python::str,class boost::python::api::object,class
boost::python::api::object)"
(?exec at python@boost@@YA?AVobject at api@12 at Vstr@12 at V3412@1 at Z) referenced in
function "public: void __thiscall CboostappDlg::OnBnClickedButton1(void)"
(?OnBnClickedButton1 at CboostappDlg@@QAEXXZ)

	boostapp error LNK2019: unresolved external symbol "class
boost::python::api::object __cdecl boost::python::import(class
boost::python::str)" (?import at python@boost@@YA?AVobject at api@12 at Vstr@12@@Z)
referenced in function "public: void __thiscall
CboostappDlg::OnBnClickedButton1(void)"
(?OnBnClickedButton1 at CboostappDlg@@QAEXXZ)


And the offending C++ code:

void CboostappDlg::OnBnClickedButton1()
{
	namespace bpl = boost::python;
	bpl::object main = bpl::import("__main__");
	bpl::object global(main.attr("__dict__"));

	//load the module
	bpl::object result = bpl::exec("import hello\n", global, global);

	//get a hold of the class
	bpl::object hello_class = global["hello.world"];

	//instantiate the class
	bpl::object hello_instance = hello_class();

	// Inject it into environment.
	global["hello_instance"] = hello_instance;

	// And run a script with it.
	result = bpl::exec("hello.greet()\n", global, global); 

}

Does this mean that exec and import are not in my library or that I'm
somehow calling them in such a way that the compiler doesn't complain but
the linker does?

Beau

-----Original Message-----
From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On
Behalf Of Stefan Seefeld
Sent: Wednesday, October 25, 2006 1:54 PM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Embedding...

Beau Sapach wrote:
> Thanks again for your help Stefan!
> 
> I'm trying to compile a simple example based on your code but I'm getting
> link errors, unresolved externals for both exec and import functions.
Does
> this mean that they are not built into my boost_python.lib?  I've
downloaded
> and built the CVS version using the visual studio .dsw file.  Now I'm
> guessing it's not up to date?

I have no idea about what the dsw file contains; I have never touched it.
The canonical way to build boost is using bjam. :-)

Regards,
		Stefan


-- 

      ...ich hab' noch einen Koffer in Berlin...
_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig





More information about the Cplusplus-sig mailing list