'Undefined symbols for architecture x86_64'

1,148 views
Skip to first unread message

gofire

unread,
Apr 6, 2015, 11:00:20 AM4/6/15
to golan...@googlegroups.com
 I am trying to use enet through C with cgo
package main

import(
/*
#include "enet.h"
*/
"C"
"fmt"
)

func main() {
if C.enet_initialize() != 0 {
fmt.Println("ok")
}
C.enet_deinitialize()
}

and i got this error

# command-line-arguments

Undefined symbols for architecture x86_64:

  "_enet_deinitialize", referenced from:

      __cgo_04342578f756_Cfunc_enet_deinitialize in cgo.cgo2.o

     (maybe you meant: __cgo_04342578f756_Cfunc_enet_deinitialize)

  "_enet_initialize", referenced from:

      __cgo_04342578f756_Cfunc_enet_initialize in cgo.cgo2.o

     (maybe you meant: __cgo_04342578f756_Cfunc_enet_initialize)

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)



Ian Lance Taylor

unread,
Apr 6, 2015, 11:51:07 AM4/6/15
to gofire, golang-nuts
I don't know what enet is, but you most likely need something like

#cgo LDFLAGS: -lenet

in the comment preceding "C". That is, you need to tell the linker to
link against the enet library.

Ian

alexandru...@gmail.com

unread,
Dec 21, 2016, 10:48:08 AM12/21/16
to golang-nuts
I just want to add that for mac/osx/darwin, in order to use an external framework with cgo and avoid this error you can do the following:

package main

// To import the CoreGraphics.framework
import (
   
// #cgo LDFLAGS: -framework CoreGraphics
   
// #include <CoreGraphics/CoreGraphics.h>
   
"C"
   
// other packages...
)

func main
() {
    display
:= C.CGMainDisplayID()
    fmt
.Println(display)
    fmt
.Println(C.CGDisplayCreateImage(display))
}

Reply all
Reply to author
Forward
0 new messages