[C][IP1] Build your own shell - The test runner doesn't compile other than main.c files, despite that they are included in your_program.sh

By this stage my main.c became too big and I decided to split it into separate .h and .c’s. I manually corrected your_program.sh to include these files into compilation and it compiles ok on my machine when I ran this script, but the test runner fails to compile. Shouldn’t the test runner run your_program.sh?

your_program.sh:

#!/bin/sh
#
# Use this script to run your program LOCALLY.
#
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
#
# Learn more: https://codecrafters.io/program-interface

set -e # Exit early if any commands fail

# Copied from .codecrafters/compile.sh
#
# - Edit this to change how your program compiles locally
# - Edit .codecrafters/compile.sh to change how your program compiles remotely
(
  cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
  # - add other .c files into compilation
  gcc app/*.c app/**/*.c -o /tmp/shell-target
)

# Copied from .codecrafters/run.sh
#
# - Edit this to change how your program runs locally
# - Edit .codecrafters/run.sh to change how your program runs remotely
exec /tmp/shell-target "$@"

The runner gives following error:

[compile] /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccJoaCPj.o: in function `main':
[compile] main.c:(.text+0x20c5): undefined reference to `init_builtins'
[compile] /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: main.c:(.text+0x2182): undefined reference to `parse_args'
[compile] /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: main.c:(.text+0x218d): undefined reference to `builtIns'
[compile] /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: main.c:(.text+0x21ac): undefined reference to `builtIns'
[compile] /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: main.c:(.text+0x21b3): undefined reference to `builtIns'
[compile] /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: main.c:(.text+0x21ba): undefined reference to `builtIns'
[compile] /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: main.c:(.text+0x21e1): undefined reference to `getCommandLocation'
[compile] /usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: main.c:(.text+0x2347): undefined reference to `free_parse_result'
[compile] collect2: error: ld returned 1 exit status

Hi @avfirsov, you will also need to update .codecrafters/compile.sh with the following:

gcc app/*.c app/**/*.c -o /tmp/shell-target

Here’s the relevant doc:

1 Like

Thank’s deeply! Sorry for inattention

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.