Currently, I have the following source tree:
client
|
|--cryptlib
| |
| |--cryptlib.so
| |--cryptlib.a
| |--<C sources>
| |--Makefile
|
|--impl1
| |--<C sources>
| |--impl1.go
| |--impl1_test.go
|
|--impl2
| |--<C sources>
| |--impl2.go
| |--impl1_test.go
|
|--client.go
|--client_test.go
The cryptlib
library is used by both impl1
and impl2
and thus, both impl1.go
and impl2.go
start with the following cgo
block:
/*
#cgo CFLAGS: -I. -I${SRCDIR}/../cryptlib -L${SRCDIR}/../cryptlib -lcryptlib -Ofast
#cgo LDFLAGS: -L${SRCDIR}/../cryptlib -lcryptlib
*/
import "C"
And this works while trying to test impl1_test.go
and impl2_test.go
.
However, when trying to run the tests situated in client_test.go
, I keep getting errors claiming that the cryptlib
library could not be found. I think this may have to do with the fact that ${SRCDIR}
in this case is ./client
which makes the rest of the CFLAGS
and LDFLAGS
paths incorrect (./client/../cryptolib
).
Although it leads to repetition, I have also tried including cryptlib
into impl1
and impl2
. This approach again causes issues when trying to test client_test.go
since the combined binary now sees multiple instances of the same functions defined in cryptlib
.
How should I properly structure my source tree and cgo
flags such that all my .go
source files can find my cryptlib
library and compile?