1 // Copyright 2015 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // This test verifies that Go can access C variables
8 // in shared object file via cgo.
11 // intentionally write the same LDFLAGS differently
12 // to test correct handling of LDFLAGS.
13 #cgo windows CFLAGS: -DIMPORT_DLL
14 #cgo linux LDFLAGS: -L. -lcgosotest
15 #cgo dragonfly LDFLAGS: -L. -l cgosotest
16 #cgo freebsd LDFLAGS: -L. -l cgosotest
17 #cgo openbsd LDFLAGS: -L. -l cgosotest
18 #cgo solaris LDFLAGS: -L. -lcgosotest
19 #cgo netbsd LDFLAGS: -L. libcgosotest.so
20 #cgo darwin LDFLAGS: -L. libcgosotest.dylib
21 #cgo windows LDFLAGS: -L. libcgosotest.dll
25 const char* getVar() {
34 const want
= "Hello world"
35 got
:= C
.GoString(C
.getVar())
37 panic(fmt
.Sprintf("testExportedVar: got %q, but want %q", got
, want
))
39 got
= C
.GoString(C
.exported_var
)
41 panic(fmt
.Sprintf("testExportedVar: got %q, but want %q", got
, want
))