Python in C++: Unresolved external -


i try embed python in c++ application, linker keeps saying error:

[ilink32 error] error: unresolved external '_pymodule_create2tracerefs' referenced e:\cpp projects\anderlicht\win32\debug\anderlicht.obj 

i'm using embarcadero c++ builder xe2, converted python33.lib coff2omf.exe.

this code in main.cpp:

#include "anderlicht.c" #pragma comment(lib, "python33_omf.lib")  // in main(): pyimport_appendinittab("anderlicht",pyinit_anderlicht); py_setprogramname(programname.w_str()); py_initialize(); 

in anderlicht.c python.h included. have fix error?

the problem you're using different compiler flags in building code used in building python dll. in particular, pymodule_create2tracerefs defined if have -dpy_trace_refs (which passed in via extra_cflags in make command on unix; have no idea how embarcadero c++ builder on windows). usually, isn't defined—in particular, if you're using dll pre-build python binary, won't have defined.

so, if want have custom flags in building code, need rebuild python same flags. otherwise, need flags used build python, , use same ones when building code.

on unix, trivial: call python3.3-config --cflags , python3.3-config --ldflags flags pass compile , link steps. on windows, it's less trivial. building c , c++ extensions on windows chapter in docs explains how when you're using same toolchain used build python (usually msvc), , if you're using mingw msvc-compat features there's documentation elsewhere on how that… if you're using different toolchain, need figure of out yourself.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -