The problem you face is not actually about compiling shared libraries or executables, but about using cgo and trying to cross-compile. (Still, if you want a library, not an executable, package name shouldn't be
When cross-compiling, cgo is disabled by default. If you add the environment variable
CGO_ENABLED=1, then your example will work:
CGO_ENABLED=1 GOOS=darwin go build -o libdoubler.dylib -buildmode=c-shared doubler
Keep in mind that using cgo while cross-compiling will be cumbersome. You will need to make sure that C libraries for the target platform are ready on your host machine. If it is not really necessary, stay away from cgo. If you have to, then you may consider compiling on the target machine instead of dealing with the maintenance of cross-compiling with cgo.