Using v8's clang-cl and libc++ on Windows

334 views
Skip to first unread message

Nikolas Kovacs

unread,
Aug 30, 2024, 1:34:52 PM8/30/24
to v8-users
Hi,
I am embedding v8 into my C++ application and I am trying to use a recent, stable version. I built 12.8 (e6286d70c55da94a8e12658918989b9b9dc325c8). 

I was unable to build with `use_custom_libcxx` set to false and I read online that MSVC support is mostly a nice-to-have. To use this, though, I believe I have to use the clang-cl and libc++ from the v8 build process to build my application that is embedding it.

So, I've been trying for a few weeks now to migrate. Things seem to be working mostly fine, but I am running into some build issues with my applications that I cannot resolve.

Below I am going to share some reproducible snippets of code and their errors. Hopefully someone will be able to put me in the right direction because I am very stuck.

I can't figure out how to put in code blocks, so please forgive the formatting.

# test.cpp
------------------

#include <stdexcept> #include <memory> int main() { throw std::runtime_error("Hello, World!"); // breaks std::make_shared<int>(2); // breaks std::make_unique<int>(2); // this is fine }

```
clang-cl.exe -v test.cpp -fuse-ld=lld /clang:-fexceptions /EHsc -I"W:\third_party\libcxx\include" -I"W:\third_party\libcxx\include.19" -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG "W:\third_party\libcxx\Debug\lib\libc++.dll.lib"
```
In the command above, the include directories are `//third_party/libc++/src/include` and `//third_party/llvm-build/Release+Asserts/lib/clang/19/lib/include` from the v8 project respectively.

The files `__assertion_handler` and `__config_site` were both copied into the first include dir from `//build_tools/third_party/libc++`

The errors:

```
 "W:\\VSSource\\repos\\ViciOnlineSDL2\\third_party\\clang\\lld-link" -out:test.exe "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.41.34120\\lib\\x64" "-libpath:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.41.34120\\atlmfc\\lib\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.26100.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.26100.0\\um\\x64" -nologo "C:\\Users\\kovac\\AppData\\Local\\Temp\\test-7eb16d.obj" "W:\\VSSource\\repos\\ViciOnlineSDL2\\third_party\\libcxx\\Debug\\lib\\libc++.dll.lib"
lld-link: error: undefined symbol: __declspec(dllimport) public: __cdecl std::runtime_error::runtime_error(char const *)
>>> referenced by C:\Users\kovac\AppData\Local\Temp\test-7eb16d.obj:(main)

lld-link: error: undefined symbol: public: __cdecl std::runtime_error::runtime_error(class std::runtime_error const &)
>>> referenced by C:\Users\kovac\AppData\Local\Temp\test-7eb16d.obj:(_CT??_R0?AVruntime_error@std@@@8??0runtime_error@std@@QEAA@AEBV01@@Z24)

lld-link: error: undefined symbol: public: virtual __cdecl std::runtime_error::~runtime_error(void)
>>> referenced by C:\Users\kovac\AppData\Local\Temp\test-7eb16d.obj:(_TI2?AVruntime_error@std@@)
clang-cl: error: linker command failed with exit code 1 (use -v to see invocation)
```

Nikolas Kovacs

unread,
Sep 8, 2024, 12:22:32 PM9/8/24
to v8-users

The solution was to add the `/Zc:dllexportsInlines-` flag

Ben Ernst

unread,
Sep 8, 2024, 3:10:38 PM9/8/24
to v8-u...@googlegroups.com

Following your experience. I understand MSVC support will soon be deprecated altogether, many of us will soon need to deal with some of these more intricate integration scenarios.

---
Sent from my Nokia 3310

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/fc1ace54-1f70-406f-b030-4779361a27efn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages