cgo c++ linker

384 views
Skip to first unread message

Drew Wells

unread,
Dec 23, 2014, 4:05:13 PM12/23/14
to golan...@googlegroups.com
I'm statically linking to a C++11 lib.  This works fine on linux64, yosemite, and mavericks.  However, Mountain Lion is throwing some errors.  It appears that cgo is using the C linker instead of the C++ linker.  I've tried passing flags -ldflags='-extld g++' but am still running into problems linking.

Full log: http://bot.brew.sh/job/Homebrew%20Pull%20Requests/18753/version=mountain_lion/testReport/


==> go build -x -v -ldflags='-extld g++' -o dist/wt wt/main.go
WORK=/var/folders/4d/ppjsc3j14wdfybr0djt6rbww0000gn/T/go-build189208889
github.com/wellington/spritewell
mkdir -p $WORK/github.com/wellington/spritewell/_obj/
mkdir -p $WORK/github.com/wellington/
cd /private/tmp/wellington-RK3J1M/wellington-0.5.0/src/github.com/wellington/spritewell
/usr/local/Cellar/go/1.4/libexec/pkg/tool/darwin_amd64/6g -o $WORK/github.com/wellington/spritewell.a -trimpath $WORK -p github.com/wellington/spritewell -complete -D _/private/tmp/wellington-RK3J1M/wellington-0.5.0/src/github.com/wellington/spritewell -I $WORK -pack ./sprite.go
github.com/wellington/wellington/token
gopkg.in/fsnotify.v1
mkdir -p $WORK/gopkg.in/fsnotify.v1/_obj/
mkdir -p $WORK/gopkg.in/
cd /private/tmp/wellington-RK3J1M/wellington-0.5.0/src/gopkg.in/fsnotify.v1
/usr/local/Cellar/go/1.4/libexec/pkg/tool/darwin_amd64/6g -o $WORK/gopkg.in/fsnotify.v1.a -trimpath $WORK -p gopkg.in/fsnotify.v1 -complete -D _/private/tmp/wellington-RK3J1M/wellington-0.5.0/src/gopkg.in/fsnotify.v1 -I $WORK -pack ./fsnotify.go ./kqueue.go ./open_mode_darwin.go
mkdir -p $WORK/github.com/wellington/wellington/token/_obj/
mkdir -p $WORK/github.com/wellington/wellington/
cd /private/tmp/wellington-RK3J1M/wellington-0.5.0/src/github.com/wellington/wellington/token
/usr/local/Cellar/go/1.4/libexec/pkg/tool/darwin_amd64/6g -o $WORK/github.com/wellington/wellington/token.a -trimpath $WORK -p github.com/wellington/wellington/token -complete -D _/private/tmp/wellington-RK3J1M/wellington-0.5.0/src/github.com/wellington/wellington/token -I $WORK -pack ./token.go
github.com/wellington/wellington/lexer
mkdir -p $WORK/github.com/wellington/wellington/lexer/_obj/
cd /private/tmp/wellington-RK3J1M/wellington-0.5.0/src/github.com/wellington/wellington/lexer
/usr/local/Cellar/go/1.4/libexec/pkg/tool/darwin_amd64/6g -o $WORK/github.com/wellington/wellington/lexer.a -trimpath $WORK -p github.com/wellington/wellington/lexer -complete -D _/private/tmp/wellington-RK3J1M/wellington-0.5.0/src/github.com/wellington/wellington/lexer -I $WORK -I /private/tmp/wellington-RK3J1M/wellington-0.5.0/pkg/darwin_amd64 -pack ./lexer.go
github.com/wellington/wellington/context
mkdir -p $WORK/github.com/wellington/wellington/context/_obj/
cd /private/tmp/wellington-RK3J1M/wellington-0.5.0/src/github.com/wellington/wellington/context
pkg-config --cflags --cflags libsass
pkg-config --libs --cflags libsass
CGO_LDFLAGS="-g" "-O2" "-lsass" "-lstdc++" "-lm" "-I/private/tmp/wellington-RK3J1M/wellington-0.5.0/libsass/include" "-L/private/tmp/wellington-RK3J1M/wellington-0.5.0/libsass/lib" "-lsass" /usr/local/Cellar/go/1.4/libexec/pkg/tool/darwin_amd64/cgo -objdir $WORK/github.com/wellington/wellington/context/_obj/ -- -I/private/tmp/wellington-RK3J1M/wellington-0.5.0/libsass/include -I $WORK/github.com/wellington/wellington/context/_obj/ context.go encoding.go export.go
/usr/local/Cellar/go/1.4/libexec/pkg/tool/darwin_amd64/6c -F -V -w -trimpath $WORK -I $WORK/github.com/wellington/wellington/context/_obj/ -I /usr/local/Cellar/go/1.4/libexec/pkg/darwin_amd64 -o $WORK/github.com/wellington/wellington/context/_obj/_cgo_defun.6 -D GOOS_darwin -D GOARCH_amd64 $WORK/github.com/wellington/wellington/context/_obj/_cgo_defun.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common -print-libgcc-file-name
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common -I/private/tmp/wellington-RK3J1M/wellington-0.5.0/libsass/include -I $WORK/github.com/wellington/wellington/context/_obj/ -g -O2 -o $WORK/github.com/wellington/wellington/context/_obj/_cgo_main.o -c $WORK/github.com/wellington/wellington/context/_obj/_cgo_main.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common -I/private/tmp/wellington-RK3J1M/wellington-0.5.0/libsass/include -I $WORK/github.com/wellington/wellington/context/_obj/ -g -O2 -o $WORK/github.com/wellington/wellington/context/_obj/_cgo_export.o -c $WORK/github.com/wellington/wellington/context/_obj/_cgo_export.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common -I/private/tmp/wellington-RK3J1M/wellington-0.5.0/libsass/include -I $WORK/github.com/wellington/wellington/context/_obj/ -g -O2 -o $WORK/github.com/wellington/wellington/context/_obj/context.cgo2.o -c $WORK/github.com/wellington/wellington/context/_obj/context.cgo2.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common -I/private/tmp/wellington-RK3J1M/wellington-0.5.0/libsass/include -I $WORK/github.com/wellington/wellington/context/_obj/ -g -O2 -o $WORK/github.com/wellington/wellington/context/_obj/encoding.cgo2.o -c $WORK/github.com/wellington/wellington/context/_obj/encoding.cgo2.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common -I/private/tmp/wellington-RK3J1M/wellington-0.5.0/libsass/include -I $WORK/github.com/wellington/wellington/context/_obj/ -g -O2 -o $WORK/github.com/wellington/wellington/context/_obj/export.cgo2.o -c $WORK/github.com/wellington/wellington/context/_obj/export.cgo2.c
clang -I . -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common -o $WORK/github.com/wellington/wellington/context/_obj/_cgo_.o $WORK/github.com/wellington/wellington/context/_obj/_cgo_main.o $WORK/github.com/wellington/wellington/context/_obj/_cgo_export.o $WORK/github.com/wellington/wellington/context/_obj/context.cgo2.o $WORK/github.com/wellington/wellington/context/_obj/encoding.cgo2.o $WORK/github.com/wellington/wellington/context/_obj/export.cgo2.o -g -O2 -lsass -lstdc++ -lm -I/private/tmp/wellington-RK3J1M/wellington-0.5.0/libsass/include -L/private/tmp/wellington-RK3J1M/wellington-0.5.0/libsass/lib -lsass
# github.com/wellington/wellington/context
Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find_last_of(char const*, unsigned long, unsigned long) const"

andrey mirtchovski

unread,
Dec 23, 2014, 4:18:04 PM12/23/14
to Drew Wells, golang-nuts
try -mmacosx-version-min=10.y where "y" is the minor version where the
C++ file was compiled. this assumes y less than your current version.
you can also try exporting MACOSX_DEPLOYMENT_TARGET=10.y before a
build, but that would require that you install the relevant SDK for
that OSX version.

for reference, i was getting similar errors with a 10.8 binary on 10.10:

Undefined symbols for architecture x86_64:
"std::string::find_last_of(char, unsigned long) const", referenced
from: llvm::UpgradeIntrinsicFunction(llvm::Function*,
llvm::Function*&) in [...]

Drew Wells

unread,
Dec 23, 2014, 4:59:44 PM12/23/14
to golan...@googlegroups.com, drew.w...@gmail.com
C lib and Go library are being built on the same machine if that makes a difference.

andrey mirtchovski

unread,
Dec 23, 2014, 6:24:03 PM12/23/14
to Drew Wells, golang-nuts

In my case the C++ lib was built on an older box. Do you have the same issue building a C++ program that uses the same lib (preferably with clang)?

Drew Wells

unread,
Dec 24, 2014, 1:17:06 AM12/24/14
to golan...@googlegroups.com, drew.w...@gmail.com
I haven't tried that.  I'm still pretty sure this is a matter of specifying the write linker on ML.  brew is apparently doing some overrides to enable c++11 (not the default on mountain lion).  I need those same overrides applied to cgo.

Drew Wells

unread,
Dec 25, 2014, 1:50:42 PM12/25/14
to golan...@googlegroups.com
This forced the c++11 linker to be used.

Reply all
Reply to author
Forward
0 new messages