Static library depends on self-built libc++, no longer compatible with libstdc++?

730 views
Skip to first unread message

Kenton Varda

unread,
Sep 8, 2017, 11:52:17 AM9/8/17
to v8-u...@googlegroups.com
Hi v8-users,

My C++ server app statically links against v8.

My build broke when updating from 6.0 to 6.1. It looks like V8 now pulls in and builds libc++ as part of its own build. However, no libc++.a is generated, nor are the libc++ objects included in the regular static library outputs. So, naturally, I get link errors.

I tried manually linking in the libc++ object files, but this reveals a second problem: I also link against the system-installed libprotobuf, which uses libstdc++. As libprotobuf uses std types in its ABI (my bad), this means my app needs to be linked against libstdc++ as well. I can't statically link against both C++ libs as this produces duplicate symbols.

Is there a recommended approach to take here? Can I tell v8 to use libstdc++? Or do I need to vendor in libprotobuf so that I can build everything against libc++ from here on out?

Thanks,
-Kenton

Zac Hansen

unread,
Sep 8, 2017, 5:57:33 PM9/8/17
to v8-users
I don't have an answer for your specific question, but I highly recommend dynamically linking to V8.   if nothing else it speeds up link times by quite a bit, from what I remember from a while ago when I switched over.

ken...@cloudflare.com

unread,
Sep 15, 2017, 2:52:32 PM9/15/17
to v8-users
I dynamically link in debug builds for the speed benefit, but for production deployments it is vastly easier to manage a statically-linked binary.

Moreover, if v8 is dynamically linking to a different C++ standard library / runtime than my main app, that is likely to cause some subtle problems since the two runtimes will be maintaining separate state. Dynamic linking only masks the issue.

-Kenton

Gang Chen

unread,
Sep 28, 2017, 10:55:08 AM9/28/17
to v8-users
I got the same issue when I wanted to build hello-world.cc using g++. And I ar .o files in buildtools/thirdparty/libc++ and libc++abi, then link those static libraries. It can work, however since I want to use std::regex functions in hello-world.cc, this program threw bad_cast and crashed.

Any help to address this issue?


在 2017年9月8日星期五 UTC+8下午11:52:17,Kenton Varda写道:

Fabio Kaminski

unread,
Sep 28, 2017, 3:48:02 PM9/28/17
to v8-users
Isnt this because its using "sysroot=.." and pointing to a custom compiler build?

If its using sysroot, just turn it off in the gyp files, and make the v8 compile with your local compiler toolchain.

At least it what i did here, after having some linking problems, and it worked fine for me..

I just dont recall in what gyp file is the sysroot var.. but you can also switch manually by passing the var when generating the
ninja files through gyp.. i guess with '-Dvar=value'

I think the gyp var is 'use_sysroot' or something like that

Kenton Varda

unread,
Sep 28, 2017, 5:56:18 PM9/28/17
to v8-u...@googlegroups.com
Thanks for the hint about use_sysroot! From there I was able to figure out a set of flags that make my build work again:

tools/dev/v8gen.py x64.release -- v8_static_library=true use_sysroot=false use_glib=false use_custom_libcxx=false

-Kenton

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/4B0zxSXulXE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages