Go 1.6.1 Link problem on Windows:

2,508 views
Skip to first unread message

Dorival Pedroso

unread,
Apr 20, 2016, 10:06:28 PM4/20/16
to golang-nuts
Hi,

I'm just wondering what is the cause of the following error (multiple definition of __something)?
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libntdll.a(dyyls01966.o):(.idata$5+0x0): multiple definition of `__imp_pow'

This only happens on Windows10 but on Ubuntu/Linux.

The Go code makes a call to LAPACK via a C interface as follows:
package main

/*
#cgo CFLAGS: -O3
#cgo linux   LDFLAGS: -lm -llapack -lgfortran -lblas
#cgo windows LDFLAGS: -lm -llapack -lgfortran -lblas -LC:/GoslDeps/lib

#include <stdlib.h>

void dgesvd_(const char* jobu, const char* jobvt, const int* M, const int* N, double* A, const int* lda, double* S, double* U, const int* ldu, double* VT, const int* ldvt, double* work,const int* lwork, const int* info);

int lapack_svd(double *U, double *S, double *Vt, long m_long, double *A) {
    int     m     = (int)(m_long);
    int     info  = 0;
    char    job   = 'A';
    int     lwork = 10*m;
    double* work  = (double*)malloc(lwork*sizeof(double));
    dgesvd_(&job,   // JOBU
            &job,   // JOBVT
            &m,     // M
            &m,     // N
            A,      // A
            &m,     // LDA
            S,      // S
            U,      // U
            &m,     // LDU
            Vt,     // VT
            &m,     // LDVT
            work,   // WORK
            &lwork, // LWORK
            &info); // INFO
    free(work);
    return info;
}
*/
import "C"

import (
"fmt"
"math"
"unsafe"
)

func main() {
A := []float64{1, 2, 3, 2, -4, -9, 3, 6, -3} // col-major format
m := int(math.Sqrt(float64(len(A))))
I := func(i, j int) int { return j*m + i }
printmat(m, A, "A")
U := make([]float64, len(A))
S := make([]float64, len(A))
Vt := make([]float64, len(A))
info := C.lapack_svd(
(*C.double)(unsafe.Pointer(&U[0])),
(*C.double)(unsafe.Pointer(&S[0])),
(*C.double)(unsafe.Pointer(&Vt[0])),
(C.long)(m),
(*C.double)(unsafe.Pointer(&A[0])),
)
fmt.Printf("SVD: info = %d\n", info)
USVt := make([]float64, len(A))
for i := 0; i < m; i++ {
for j := 0; j < m; j++ {
for k := 0; k < m; k++ {
USVt[I(i, j)] += U[I(i, k)] * S[k] * Vt[I(k, j)]
}
}
}
printmat(m, USVt, "U*S*Vt")
}

func printmat(m int, M []float64, msg string) {
fmt.Printf("%s =\n", msg)
for i := 0; i < m; i++ {
for j := 0; j < m; j++ {
fmt.Printf("%13.8f", M[j*m+i])
}
fmt.Println()
}
}

Any help is much appreciated.

Cheers.
Dorival

Ian Lance Taylor

unread,
Apr 20, 2016, 10:22:36 PM4/20/16
to Dorival Pedroso, golang-nuts
On Wed, Apr 20, 2016 at 7:06 PM, Dorival Pedroso
<dorival...@gmail.com> wrote:
>
> I'm just wondering what is the cause of the following error (multiple
> definition of __something)?
> C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
> C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libntdll.a(dyyls01966.o):(.idata$5+0x0):
> multiple definition of `__imp_pow'

Hmmm, that looks a lot like https://golang.org/issue/9510 , but that
was fixed in Go 1.6. Are you sure you are using 1.6.1?

Ian

Dorival Pedroso

unread,
Apr 20, 2016, 10:24:08 PM4/20/16
to golang-nuts, dorival...@gmail.com
Yep. I've installed go1.6.1.windows-amd64.msi

$ go version
go version go1.6.1 windows/amd64


Thanks

brainman

unread,
Apr 20, 2016, 10:31:25 PM4/20/16
to golang-nuts, dorival...@gmail.com
On Thursday, 21 April 2016 12:24:08 UTC+10, Dorival Pedroso wrote:
Yep. I've installed go1.6.1.windows-amd64.msi

If you can provide steps to reproduce your problem here https://golang.org/issue/new, I will try to investigate it.

Thank you.

Alex 

Dorival Pedroso

unread,
Apr 20, 2016, 11:31:56 PM4/20/16
to golang-nuts, dorival...@gmail.com
Sure! And thank you very much!

This is what I did to install everything in Windows to compile LAPACK and then connect it to Go (you can definitively skip some steps if you work in Windows already):

1 Git and Git Bash

From https://git-scm.com/download/ download and install Git-2.8.1-64-bit.exe. Default options are fine.

2 TDM gcc and gfortran

From http://tdm-gcc.tdragon.net/download download and install tdm64-gcc-5.1.0-2.exe. Select gfortran and keep other default options.

3 CMake

From https://cmake.org/download/ download and install cmake-3.5.2-win32-x86

4 Go language (1.6)

From https://golang.org/dl/ download go1.6.1.windows-amd64.msi. Default options are fine.

Set a new environment variable named GOPATH with the location where to store all go source code, including yours (e.g. C:\Users\MyName\\MyGo). Restart.

5 Lapack

Download

Get lapack-3.5.0.tgz from http://www.netlib.org/lapack/lapack-3.6.0.tgz and save it into C:\GoslDeps

Extract files

Start Git Bash and type

cd /c/GoslDeps

tar xzvf lapack-3.6.0.tgz

mkdir build-lapack

Compile

Start CMake (cmake-gui) and select:

  1. Where is the source code = C:/GoslDeps/lapack-3.6.0

  2. Where to build the binaries = C:/GoslDeps/build-lapack

  3. Hit [Configure]

  4. Select MinGW Makefiles under Specify the generator for this project (leave Use default native compilers on). Hit [Finish]

  5. Change CMAKE_INSTALL_PREFIX = C:/GoslDeps

  6. Hit [Configure] again

  7. Hit [Generate] (and close window)

Continue on Git Bash:

alias m='mingw32-make.exe'

cd build-lapack

m


6 Call Lapack from Go

We can now run the above code:

go run main.go


Cheers
Dorival

brainman

unread,
Apr 21, 2016, 12:37:20 AM4/21/16
to golang-nuts, dorival...@gmail.com
Select MinGW Makefiles under Specify the generator for this project (leave Use default native compilers on). Hit [Finish]

When I hit Finish I get "Error in configuration process, project files may be invalid".

Alex

caleb.c...@gmail.com

unread,
Jun 3, 2016, 4:03:30 PM6/3/16
to golang-nuts
I'm experiencing the same thing after updating from Go 1.5.x to 1.6.x. CGO programs that used to build fine are now reporting about multiple definitions between libntdll and libmsvcrt.

I:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libntdll.a(dcxis01971.o):(.idata$5+0x0): multiple definition of `__imp_sqrt'
I:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(deips01189.o):(.idata$5+0x0): first defined here

Roger Pack

unread,
Jun 7, 2016, 10:49:10 PM6/7/16
to golang-nuts, caleb.c...@gmail.com


On Friday, June 3, 2016 at 2:03:30 PM UTC-6, caleb.c...@gmail.com wrote:
I'm experiencing the same thing after updating from Go 1.5.x to 1.6.x. CGO programs that used to build fine are now reporting about multiple definitions between libntdll and libmsvcrt.

I:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libntdll.a(dcxis01971.o):(.idata$5+0x0): multiple definition of `__imp_sqrt'
I:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(deips01189.o):(.idata$5+0x0): first defined here


That looks like a mingw-w64 issue to me [?]

brainman

unread,
Jun 8, 2016, 3:17:08 AM6/8/16
to golang-nuts, caleb.c...@gmail.com
On Friday, 3 June 2016 10:03:30 UTC-10, caleb.c...@gmail.com wrote:
I'm experiencing the same thing after updating from Go 1.5.x to 1.6.x. CGO programs that used to build fine are now reporting about multiple definitions between libntdll and libmsvcrt.

I:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libntdll.a(dcxis01971.o):(.idata$5+0x0): multiple definition of `__imp_sqrt'
I:/msys/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(deips01189.o):(.idata$5+0x0): first defined here



I am pretty sure your problem is similar to https://github.com/golang/go/issues/8756. If not, please, create new issue. Thank you.

Alex 

saurabh...@gmail.com

unread,
Jun 22, 2016, 8:33:01 AM6/22/16
to golang-nuts
I am having the same issues with go1.6.2... I also tried go1.7beta2 with no luck.
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1

c
:/program files/mingw-w64/x86_64-4.8.1-posix-seh-rt_v3-rev2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/libntdll.a(dmads01971.o):(.idata$5+0x0): multiple definition of `__imp_sqrt'
c:/program files/mingw-w64/x86_64-4.8.1-posix-seh-rt_v3-rev2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(dygcs01179.o):(.idata$5+0x0): first defined here

Dorival Pedroso

unread,
Jun 22, 2016, 8:34:34 AM6/22/16
to saurabh...@gmail.com, golang-nuts
oh, bad news... I was expecting this to be fixed in 1.7...

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/fW4KZQ05G_8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Dorival Pedroso PhD +61 0420411142 www.cpmech.com Brisbane Australia

Roger Pack

unread,
Jun 22, 2016, 10:31:18 AM6/22/16
to saurabh...@gmail.com, golang-nuts
FWIW this is not a failure, just a double define... and if the problem
is in mingw-w64 then it won't be fixed in golang any version of
course, though I'm not sure if that's the case or not.
Cheers!

saurabh...@gmail.com

unread,
Jan 1, 2017, 11:19:36 AM1/1/17
to golang-nuts
Happy new year everyone. Just checked this on Go 1.7.4 and MinGW x86_64-6.2.0-posix-seh-rt_v5-rev1 on my code and the problem stays the same.
C:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1

C
:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libntdll.a(dkbgs01971.o):(.idata$5+0x0): multiple definition of `__imp_sqrt'
C:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(dekes01190.o):(.idata$5+0x0): first defined here
C:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libntdll.a(dkbgs01966.o):(.idata$5+0x0): multiple definition of `
__imp_pow'
C:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(dekes01161.o):(.idata$5+0x0): first defined here
C:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(dkbgs01971.o): illegal symbol index 116 in relocs
collect2.exe: error: ld returned 1 exit status


There is no problem on Linux (tried various distros).

Best Regards,
Saurabh


On Wednesday, April 20, 2016 at 7:06:28 PM UTC-7, Dorival Pedroso wrote:

Dave Cheney

unread,
Jan 1, 2017, 1:46:28 PM1/1/17
to golang-nuts, saurabh...@gmail.com
It looks like something is trying to invoke the 32 bit compiler, not the 64 bit compiler. Can you please post the entire output, including the command you used to invoke it.

saurabh...@gmail.com

unread,
Jan 1, 2017, 2:43:37 PM1/1/17
to golang-nuts
The commands I am using are standard go build and go test. Anyway, here is the complete output.

SDeoras@D8R6G12 MINGW64 ~/x/sWin (master)
$ go build
./


SDeoras@D8R6G12 MINGW64 ~/x/sWin (master)
$ which gcc
/c/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/gcc


SDeoras@D8R6G12 MINGW64 ~/x/sWin (master)
$ go test
-v
# testmain

C
:\Go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1

C
:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libntdll.a(dkbgs01971.o):(.idata$5+0x0): multiple definition of `__imp_sqrt'
C:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(dekes01190.o):(.idata$5+0x0): first defined here
C:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libntdll.a(dkbgs01966.o):(.idata$5+0x0): multiple definition of `
__imp_pow
'

C:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(dekes01161.o):(.idata$5+0x0): first defined here
C:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/program files/mingw-w64/x86_64-6.2.0-posix-seh-rt_v5-rev1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(dkbgs01971.o): illegal symbol index 116 in relocs
collect2.exe: error: ld returned 1 exit status


FAIL    _/C_/Users/SDeoras/x/sWin [build failed]


SDeoras@D8R6G12 MINGW64 ~/x/sWin (master)
$



On Wednesday, April 20, 2016 at 7:06:28 PM UTC-7, Dorival Pedroso wrote:

Dave Cheney

unread,
Jan 1, 2017, 2:46:45 PM1/1/17
to golang-nuts, saurabh...@gmail.com
Can you please post the output of go env.

What cgo libraries does your project use?

saurabh...@gmail.com

unread,
Jan 1, 2017, 2:58:14 PM1/1/17
to golang-nuts
$ go env
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\SDeor7119713\gocode
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\SDEOR7~1\AppData\Local\Temp\go-build176493662=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1

cgo is setup to use boost, pthread etc. along with archive built from my own code (-ls88). libs88.a uses another .a, which is where boost is being called.
// #cgo CFLAGS: -I${SRCDIR}/includes
// #cgo LDFLAGS: -Wl,-rpath,'$ORIGIN/lib/' -L${SRCDIR}/windows/amd64 -ls88 -lLogDump -lboost_system -lboost_date_time -lboost_thread -lboost_filesystem -lstdc++ -lm -lpthread
// #include <stdlib.h>
// #include <stdio.h>
// #include "s88.h"
import "C"

On Wednesday, April 20, 2016 at 7:06:28 PM UTC-7, Dorival Pedroso wrote:

Dave Cheney

unread,
Jan 1, 2017, 3:10:51 PM1/1/17
to golang-nuts, saurabh...@gmail.com
Is your library compiled in x86_64 mode, and boost? Do you need to set some -D flags to tell boost to be 64bit. I'm not a windows expert, but clearly sometime is triggering the 32bit compiler and you end up linking a blob of 32bit code into your 64bit program.

saurabh...@gmail.com

unread,
Jan 1, 2017, 3:18:28 PM1/1/17
to golang-nuts
Hi Dave, I was able to build a pure C++ project using same libraries and it linked and executed fine, so I assumed boost was ok (yes, I built boost from src on my system). However, linking the same using cgo is giving these errors.


On Wednesday, April 20, 2016 at 7:06:28 PM UTC-7, Dorival Pedroso wrote:

brainman

unread,
Jan 1, 2017, 3:40:56 PM1/1/17
to golang-nuts, saurabh...@gmail.com

saurabh...@gmail.com

unread,
Jan 4, 2017, 9:18:45 AM1/4/17
to golang-nuts, saurabh...@gmail.com
Ok, Let me try to see if I can repro the bug with a code that I can share.

Thank you,
Saurabh

saurabh...@gmail.com

unread,
Feb 5, 2017, 6:18:09 PM2/5/17
to golang-nuts
Hi Folks,

So some good news on the issue but still not out of woods. After getting rid of all statically built libs and replacing them by dll's, I was able to compile and link against GO code. So far so good, but when running a test I get an error code:
exit status 3221225781

getting closer :)
Saurabh


On Wednesday, April 20, 2016 at 7:06:28 PM UTC-7, Dorival Pedroso wrote:

saurabh...@gmail.com

unread,
Feb 5, 2017, 7:05:15 PM2/5/17
to golang-nuts
Hi Folks,

Putting dll's in the same folder as my GO code solved the problem as suggested here: https://github.com/veandco/go-sdl2

Thanks,
Saurabh

On Wednesday, April 20, 2016 at 7:06:28 PM UTC-7, Dorival Pedroso wrote:
Reply all
Reply to author
Forward
0 new messages