Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: windows 7; cgo compile link error #6733

Closed
gopherbot opened this issue Nov 7, 2013 · 8 comments
Closed

cmd/go: windows 7; cgo compile link error #6733

gopherbot opened this issue Nov 7, 2013 · 8 comments

Comments

@gopherbot
Copy link

by anwar.root:

D:\0go\src\astyle>dir
2013/11/07  16:42    <DIR>          .
2013/11/07  16:42    <DIR>          ..
2013/11/02  04:31             4,946 ASLocalizer.h
2013/11/07  16:26             1,236 astyle.go
2013/11/02  04:31            35,358 astyle.h
2013/11/07  14:46             7,212 AstyleFormat.cpp
2013/09/29  09:38               168 AstyleFormat.h
2013/09/29  09:40               326 AstyleFormatCppExprot.cpp
2013/09/29  09:40               234 AstyleFormatCppExprot.h
2013/11/07  14:51            19,046 astyle_main.h
2013/11/07  16:46           358,844 libastyle.a

D:\0go\src\astyle>go version
go version go1.2rc3 windows/amd64

D:\0go\src\astyle>go build    ------> build package is ok 

D:\0go\src\use_astyle>go build astyleExample.go    ------>   Generation program
'astyleExample.go' can not be linked through
# command-line-arguments
__cxa_pure_virtual(0): not defined
_ZTVN10__cxxabiv120__si_class_type_infoE(0): not defined
_ZTVN10__cxxabiv117__class_type_infoE(0): not defined
__gxx_personality_seh0(0): not defined
_ZNSt8ios_base4InitC1Ev(0): not defined
_ZNSi5seekgESt4fposIiE(0): not defined
_ZNSi5tellgEv(0): not defined
_ZNSi3getEv(0): not defined
_ZNSi4peekEv(0): not defined
_ZNSs6appendEyc(0): not defined
_ZNSi3getERc(0): not defined
_ZNSs9_M_mutateEyyy(0): not defined
_ZNSt8ios_base4InitD1Ev(0): not defined
_ZNSo5flushEv(0): not defined
_ZdaPv(0): not defined
_ZNSdD2Ev(0): not defined
_ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEED1Ev(0): not defined
_ZNSt18basic_stringstreamIcSt11char_traitsIcESaIcEED1Ev(0): not defined
_ZNSt19basic_istringstreamIcSt11char_traitsIcESaIcEED1Ev(0): not defined
_ZN6astyle9ASOptions15getOptionErrorsEv(0): not defined
_ZN6astyle11ASFormatterD1Ev(0): not defined
too many errors

D:\0go\src\use_astyle>dir
2013/11/07  16:56    <DIR>          .
2013/11/07  16:56    <DIR>          ..
2013/11/07  16:56         2,281,984 astyleExample.exe    ------>  But the binary file
has been generated
2013/11/07  15:31               113 astyleExample.go

D:\0go\src\use_astyle>astyleExample.exe       
panic: invalid memory address or nil pointer dereference
fatal error: panic during malloc
[signal 0xc0000005 code=0x0 addr=0x50 pc=0x41d27a]

runtime stack:


astyle.go
++++++++++++++++++++++++++++++++++++
package astyle

// #cgo windows LDFLAGS: -L. -fpermissive  -static -lws2_32 -lmingwex -lmingw32 -lwinmm
-mwindows -lpthread -lastyle  -lm -mthreads
// #cgo windows CFLAGS: -I. -fno-stack-check -fno-stack-protector -mno-stack-arg-probe
-Wall -Werror
// #include <stdlib.h>
// #include <string.h>
// #include "AstyleFormatCppExprot.h"
import "C"
import "unsafe"

func FormatCode(fileName string) int {
    cFileName := C.CString(fileName)
    ret := C.astyleCodeFormat(cFileName)
    C.free(unsafe.Pointer(cFileName))
    return int(ret)
}

func GoFormatCode(file, buf string) int {
    cFile := C.CString(file)
    cBuf := C.CString(buf)
    ret := C.goAstyleCodeFormat(cFile, cBuf)
    C.free(unsafe.Pointer(cFile))
    C.free(unsafe.Pointer(cBuf))
    return int(ret)
}

func GoOutFormatCode(buf string) string {
    cBuf := C.CString(buf)
    defer C.free(unsafe.Pointer(cBuf))
    ret := C.goOutAstyleCodeFormat(cBuf)
    gRet:=C.GoString(ret)
    defer C.free(unsafe.Pointer(ret))
    return gRet
}

astyleExample.go
+++++++++++++++++++++++++++++++++
package main

import (
    "astyle"
    "fmt"
)

func main() {
    a := astyle.GoOutFormatCode("printf("ok");")
    fmt.Println(a)
}

Attachments:

  1. win_cgo_error.rar (622561 bytes)
@ianlancetaylor
Copy link
Contributor

Comment 1:

Isn't this exactly the same as issue #6731, which you filed, and which was closed as
working as intended?

@gopherbot
Copy link
Author

Comment 2 by anwar.root:

Short description:
As issue #6731, Package and import the package is mixed, ie, the golang program direct
call cgo!
As this issue, Package and import the package separatel, this package uses cgo way!
Describe the problem differences:
As issue #6731, 'test.go' is the main entrance of the program, not a golang package; I am
currently on golang learning to know is that a program with a main entrance, 
Compile with program names, such as 'go build test.go' should be passed, but the windows
platform is not compiled; while the Linux platform is good! (Package and import the
package separatel, this package uses cgo way!)
As this issue, build package is ok; but import this package, links can not pass!
(Package and import the package separatel, this package uses cgo way )

@ianlancetaylor
Copy link
Contributor

Comment 3:

I really can't tell whether this is a bug or not.

Labels changed: added os-windows.

@gopherbot
Copy link
Author

Comment 4 by zhangchenyu2009:

I have same problem on windows 7,while build a source import a CGO package.  source is
at github.com/zhcy/xls. Build ok on os 10.7(lion), I changed the CGO ldflag and CFLAGS
according to the windows env, but  build failed on windows 7.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 5:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 6:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 7:

Labels changed: added repo-main.

@davecheney
Copy link
Contributor

Comment 8:

This issue appears identical to 6731. In both issues you are using go build incorrectly.
There may be a separate issue for the go tool producing a binary even when compilation
is aborted. If this is the case please open a new issue stating this clearly.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants