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. 4 5package cgosotest 6 7// This test verifies that Go can access C variables 8// in shared object file via cgo. 9 10/* 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 23 24#include "cgoso_c.h" 25 26const char* getVar() { 27 return exported_var; 28} 29*/ 30import "C" 31 32import "fmt" 33 34func Test() { 35 const want = "Hello world" 36 got := C.GoString(C.getVar()) 37 if got != want { 38 panic(fmt.Sprintf("testExportedVar: got %q, but want %q", got, want)) 39 } 40 got = C.GoString(C.exported_var) 41 if got != want { 42 panic(fmt.Sprintf("testExportedVar: got %q, but want %q", got, want)) 43 } 44} 45