Python Forum
Embedded python fails to compile on Raspberry Pi
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Embedded python fails to compile on Raspberry Pi
#1
Hi all!

I installed python 3.9.1 on my Raspberry Pi following the instructions here and set it as the default python interpreter. I got my compiling and linking parameters for embedded Python following the instructions here

I tried a simple test with the following code (test.c) :
int
main(int argc, char *argv[])
{
    wchar_t *program = Py_DecodeLocale(argv[0], NULL);
    if (program == NULL) {
        fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
        exit(1);
    }
    Py_SetProgramName(program);  /* optional but recommended */
    Py_Initialize();
    PyRun_SimpleString("from time import time,ctime\n"
                       "print('Today is', ctime(time()))\n");
    Py_Finalize();
    PyMem_RawFree(program);
    return 0;
}
and then

gcc -I/usr/local/opt/python-3.9.1/include/python3.9 -I/usr/local/opt/python-3.9.1/include/python3.9 -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -c test.c -o test.o

and

gcc -L/usr/local/opt/python-3.9.1/lib/python3.9/config-3.9-arm-linux-gnueabihf -L/usr/local/opt/python-3.9.1/lib -lcrypt -lpthread -ldl -lutil -lm -o test.o

and got
Error:
/usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../arm-linux-gnueabihf/crt1.o: In function '_start': /build/glibc-P1SmLh/glibc-2.19/csu/../ports/sysdeps/arm/start.S:119: undefined reference to 'main' collect2: error: ld returned 1 exit status
Trying to compile the example over here throws the same error. What could the problem be?
Reply


Messages In This Thread
Embedded python fails to compile on Raspberry Pi - by tryfon - Dec-22-2020, 11:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to run detectron2, as python embedded code in C++, on GPU? hassaniqbal931 3 1,081 Nov-02-2023, 04:45 PM
Last Post: blabling2
  Anaconda 2.4.2: The JupyterLab 3.5.3 fails to run the python code of the Geographical jamalnuman 0 330 Aug-23-2023, 07:48 AM
Last Post: jamalnuman
  Adding libraries to embedded Python as a ZIP The_Oman 0 1,224 May-05-2023, 04:05 PM
Last Post: The_Oman
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,246 Feb-24-2023, 06:14 PM
Last Post: deanhystad
Bug Embedded Python Memory Leaks Alexei 1 1,024 Sep-16-2022, 01:15 PM
Last Post: Alexei
  Embedded Python in C++ Xeno 19 3,520 Aug-03-2022, 07:29 AM
Last Post: Gribouillis
  How to compile a Python script for a Windows / Linux executable? netanelst 2 1,314 May-24-2022, 07:02 AM
Last Post: netanelst
  cv2-python will n ot compile?? barryjo 5 2,188 Dec-26-2021, 06:42 PM
Last Post: barryjo
  Coding for Python and Raspberry pi beast 3 45,723 Sep-21-2021, 09:56 PM
Last Post: beast
  Python Compile error ajitnayak1987 4 3,621 Jun-03-2021, 12:11 PM
Last Post: ibreeden

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020