go.mod: 1: module: not found

130 views
Skip to first unread message

saurav deshpande

unread,
Feb 1, 2021, 1:35:32 PM2/1/21
to golang-nuts
Hello, I am trying to run a make file but it gives me the following error:
go.mod: 1: module: not found
go 1.15: unknown command


here is the make file:

OS = $(shell uname -s)
ARCH := x86
BUILD_DIR := build
BUILD_ABS_DIR := $(CURDIR)/$(BUILD_DIR)

export SHELL := /bin/bash -o pipefail

LD := ld
AS := nasm

GOOS := linux
GOARCH := 386
GOPATH := $(CURDIR)/


LDFLAGS := -n -melf_i386 -T linker.ld -static --no-ld-generated-unwind-info
ASFLAGS := -f elf32

all: clean kernel.elf run

kernel.elf: boot.o go.o
@$(LD) $(LDFLAGS) boot.o go.o -o kernel.elf

os.iso: kernel.elf
@cp kernel.elf iso/boot/kernel.elf
@genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -A os -input-charset utf8 -quiet -boot-info-table -o os.iso iso

run: os.iso
@bochs -f bochsrc.txt -q

go.o:
@mkdir -p $(BUILD_DIR)
@echo "[go] compiling go sources into a standalone .o file"
echo $(GOPATH)
@GOARCH=386 GOOS=linux GOPATH=$(GOPATH) COG_ENABLED=1 go build -n 2>&1 | sed \
-e "1s|^|set -e\n|" \
-e "1s|^|export GOOS=linux\n|" \
-e "1s|^|export GOARCH=386\n|" \
-e "1s|^|export CGO_ENABLED=1\n|" \
-e "1s|^|WORK='$(BUILD_ABS_DIR)'\n|" \
-e "1s|^|alias pack='go tool pack'\n|" \
-e "/^mv/d" \
-e "s|-extld|-tmpdir='$(BUILD_ABS_DIR)' -linkmode=external -extldflags='-nostdlib' -extld|g" \
| sh 2>&1 | sed -e "s/^/ | /g"

@# build/go.o is a elf32 object file but all go symbols are unexported. Our
@# asm entrypoint code needs to know the address to 'main.main' so we use
@# objcopy to make that symbol exportable
@echo "[objcopy] export 'main.main' symbol in go.o"
@objcopy --globalize-symbol='main.main' $(BUILD_DIR)/go.o go.o

%.o: assembly/%.asm
@$(AS) $(ASFLAGS) $< -o $@

clean:
@rm -rf *.o kernel.elf os.iso iso/boot/kernel.elf build/



Thank you

Ian Lance Taylor

unread,
Feb 1, 2021, 2:18:51 PM2/1/21
to saurav deshpande, golang-nuts
On Mon, Feb 1, 2021 at 10:35 AM saurav deshpande
<saurav.des...@gmail.com> wrote:
>
> Hello, I am trying to run a make file but it gives me the following error:
> go.mod: 1: module: not found
> go 1.15: unknown command

...

> go.o:
> @mkdir -p $(BUILD_DIR)
> @echo "[go] compiling go sources into a standalone .o file"
> echo $(GOPATH)
> @GOARCH=386 GOOS=linux GOPATH=$(GOPATH) COG_ENABLED=1 go build -n 2>&1 | sed \
> -e "1s|^|set -e\n|" \
> -e "1s|^|export GOOS=linux\n|" \
> -e "1s|^|export GOARCH=386\n|" \
> -e "1s|^|export CGO_ENABLED=1\n|" \
> -e "1s|^|WORK='$(BUILD_ABS_DIR)'\n|" \
> -e "1s|^|alias pack='go tool pack'\n|" \
> -e "/^mv/d" \
> -e "s|-extld|-tmpdir='$(BUILD_ABS_DIR)' -linkmode=external -extldflags='-nostdlib' -extld|g" \
> | sh 2>&1 | sed -e "s/^/ | /g"

This procedure--using "go build -n" and editing the output--is not
supported and is going to be highly version-specific. Has this ever
worked? Have you changed the version of Go that you are using?

Do your sources have a go.mod file?

Ian

saurav deshpande

unread,
Feb 1, 2021, 2:23:33 PM2/1/21
to golang-nuts
We have a go.mod file.
The same make file worked with go 1.9.7 version, it did not support mod.
I am trying to make this work with go 1.15, can you please suggest changes that would make this work.

Thank you

Ian Lance Taylor

unread,
Feb 1, 2021, 4:34:39 PM2/1/21
to saurav deshpande, golang-nuts
On Mon, Feb 1, 2021 at 11:24 AM saurav deshpande
<saurav.des...@gmail.com> wrote:
>
> We have a go.mod file.
> The same make file worked with go 1.9.7 version, it did not support mod.
> I am trying to make this work with go 1.15, can you please suggest changes that would make this work.

What does your go.mod file look like?

Ian
> --
> You received this message because you are subscribed to the Google Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/4cfebff8-f9ad-40b1-afab-253b8ba25e48n%40googlegroups.com.

saurav deshpande

unread,
Feb 1, 2021, 4:41:43 PM2/1/21
to golang-nuts
it just contains:

module babyLotus

go 1.15


Ian Lance Taylor

unread,
Feb 1, 2021, 7:03:27 PM2/1/21
to saurav deshpande, golang-nuts
On Mon, Feb 1, 2021 at 1:42 PM saurav deshpande
<saurav.des...@gmail.com> wrote:
>
> it just contains:
>
> module babyLotus
>
> go 1.15

The module name should probably be a path name.

I bet that "go build -n" is printing an error, and you are piping that
error to sh.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/487b32a6-2222-4025-b754-790d5f3820can%40googlegroups.com.

saurav deshpande

unread,
Feb 2, 2021, 2:15:50 PM2/2/21
to golang-nuts
I tried by giving the module name as pathname by pushing the code to git and created go.mod using that path, but still gives the same error.


Thank you

Ian Lance Taylor

unread,
Feb 2, 2021, 3:13:47 PM2/2/21
to saurav deshpande, golang-nuts
On Tue, Feb 2, 2021 at 11:16 AM saurav deshpande
<saurav.des...@gmail.com> wrote:
>
> I tried by giving the module name as pathname by pushing the code to git and created go.mod using that path, but still gives the same error.

I'm sorry that didn't help, but I still expect that the problem is
that "go build -n" is printing an error message, and your Makefile is
piping that error message directly to the shell. You're going to have
to figure out what "go build -n" is printing.

I'll repeat my earlier comment that this build procedure is not
supported. "go build" is supported. "go build -n | sed | sh" is not
supported.
> To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/bef3aea9-2ecb-4e9c-a395-992d8e0ed3edn%40googlegroups.com.

saurav deshpande

unread,
Feb 2, 2021, 3:26:24 PM2/2/21
to Ian Lance Taylor, golang-nuts
Okay, will try with a different approach
Thank you
Reply all
Reply to author
Forward
0 new messages