FAQ
Failure to static link go source with IUP

Using go language for MS Windows:
     go version go1.4.2 windows/386

Using IUP gui library from tecgraf:
         http://sourceforge.net/projects/iup/files/
     Dynamic version unzipped into c:\iup
         iup-3.15_Win32_dllw4_lib.zip
     Static version unzipped into c:\iupstc
         iup-3.15_Win32_mingw4_lib.zip

On Windows 8.1 (circa 2013)
With MinGW installed as c:\MinGW
     gcc version 4.6.2 (GCC)

MinGW is in the PATH variable

Very minimal go program using Iup (see source code farther down)

Dynamic linking works and resulting GUI program works
Uses these cgo directives:
     #cgo CFLAGS:-I c:/iup/include
     #cgo LDFLAGS:-Lc:/iup -liup

Static linking fails with message:
     C:\Go\pkg\tool\windows_386\8l.exe: symbol main listed multiple times
It used these cgo commands:
     #cgo CFLAGS:-I c:/iupstc/include
     #cgo LDFLAGS:c:/iupstc/libiup.a -lgdi32 -lcomdlg32 -lcomctl32 -luuid
-lole32

It appears that go produces a main function and that the windows API does
as well and they conflict. Why would the dynamic version avoid this and
the static not?
BTW a c language only version using Mingw DOES link statically and work.

What option do I need in the #cgo static directives to prevent this
happening?

The go source:

package main

/*
#cgo CFLAGS:-I c:/iup/include
#cgo LDFLAGS:-Lc:/iup -liup
#include "iup.h"
*/
import "C"

func main() {
   C.IupOpen(nil,nil)
   C.IupShow(C.IupDialog(C.IupLabel (C.CString("Hello, world!"))))
   C.IupMainLoop()
   C.IupClose()
}


--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Didier Spezia at Jul 17, 2015 at 5:18 pm
    Did you try:

    #cgo LDFLAGS:-Wl,-Bstatic -Lc:/iupstc -liup -Wl,-Bdynamic -lgdi32
    -lcomdlg32 -lcomctl32 -luuid -lole32

    ?

    See more information
    at: http://stackoverflow.com/questions/15852677/static-and-dynamic-shared-linking-with-mingw

    Regards,
    Didier.
    On Friday, July 17, 2015 at 5:07:57 AM UTC+2, wirthless wrote:

    Failure to static link go source with IUP

    Using go language for MS Windows:
    go version go1.4.2 windows/386

    Using IUP gui library from tecgraf:
    http://sourceforge.net/projects/iup/files/
    Dynamic version unzipped into c:\iup
    iup-3.15_Win32_dllw4_lib.zip
    Static version unzipped into c:\iupstc
    iup-3.15_Win32_mingw4_lib.zip

    On Windows 8.1 (circa 2013)
    With MinGW installed as c:\MinGW
    gcc version 4.6.2 (GCC)

    MinGW is in the PATH variable

    Very minimal go program using Iup (see source code farther down)

    Dynamic linking works and resulting GUI program works
    Uses these cgo directives:
    #cgo CFLAGS:-I c:/iup/include
    #cgo LDFLAGS:-Lc:/iup -liup

    Static linking fails with message:
    C:\Go\pkg\tool\windows_386\8l.exe: symbol main listed multiple times
    It used these cgo commands:
    #cgo CFLAGS:-I c:/iupstc/include
    #cgo LDFLAGS:c:/iupstc/libiup.a -lgdi32 -lcomdlg32 -lcomctl32 -luuid
    -lole32

    It appears that go produces a main function and that the windows API does
    as well and they conflict. Why would the dynamic version avoid this and
    the static not?
    BTW a c language only version using Mingw DOES link statically and work.

    What option do I need in the #cgo static directives to prevent this
    happening?

    The go source:

    package main

    /*
    #cgo CFLAGS:-I c:/iup/include
    #cgo LDFLAGS:-Lc:/iup -liup
    #include "iup.h"
    */
    import "C"

    func main() {
    C.IupOpen(nil,nil)
    C.IupShow(C.IupDialog(C.IupLabel (C.CString("Hello, world!"))))
    C.IupMainLoop()
    C.IupClose()
    }

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Wirthless at Jul 26, 2015 at 10:23 pm
    Thanks for the reply.

    Trying

    #cgo LDFLAGS:-Wl,-Bstatic -Lc:/iupstc -liup -Wl,-Bdynamic -lgdi32
    -lcomdlg32 -lcomctl32 -luuid -lole32

    gave multiple errors such as:
         main(.text): IupClose: not defined

    So I changed it to:

    #cgo LDFLAGS:-Wl,-Bstatic c:/iupstc/libiup.a -Wl,-Bdynamic -lgdi32
    -lcomdlg32 -lcomctl32 -luuid -lole32

    which got rid of the not-defined error but reintroduced the symbol
    main-listed-multiple-times

    Even more peculiar sometimes (I can't reproduce it) the error message game
    from c:\Go\pkg\tool\windows_386\8l.exe
    which I guess would be go's own linker.

    No doubt the main (or WinMain) from Iup is conflicting with go's main - but
    it is not a problem when libiup.dll is used
    (except I would have to distribute libiup.dll)

    The mingw cannot be blamed since the equivalent main.c works under mingq
    with libiup.a quite nicely - even when I hide the libiup.dll

    Am Most Perplexed


    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJul 17, '15 at 3:07a
activeJul 26, '15 at 10:23p
posts3
users2
websitegolang.org

2 users in discussion

Wirthless: 2 posts Didier Spezia: 1 post

People

Translate

site design / logo © 2022 Grokbase