[Python] C++ cross compile error: Python.h: No such file or directory?

Discussão em 'Python' iniciado por Stack, Fevereiro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I have this code of mytest.cpp to try calling some class from Standby.py python file.

    #include <iostream>
    #include <cstdlib>
    #include <string>
    #include <array>
    #include <sstream>
    #include <unistd.h> // Required for sleep() function
    #include <Python.h>

    // Function to show available commands
    void showUsage() {
    std::cout << " standby - Put the system into standby mode\n";
    std::cout << " reboot - Send the system into shutdown mode\n";
    }

    // Function to execute the provided command
    void executeCommand(const std::string &command) {
    PyObject* myModuleString = PyLong_FromString((char*)"/usr/lib/enigma2/python/Screens/Standby.py");
    PyObject* myModule = PyImport_Import(myModuleString);
    PyObject* myFunction = PyObject_GetAttrString(myModule,(char*)"Standby");
    if (command == "standby") {
    myFunction;
    }
    }

    // Main function
    int main(int argc, char *argv[]) {
    if (argc != 2) {
    showUsage();
    return 1;
    }

    std::string command = argv[1];
    executeCommand(command);

    return 0;
    }


    And when i try to compile it with this command

    arm-linux-gnueabihf-g++ -o Bcmd.so Bcmd.cpp


    I have got this error

    cmd.cpp:7:10: fatal error: Python.h: No such file or directory
    7 | #include <Python.h>
    | ^~~~~~~~~~
    compilation terminated.


    and also try this command

    arm-linux-gnueabihf-g++ -o Bcmd.so Bcmd.cpp -I/usr/include/python3.12/ -lpython3.12


    But I have got

    In file included from /usr/include/python3.12/Python.h:12,
    from Bcmd.cpp:7:
    /usr/include/python3.12/pyconfig.h:15:12: fatal error: arm-linux-gnueabihf/python3.12/pyconfig.h: No such file or directory
    15 | # include <arm-linux-gnueabihf/python3.12/pyconfig.h>
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    compilation terminated.


    And here are the output of find files

    /usr/lib/ccache/arm-linux-gnueabihf-g++
    /usr/bin/arm-linux-gnueabihf-g++

    /usr/libexec/gcc-cross/arm-linux-gnueabihf
    /usr/share/gdb/auto-load/usr/arm-linux-gnueabihf
    /usr/arm-linux-gnueabihf
    /usr/arm-linux-gnueabihf/include/c++/13/arm-linux-gnueabihf
    /usr/arm-linux-gnueabihf/include/finclude/arm-linux-gnueabihf
    /usr/lib/arm-linux-gnueabihf
    /usr/lib/gcc-cross/arm-linux-gnueabihf

    /usr/include/python3.12/Python.h

    /usr/include/x86_64-linux-gnu/python3.12/pyconfig.h
    /usr/include/python3.12/pyconfig.h


    How to fix this issue ?!

    Continue reading...

Compartilhe esta Página