Installation

Installation in Python

#bash

pip install PyCPPExecuter

Installation in Linux

#bash

python3 -m pip install PyCPPExecuter

Installation in Google Colab/Jupyter Notebook

#Python

!pip install PyCPPExecuter

To verify the gcc compiler is installed run this

#bash

gcc-install

For Google colab/jupyter Notebook

#Python

import os

os.system('gcc-install')

Note: Any error in file path permissions please try to use Python virtual environment

C++

Running C++ Code

By specifying the code in the doc strings and invoking the compile method and execute method one after the other from the class CPPExecuter.

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

#Initialize the Code in doc string

cppcode =

"""#include<iostream> int main(){ std::cout << "Hello World!"; return 0; }"""

executer = CPPExecuter()

executer.compile(code = cppcode)

executer.execute()

Compiling the External File of C++ Code

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

file_path = "path/to/your/c++/file.cpp"

executer = CPPExecuter()

executer.compile(file_path = file_path)

executer.execute()

Generating the Object file for the C++ code

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

executer = CPPExecuter()

cppcode =

"""#include<iostream> int main(){ std::cout << "Hello World!"; return 0; }"""

saving_path = "path/to/save/object/file.o"

executer.create_object_file(code = cppcode, path = saving_path)

Generating Object file from external C++ code by specifying the file_path

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

executer = CPPExecuter()

file_path = "path/of/the/c++/file.cpp"

saving_path = "path/to/save/object/file.o"

executer.create_object_file(file_path = file_path, path = saving_path)

Generating Assembly code for the C++ code

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

executer = CPPExecuter()

cppcode =

"""#include<iostream> int main(){ std::cout << "Hello World!"; return 0; }"""

saving_path = "path/to/save/object/file.asm"

executer.create_assembly_code(code = cppcode, path = saving_path)

Generating Assembly Code from external C++ code by specifying the file_path

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

executer = CPPExecuter()

file_path = "path/of/the/c++/file.cpp"

saving_path = "path/to/save/object/file.asm"

executer.create_object_file(file_path = file_path, path = saving_path)

C

Running C Code

By specifying the code in the doc strings and invoking the compile method and execute method one after the other from the class CPPExecuter.

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

#Initialize the Code in doc string

ccode =

"""#include<stdio.h> int main(){ printf("Hello World!"); return 0; }"""

executer = CPPExecuter(lang='C')

executer.compile(code = ccode)

executer.execute()

Compiling the External File of C Code

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

file_path = "path/to/your/c/file.c"

executer = CPPExecuter(lang='C')

executer.compile(file_path = file_path)

executer.execute()

Generating the Object file for the C code

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

executer = CPPExecuter(lang='C')

ccode =

"""#include<stdio.h> int main(){ printf("Hello World!"); return 0; }"""

saving_path = "path/to/save/object/file.o"

executer.create_object_file(code = ccode, path = saving_path)

Generating Object file from external C code by specifying the file_path

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

executer = CPPExecuter(lang='C')

file_path = "path/of/the/c/file.c"

saving_path = "path/to/save/object/file.o"

executer.create_object_file(file_path = file_path, path = saving_path)

Generating Assembly code for the C code

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

executer = CPPExecuter(lang='C')

ccode =

"""#include<stdio.h> int main(){ printf("Hello World!"); return 0; }"""

saving_path = "path/to/save/object/file.asm"

executer.create_assembly_code(code = ccode, path = saving_path)

Generating Assembly Code from external C code by specifying the file_path

#Python

#Import the CPPExecuter class

from PyCPPExecuter import CPPExecuter

executer = CPPExecuter(lang='C')

file_path = "path/of/the/c/file.cpp"

saving_path = "path/to/save/object/file.asm"

executer.create_object_file(file_path = file_path, path = saving_path)

Note: Please use additional forward slash(/) for escapce sequence characters in the doc strings.
Note: Please report any Issues in the github repository Issues page.