Skip to content

Tutorial for successful compile on OSX #2

@mrchrisster

Description

@mrchrisster

[Guide] Building on macOS (Apple Silicon/Homebrew) without Makefiles

If you are trying to build libgourou on macOS (specifically Apple Silicon) and encountering linker errors like Undefined symbols, missing vtable, or issues finding OpenSSL/Curl/Libzip, you are not alone. The default Makefiles often struggle with Homebrew's "keg-only" paths and specific macOS linker requirements.

I have created a standalone shell script that bypasses the Makefile entirely. It automatically detects your Homebrew paths, compiles all dependencies (including the internal pugixml and uPDFParser), and links the utilities correctly.

1. Prerequisites

Install the required libraries via Homebrew:

brew install openssl curl libzip
  1. The Build Script
    Save the following code as build_mac.sh in the root of the libgourou directory.
    Why this script works:
    Dynamic Paths: Automatically finds where Homebrew installed libraries (which varies by chip architecture).
    Symbol Fix: Automatically detects and compiles helper files in utils/ (like DRMProcessorClientImpl.cpp), fixing the common Undefined symbols for architecture arm64 error.
    Zero Config: No need to edit Makefiles or fight with CMake versions.
#!/bin/bash
set -e # Stop immediately if any command fails

echo "=== 1. Setting up paths ==="
# Automatically detect Homebrew paths
OPENSSL=$(brew --prefix openssl)
CURL=$(brew --prefix curl)
LIBZIP=$(brew --prefix libzip)

# Compiler flags (Apple Silicon / Clang friendly)
CXX="clang++"
CXXFLAGS="-Wall -fPIC -O2 -std=c++11 -stdlib=libc++ -I./include -I./lib/pugixml/src -I./lib/updfparser/include -I$OPENSSL/include -I$CURL/include -I$LIBZIP/include"
LIBS="-L$OPENSSL/lib -L$CURL/lib -L$LIBZIP/lib -lcurl -lzip -lssl -lcrypto -lz"

echo "=== 2. Compiling Library Object Files ==="
mkdir -p obj

# Compile src/*.cpp
for file in src/*.cpp; do
    echo "  Compiling $(basename $file)..."
    $CXX $CXXFLAGS -c "$file" -o "obj/$(basename "$file" .cpp).o"
done

# Compile dependencies (pugixml)
echo "  Compiling pugixml..."
$CXX $CXXFLAGS -c lib/pugixml/src/pugixml.cpp -o obj/pugixml.o

# Compile dependencies (uPDFParser - compiles all sources in the folder)
echo "  Compiling uPDFParser..."
for file in lib/updfparser/src/*.cpp; do
    echo "    Compiling $(basename $file)..."
    $CXX $CXXFLAGS -c "$file" -o "obj/$(basename "$file" .cpp).o"
done

echo "=== 3. Linking Shared Library ==="
$CXX -shared -install_name /usr/local/lib/libgourou.so -o libgourou.so obj/*.o $LIBS

echo "=== 4. Compiling Utils Helpers ==="
# Dynamically find any helper .cpp files in utils/ that are NOT main programs.
# This fixes "Undefined symbols" errors by ensuring DRMProcessorClientImpl and others are compiled.
HELPER_OBJS=""
for file in utils/*.cpp; do
    if ! grep -q "int main" "$file"; then
        echo "  Compiling helper: $(basename $file)..."
        OBJ_NAME="obj/utils_$(basename "$file" .cpp).o"
        $CXX $CXXFLAGS -c "$file" -o "$OBJ_NAME"
        HELPER_OBJS="$HELPER_OBJS $OBJ_NAME"
    fi
done

echo "=== 5. Compiling Tools ==="
# Link tools against the shared library AND the helper objects found above
echo "  Building adept_activate..."
$CXX $CXXFLAGS utils/adept_activate.cpp $HELPER_OBJS -o adept_activate -L. -lgourou $LIBS

echo "  Building acsmdownloader..."
$CXX $CXXFLAGS utils/acsmdownloader.cpp $HELPER_OBJS -o acsmdownloader -L. -lgourou $LIBS

echo "  Building adept_remove..."
$CXX $CXXFLAGS utils/adept_remove.cpp $HELPER_OBJS -o adept_remove -L. -lgourou $LIBS

echo "=== 6. Installing ==="
sudo cp libgourou.so /usr/local/lib/
sudo cp adept_activate /usr/local/bin/
sudo cp acsmdownloader /usr/local/bin/
sudo cp adept_remove /usr/local/bin/
sudo mkdir -p /usr/local/include/libgourou
sudo cp include/* /usr/local/include/libgourou/

echo "SUCCESS! Installation complete."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions