Go run error (collect2.exe: error: ld returned 1 exit status)

What version of Go are you using (go version)?

go version go1.7 windows/amd64

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Go_workspace
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\hisha\AppData\Local\Temp\go-build226207278=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1

What did you do?

i am using iris framework and gorm every thing was ok until using gorm

├───controllers
├───models
├───static
│   ├───css
│   │   └───images
│   │       └───prettyPhoto
│   │           ├───dark_rounded
│   │           ├───dark_square
│   │           ├───default
│   │           ├───facebook
│   │           ├───light_rounded
│   │           └───light_square
│   ├───fonts
│   ├───img
│   │   ├───clients
│   │   ├───portfolio
│   │   └───team
│   └───js
└───templates

main.go :

package main


import (
    "mywebsite/controllers"
    "mywebsite/models"

    "github.com/kataras/go-template/django"
    "github.com/kataras/iris"
)

func main() {
    iris.UseTemplate(django.New()).Directory("templates", ".html")
    iris.StaticServe("./static", "/public")
    iris.Handle("GET", "/", controllers.MainHandler{})
    models.DB_init()
    iris.Listen(":8080")
}

models.go :

package models

import (
    "time"

    "github.com/jinzhu/gorm"
    _ "github.com/jinzhu/gorm/dialects/sqlite"
)

type User struct {
    gorm.Model
    FirstName string `gorm:"size:25"`
    LastName  string `gorm:"size:25"`
    Email     string `gorm:"type:varchar(60);unique"`
    Password  string
    IsAdmin   bool
    LastLogin time.Time
    Posts     []Post `gorm:"ForeignKey:UserID;"`
}
type Post struct {
    gorm.Model
    Title   string `gorm:"type:varchar(60)"`
    Content string `gorm:"type:text"`
    UserID  uint
}

//Init Function Initialize database and Migrate Scheme
func DB_init() {
    db, err := gorm.Open("sqlite3", "db.db")
    defer db.Close()
    if err != nil {
        panic("Failed to Connect to Database")
    }
    db.AutoMigrate(&User{}, &Post{})
}

controllers :

package controllers

import "github.com/kataras/iris"

type MainHandler struct {
}

func (c MainHandler) Serve(ctx *iris.Context) {
    ctx.MustRender("home.html", map[string]interface{}{"message": "Hi Our Visitor"}, iris.RenderOptions{"gzip": true})
}

What did you expect to see?

C:\Go_workspace\src\mywebsite>iris run main.go
         _____      _
        |_   _|    (_)
          | |  ____ _  ___
          | | | __|| |/ __|
         _| |_| |  | |\__ \
        |_____|_|  |_||___/ 4.2.7

Mon, 19 Sep 2016 04:50:46 GMT: Running at 0.0.0.0:8080
What did you see instead?

go run "c:\Go_workspace\src\mywebsite\main.go"
# command-line-arguments
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x920260): multiple definition of `r2r1kp'
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x920270): first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x9202a0): multiple definition of `r4r3kp'
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x920290): first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x91eae0): multiple definition of `r5kp'
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x91ead8): first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x920360): multiple definition of `rupolykp'
C:\Users\hisha\AppData\Local\Temp\go-link-101492155\go.o:(.text+0x920350): first defined here
collect2.exe: error: ld returned 1 exit status
iris run main.go
# command-line-arguments
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x920260): multiple definition of `r2r1kp'
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x920270): first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x9202a0): multiple definition of `r4r3kp'
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x920290): first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x91eae0): multiple definition of `r5kp'
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x91ead8): first defined here
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x920360): multiple definition of `rupolykp'
C:\Users\hisha\AppData\Local\Temp\go-link-217894499\go.o:(.text+0x920350): first defined here
collect2.exe: error: ld returned 1 exit status


Error: Failed to build the program.

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