Sory i totaly forgot to add error messages...
obj\Debug\main.o||In function `main': |
C:\Documents and Settings\PJani\Desktop\SandBox\test_boost_py\main.cpp|14|undefined reference to `_imp___ZN5boost6python6importENS0_3strE'|
C:\Documents and Settings\PJani\Desktop\SandBox\test_boost_py\main.cpp|20|undefined reference to `_imp___ZN5boost6python4execENS0_3strENS0_3api6objectES3_'|
obj\Debug\main.o||In function `ZN5boost6python3api9slice_nilD1Ev': |
)]+0x14)||undefined reference to `_imp___ZN5boost6python6detail8str_baseC2EPKc'|
)]+0x1c)||undefined reference to `_imp___ZN5boost6python3api7getattrERKNS1_6objectEPKc'|
||=== Build finished: 4 errors, 0 warnings ===|
And this the code
#include <boost/python.hpp>
#include <iostream>
using namespace std;
namespace python = boost::python;
int main(){
Py_Initialize();
python::object l;
python::object main_module = python::import("__main__");
python::object main_namespace = main_module.attr("__dict__");
python::object ignored = python::exec("hello = file('hello.txt', 'w')\n"
"hello.write('Hello world!')\n"
"hello.close()",
main_namespace);
return 0;
}
And this library was added by absolute path to codeblocks. Boost was build with mingw.
Please turn on Full Compiler Logging per
http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
And, post the Build Log to help me decide where error is.
Note: The Code::Blocks IDE does not always work well with absolute path to library.
It is better to put the path to Library in Linker search directory and the Library name in link library list.
But, this might be an Compiler Setup issue.
I am not sure how to set the Compiler up to use Boost Libraries.
And, http://wiki.codeblocks.org/index.php?title=BoostWindowsQuickRef does not do it the way I think is correct; but, I have never used Boost Libraries before.
Tim S
Note to Self:
Added following line to user-config.jam because my Python is in folder C:\Apps\Python26
using python : 2.6 : C:\\Apps\\Python26 ;
Made some test code that works OK for me.
Note: I am using MinGW GCC 4.4 DW2 for my testing; it gave error messages when it crashed; not, like MinGW 3.4.5.
Tim S
#include <iostream>
#include <boost/python.hpp>
namespace python = boost::python;
int main(){
Py_Initialize();
python::object main_module = python::import("__main__");
python::object global = main_module.attr("__dict__");
python::object result = python::exec(
"def greet(): \n"
" return 'Hello from Python!' \n",
global, global
);
// Create a reference to it.
python::object greet = global["greet"];
// Call it.
std::string message = python::extract<std::string>(greet());
std::cout << message << std::endl;
return 0;
}
Snippet of my Build Log for you to compare with yours.
Note: I renamed "boost_python-mgw44-mt-1_39.lib" to "libboost_python-mgw44-mt-1_39.a" and used "boost_python-mgw44-mt-1_39" in the library name.
mingw32-g++.exe -Wall -fexceptions -O2 -fno-strict-aliasing -IC:\Apps\Python26\include -IC:\GreenApps\MinGW_Boost\include\boost-1_39 -IC:\GreenApps\MinGW_Boost\include -c C:\SourceCode\Projects\IDEs\CodeBlocks\Projects\BoostTest\main.cpp -o obj\Release\main.o
mingw32-g++.exe -LC:\Apps\Python26\libs -LC:\GreenApps\MinGW_Boost\lib -o bin\Release\BoostTest.exe obj\Release\main.o -s -lpython26 -lboost_python-mgw44-mt-1_39
I used multiple sites for directions here some of them will add them as I find them.
http://www.boost.org/doc/libs/1_35_0/more/getting_started/windows.html
The two bjam commands from the batch file below; I found out by trial and error that mixing --with-XXX ans --without-XXX did not work.
IIRC I used --with-python or --without-mpi to build python; been to long for me to be sure.
bjam -q -d0 --with-graph --prefix="%_MINGWBASEFOLDER%" --build-dir=C:\temp\BoostTmp threading=multi variant=release link=shared toolset=gcc install
REM bjam -q -d0 --without-mpi --prefix="%_MINGWBASEFOLDER%" --build-dir=C:\temp\BoostTmp threading=multi variant=debug link=shared toolset=gcc install
Found my batch file I used to build boost
build-boost.bat
SET _MINGWBASEFOLDER=C:\GreenApps\MinGW_Boost
SET PATH=%_MINGWBASEFOLDER%\bin;%PATH%
cd C:\SourceCode\Libraries\Boost\boost_1_39_0
REM SET EXPAT_INCLUDE=%_MINGWBASEFOLDER%
REM SET EXPAT_LIBPATH=%_MINGWBASEFOLDER%
REM
REM Change file user-config.jam by adding the line, without quotes,
REM "using python : 2.6 : C:\\Apps\\Python26 ;" to it.
REM
REM bjam option info
REM -d+2 Show commands as they are executed
REM -d0 Supress all informational messages
REM -q Stop at first error
REM --debug-configuration Diagnose configuration
REM bjam troubleshoot with "-q -d+2 --debug-configuration"
REM bjam normal build with "-q -d0"
REM
REM Clean
REM
REM bjam --clean -d0 --without-mpi --prefix="%_MINGWBASEFOLDER%" --build-dir=C:\temp\BoostTmp threading=multi variant=release link=shared toolset=gcc install
REM bjam --clean -d0 --without-mpi --prefix="%_MINGWBASEFOLDER%" --build-dir=C:\temp\BoostTmp threading=multi variant=debug link=shared toolset=gcc install
REM PAUSE
REM
REM Build
REM
bjam -q -d0 --with-graph --prefix="%_MINGWBASEFOLDER%" --build-dir=C:\temp\BoostTmp threading=multi variant=release link=shared toolset=gcc install
REM bjam -q -d0 --without-mpi --prefix="%_MINGWBASEFOLDER%" --build-dir=C:\temp\BoostTmp threading=multi variant=debug link=shared toolset=gcc install
PAUSE
goto _end
CD %_MINGWBASEFOLDER%\lib
copy boost_date_time-mgw44-mt-1_39.lib libboost_date_time-mgw44-mt-1_39.a
copy boost_date_time-mgw44-mt-d-1_39.lib libboost_date_time-mgw44-mt-d-1_39.a
copy boost_date_time-mgw44-mt-d.lib libboost_date_time-mgw44-mt-d.a
copy boost_date_time-mgw44-mt.lib libboost_date_time-mgw44-mt.a
copy boost_filesystem-mgw44-mt-1_39.lib libboost_filesystem-mgw44-mt-1_39.a
copy boost_filesystem-mgw44-mt-d-1_39.lib libboost_filesystem-mgw44-mt-d-1_39.a
copy boost_filesystem-mgw44-mt-d.lib libboost_filesystem-mgw44-mt-d.a
copy boost_filesystem-mgw44-mt.lib libboost_filesystem-mgw44-mt.a
copy boost_graph-mgw44-mt-1_39.lib libboost_graph-mgw44-mt-1_39.a
copy boost_graph-mgw44-mt-d-1_39.lib libboost_graph-mgw44-mt-d-1_39.a
copy boost_graph-mgw44-mt-d.lib libboost_graph-mgw44-mt-d.a
copy boost_graph-mgw44-mt.lib libboost_graph-mgw44-mt.a
copy boost_iostreams-mgw44-mt-1_39.lib libboost_iostreams-mgw44-mt-1_39.a
copy boost_iostreams-mgw44-mt-d-1_39.lib libboost_iostreams-mgw44-mt-d-1_39.a
copy boost_iostreams-mgw44-mt-d.lib libboost_iostreams-mgw44-mt-d.a
copy boost_iostreams-mgw44-mt.lib libboost_iostreams-mgw44-mt.a
copy boost_math_c99-mgw44-mt-1_39.lib libboost_math_c99-mgw44-mt-1_39.a
copy boost_math_c99-mgw44-mt-d-1_39.lib libboost_math_c99-mgw44-mt-d-1_39.a
copy boost_math_c99-mgw44-mt-d.lib libboost_math_c99-mgw44-mt-d.a
copy boost_math_c99-mgw44-mt.lib libboost_math_c99-mgw44-mt.a
copy boost_math_c99f-mgw44-mt-1_39.lib libboost_math_c99f-mgw44-mt-1_39.a
copy boost_math_c99f-mgw44-mt-d-1_39.lib libboost_math_c99f-mgw44-mt-d-1_39.a
copy boost_math_c99f-mgw44-mt-d.lib libboost_math_c99f-mgw44-mt-d.a
copy boost_math_c99f-mgw44-mt.lib libboost_math_c99f-mgw44-mt.a
copy boost_math_c99l-mgw44-mt-1_39.lib libboost_math_c99l-mgw44-mt-1_39.a
copy boost_math_c99l-mgw44-mt-d-1_39.lib libboost_math_c99l-mgw44-mt-d-1_39.a
copy boost_math_c99l-mgw44-mt-d.lib libboost_math_c99l-mgw44-mt-d.a
copy boost_math_c99l-mgw44-mt.lib libboost_math_c99l-mgw44-mt.a
copy boost_math_tr1-mgw44-mt-1_39.lib libboost_math_tr1-mgw44-mt-1_39.a
copy boost_math_tr1-mgw44-mt-d-1_39.lib libboost_math_tr1-mgw44-mt-d-1_39.a
copy boost_math_tr1-mgw44-mt-d.lib libboost_math_tr1-mgw44-mt-d.a
copy boost_math_tr1-mgw44-mt.lib libboost_math_tr1-mgw44-mt.a
copy boost_math_tr1f-mgw44-mt-1_39.lib libboost_math_tr1f-mgw44-mt-1_39.a
copy boost_math_tr1f-mgw44-mt-d-1_39.lib libboost_math_tr1f-mgw44-mt-d-1_39.a
copy boost_math_tr1f-mgw44-mt-d.lib libboost_math_tr1f-mgw44-mt-d.a
copy boost_math_tr1f-mgw44-mt.lib libboost_math_tr1f-mgw44-mt.a
copy boost_math_tr1l-mgw44-mt-1_39.lib libboost_math_tr1l-mgw44-mt-1_39.a
copy boost_math_tr1l-mgw44-mt-d-1_39.lib libboost_math_tr1l-mgw44-mt-d-1_39.a
copy boost_math_tr1l-mgw44-mt-d.lib libboost_math_tr1l-mgw44-mt-d.a
copy boost_math_tr1l-mgw44-mt.lib libboost_math_tr1l-mgw44-mt.a
copy boost_prg_exec_monitor-mgw44-mt-1_39.lib libboost_prg_exec_monitor-mgw44-mt-1_39.a
copy boost_prg_exec_monitor-mgw44-mt-d-1_39.lib libboost_prg_exec_monitor-mgw44-mt-d-1_39.a
copy boost_prg_exec_monitor-mgw44-mt-d.lib libboost_prg_exec_monitor-mgw44-mt-d.a
copy boost_prg_exec_monitor-mgw44-mt.lib libboost_prg_exec_monitor-mgw44-mt.a
copy boost_program_options-mgw44-mt-1_39.lib libboost_program_options-mgw44-mt-1_39.a
copy boost_program_options-mgw44-mt-d-1_39.lib libboost_program_options-mgw44-mt-d-1_39.a
copy boost_program_options-mgw44-mt-d.lib libboost_program_options-mgw44-mt-d.a
copy boost_program_options-mgw44-mt.lib libboost_program_options-mgw44-mt.a
copy boost_python-mgw44-mt-1_39.lib libboost_python-mgw44-mt-1_39.a
copy boost_python-mgw44-mt-d-1_39.lib libboost_python-mgw44-mt-d-1_39.a
copy boost_python-mgw44-mt-d.lib libboost_python-mgw44-mt-d.a
copy boost_python-mgw44-mt.lib libboost_python-mgw44-mt.a
copy boost_serialization-mgw44-mt-1_39.lib libboost_serialization-mgw44-mt-1_39.a
copy boost_serialization-mgw44-mt-d-1_39.lib libboost_serialization-mgw44-mt-d-1_39.a
copy boost_serialization-mgw44-mt-d.lib libboost_serialization-mgw44-mt-d.a
copy boost_serialization-mgw44-mt.lib libboost_serialization-mgw44-mt.a
copy boost_signals-mgw44-mt-1_39.lib libboost_signals-mgw44-mt-1_39.a
copy boost_signals-mgw44-mt-d-1_39.lib libboost_signals-mgw44-mt-d-1_39.a
copy boost_signals-mgw44-mt-d.lib libboost_signals-mgw44-mt-d.a
copy boost_signals-mgw44-mt.lib libboost_signals-mgw44-mt.a
copy boost_system-mgw44-mt-1_39.lib libboost_system-mgw44-mt-1_39.a
copy boost_system-mgw44-mt-d-1_39.lib libboost_system-mgw44-mt-d-1_39.a
copy boost_system-mgw44-mt-d.lib libboost_system-mgw44-mt-d.a
copy boost_system-mgw44-mt.lib libboost_system-mgw44-mt.a
copy boost_thread-mgw44-mt-1_39.lib libboost_thread-mgw44-mt-1_39.a
copy boost_thread-mgw44-mt-d-1_39.lib libboost_thread-mgw44-mt-d-1_39.a
copy boost_thread-mgw44-mt-d.lib libboost_thread-mgw44-mt-d.a
copy boost_thread-mgw44-mt.lib libboost_thread-mgw44-mt.a
copy boost_unit_test_framework-mgw44-mt-1_39.lib libboost_unit_test_framework-mgw44-mt-1_39.a
copy boost_unit_test_framework-mgw44-mt-d-1_39.lib libboost_unit_test_framework-mgw44-mt-d-1_39.a
copy boost_unit_test_framework-mgw44-mt-d.lib libboost_unit_test_framework-mgw44-mt-d.a
copy boost_unit_test_framework-mgw44-mt.lib libboost_unit_test_framework-mgw44-mt.a
copy boost_wave-mgw44-mt-1_39.lib libboost_wave-mgw44-mt-1_39.a
copy boost_wave-mgw44-mt-d-1_39.lib libboost_wave-mgw44-mt-d-1_39.a
copy boost_wave-mgw44-mt-d.lib libboost_wave-mgw44-mt-d.a
copy boost_wave-mgw44-mt.lib libboost_wave-mgw44-mt.a
copy boost_wserialization-mgw44-mt-1_39.lib libboost_wserialization-mgw44-mt-1_39.a
copy boost_wserialization-mgw44-mt-d-1_39.lib libboost_wserialization-mgw44-mt-d-1_39.a
copy boost_wserialization-mgw44-mt-d.lib libboost_wserialization-mgw44-mt-d.a
copy boost_wserialization-mgw44-mt.lib libboost_wserialization-mgw44-mt.a
copy libboost_regex-mgw44-mt-1_39.lib libboost_regex-mgw44-mt-1_39.a
copy libboost_regex-mgw44-mt-d-1_39.lib libboost_regex-mgw44-mt-d-1_39.a
copy libboost_regex-mgw44-mt-d.lib libboost_regex-mgw44-mt-d.a
copy libboost_regex-mgw44-mt.lib libboost_regex-mgw44-mt.a
copy libboost_test_exec_monitor-mgw44-mt-1_39.lib libboost_test_exec_monitor-mgw44-mt-1_39.a
copy libboost_test_exec_monitor-mgw44-mt-d-1_39.lib libboost_test_exec_monitor-mgw44-mt-d-1_39.a
copy libboost_test_exec_monitor-mgw44-mt-d.lib libboost_test_exec_monitor-mgw44-mt-d.a
copy libboost_test_exec_monitor-mgw44-mt.lib libboost_test_exec_monitor-mgw44-mt.a
:_end
PAUSE
Tim S.