[ell-i-developers] Fwd: Embedding python in emulator

  • From: Asif Sardar <engr.asif.sardar@xxxxxxxxxxxxxx>
  • To: ell-i-developers@xxxxxxxxxxxxx
  • Date: Tue, 14 Oct 2014 19:40:11 +0300

Hi,

Has anybody embedded python in C/C++ application. My platform is 64-bit and
python binaries I am using for Runtime/emulator is 32-bit. I have added
following flags in CFLAGS and LDFLAGS to compile and link the c/c++ files
in emulator with (#include </path/32-bit-python/include/python.h>)

CFLAGS += -I/opt/pym32/bin/include/python2.7 -fno-strict-aliasing
-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes

LDFLAGS += -L/opt/pym32/lib/python2.7/config -lpthread -ldl -lutil -lm
-lpython2.7 -Xlinker -export-dynamic

The files compiles but breaks when linking. Can anybody help with following
errors:

-----------------------
./libsystem_stm32f4discovery.a(Register.o): In function
`Register::GPIO_Callback_Python(std::string, std::string, unsigned int,
std::string)':
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:41:
undefined reference to `Py_Initialize'
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:43:
undefined reference to `PyRun_SimpleStringFlags'
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:44:
undefined reference to `Py_Finalize'
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:41:
undefined reference to `Py_Initialize'
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:43:
undefined reference to `PyRun_SimpleStringFlags'
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:44:
undefined reference to `Py_Finalize'
./libsystem_stm32f4discovery.a(system_stm32f4xx.o): In function
`__exchange_and_add':
/usr/include/c++/4.8/ext/atomicity.h:49: undefined reference to
`__atomic_fetch_add_4'
/usr/include/c++/4.8/ext/atomicity.h:49: undefined reference to
`__atomic_fetch_add_4'
/usr/include/c++/4.8/ext/atomicity.h:49: undefined reference to
`__atomic_fetch_add_4'
/usr/include/c++/4.8/ext/atomicity.h:49: undefined reference to
`__atomic_fetch_add_4'
-----------------------


---------- Forwarded message ----------
From: Asif Sardar <engr.asif.sardar@xxxxxxxxxxxxxx>
Date: Mon, Oct 13, 2014 at 6:17 PM
Subject: Embedding python in emulator
To: Pekka Nikander <pekka.nikander@xxxxxx>


Hi Pekka,

I am trying to include python.h in emulator/inc/register.h

I have to include cflags and ldflags in Makefile system of emulator e.g.

-I/opt/include/python2.7 -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3
-Wall -Wstrict-prototypes

-L/opt/lib/python2.7/config -lpthread -ldl -lutil -lm -lpython2.7
-Xlinker -export-dynamic

However, I am getting:
----------------------------------------------------
g++ -m32 -march=i386 -m32 -march=i386 -Xlinker -export-dynamic -o
robot_library  robot_library.o stm32f4discovery.o libSPI.a "-L."
"-L/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../variants/stm32f4discovery"
"-lsystem_stm32f4discovery" -lstdc++
./libsystem_stm32f4discovery.a(Register.o): In function
`Register::GPIO_Callback_Python(std::string, std::string, unsigned int,
std::string)':
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:41:
undefined reference to `Py_Initialize'
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:43:
undefined reference to `PyRun_SimpleStringFlags'
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:44:
undefined reference to `Py_Finalize'
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:41:
undefined reference to `Py_Initialize'
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:43:
undefined reference to `PyRun_SimpleStringFlags'
/home/asif/Ell-i-Working-Directory/Ell-i-Software-Development/Runtime/stm32/tests/robot_library/../../emulator/src/Register.cpp:44:
undefined reference to `Py_Finalize'
./libsystem_stm32f4discovery.a(system_stm32f4xx.o): In function
`__exchange_and_add':
/usr/include/c++/4.8/ext/atomicity.h:49: undefined reference to
`__atomic_fetch_add_4'
/usr/include/c++/4.8/ext/atomicity.h:49: undefined reference to
`__atomic_fetch_add_4'
/usr/include/c++/4.8/ext/atomicity.h:49: undefined reference to
`__atomic_fetch_add_4'
/usr/include/c++/4.8/ext/atomicity.h:49: undefined reference to
`__atomic_fetch_add_4'
collect2: error: ld returned 1 exit status
make[1]: *** [robot_library] Error 1
-----------------------------------

Can you help me in including these flags in the Makefile system and link
the python with it? It will help a lot, to call from c to python
independently.



-- 



*With Best Regards,Asif Sardar.+358 43 8265795 <%2B358%2043%208265795>*



-- 



*With Best Regards,Asif Sardar.+358 43 8265795*

Other related posts:

  • » [ell-i-developers] Fwd: Embedding python in emulator - Asif Sardar