Skip to content

Latest commit

Β 

History

History
123 lines (91 loc) Β· 2.25 KB

File metadata and controls

123 lines (91 loc) Β· 2.25 KB

Mojo πŸ”₯ Programming

Welcome to the Mojo Programming repository!
This repo contains programming problems and solutions implemented using the Mojo language.


πŸ“Œ Running mojo in google colab

Run the following commands in notebook cells.

Install magic:

!curl -ssL https://magic.modular.com/ | bash

πŸ“Œ Issues & Fixes

If running Mojo on Ubuntu gives an error like:

No suitable compiler found or similar build issues,

Run the following commands to install the necessary dependencies:

sudo apt update
sudo apt install -y build-essential

/usr/bin/ld: cannot find -lz: No such file or directory

/usr/bin/ld: cannot find -ltinfo: No such file or directory

Means the linker (ld) is unable to find two required libraries:

  • -lz β†’ the zlib compression library

  • -ltinfo β†’ the termcap/info library, part of ncurses

Run the following commands to install the necessary dependencies:

sudo apt-get update
sudo apt-get install zlib1g-dev libtinfo-dev
  • zlib1g-dev: Provides libz.so
  • libtinfo-dev: Provides libtinfo.so (used for terminal interfaces)

Upadate PATH:

import os
os.environ['PATH'] += ':/root/.modular/bin'

Create a example mojo project:

!magic init example --format mojoproject

Go inside project folder:

%cd example/

Create a sample hello.mojo file:

%%bash
cat > hello.mojo <<EOF
fn main():
  print("Hello word from mojo!")
EOF



Run the mojo program:

!magic run mojo hello.mojo

Build and run the binary if you want:

!magic run mojo build hello.mojo
!./hello

πŸ“Œ Check out only the cuda folder

Use the following shell script snippet to checkout only the cuda folder

# CUDA compiler
NVCC := nvcc

# Directories
INCLUDE_DIR := include
SRC_DIR := src
BUILD_DIR := build

# Source files
SRCS := $(wildcard $(SRC_DIR)/*.cu)
TARGET := $(BUILD_DIR)/histogram

# Flags
NVCC_FLAGS := -I$(INCLUDE_DIR) -O2

# Default rule
all: $(TARGET)

# Linking and compilation
$(TARGET): $(SRCS) | $(BUILD_DIR)
	$(NVCC) $(NVCC_FLAGS) $(SRCS) -o $@

# Create build directory if it doesn't exist
$(BUILD_DIR):
	mkdir -p $(BUILD_DIR)

# Cleanup rule
clean:
	rm -rf $(BUILD_DIR)