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.a
22 #cgo aix LDFLAGS: -L. -l cgosotest
26 const char* getVar() {
35 const want = "Hello world"
36 got := C.GoString(C.getVar())
38 panic(fmt.Sprintf("testExportedVar: got %q, but want %q", got, want))
40 got = C.GoString(C.exported_var)
42 panic(fmt.Sprintf("testExportedVar: got %q, but want %q", got, want))