actboy168/bee.lua

macOS 10.14.4 编译不通过

young40 opened this issue · 6 comments

➜  bee.lua git:(master) clang --version
Apple LLVM version 10.0.1 (clang-1001.0.46.3)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

ninja 1.9.0

➜  bee.lua git:(master) ninja -f ninja/macos.ninja
[89/89] build/macos/bin/bootstrap test/test.lua
FAILED: build/macos/_/test
build/macos/bin/bootstrap test/test.lua
build/macos/bin/bootstrap: error loading module 'bee.filesystem' from file 'build/macos/bin/bee.so':
	dlopen(build/macos/bin/bee.so, 6): Symbol not found: __ZNSt3__16__itoa8__u32toaEjPc
  Referenced from: build/macos/bin/bee.so
  Expected in: flat namespace
 in build/macos/bin/bee.so
stack traceback:
	[C]: in ?
	[C]: in function 'require'
	./test/test_platform.lua:49: in main chunk
	[C]: in function 'require'
	test/test.lua:21: in main chunk
	/Users/young40/Work/Lua/bee.lua/build/macos/bin/main.lua:24: in main chunk
	[C]: in ?
ninja: build stopped: subcommand failed.

1.我没有macos 10.4
2.欢迎提供pr

@actboy168

我从sumneko的lua-language-server过来的, 打算在macOS上编译一份lua的lsp server.

我今天研究了一下这个问题. 似乎是因为C++17引起的, 可能是macOS的自带的库不够新或者不够标准吧.

引起问题的代码是:
endpoint.cpp 里面的.

        std::to_chars(portstr.data(), portstr.data() + portstr.size() - 1, port);

去掉这一句, 就能正常加载bee.so

从这里找到的一个例子:
https://zh.cppreference.com/w/cpp/utility/to_chars

放到Xcode 10.2里面运行.
也是会报

Undefined symbols for architecture x86_64:
  "std::__1::__itoa::__u32toa(unsigned int, char*)", referenced from:
      std::__1::__itoa::__traits_base<unsigned int, void>::__convert(unsigned int, char*) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我对c++17和bee.lua不太熟, 也还没看明白这句std::to_chars的作用.

不知道大神能否换一种写法来实现to_chars的功能.

to_chars是有备选方案的,如果没有charconv就会使用。你的编译器显然是有charconv,但却在link时失败了。我觉得是你的编译环境有问题。

#if __has_include(<charconv>)
std::array<char, 10> portstr;
if (auto[p, ec] = std::to_chars(portstr.data(), portstr.data() + portstr.size() - 1, port); ec != std::errc()) {
return nonstd::make_unexpected(make_error_code(ec).message());
}
else {
p[0] = '\0';
}
auto info = gethostaddr(hint, ip, portstr.data());
#else
auto info = gethostaddr(hint, ip, bee::format("%d", port).c_str());
#endif

@actboy168

link也是成功的, 可以成功生成bee.so

失败的地方在运行单元测试失败了.
加载bee.so的时候失败了, 估计是macOS Runtime的问题.

还是非常感谢哈, 我再试一下不走charconv.
🙏

@actboy168

我把 charconv 部分去掉, 编译, 运行似乎一切正常.

也能把 lua-language-server 给编译出来的. 回头再尝试下运行.

非常感谢. 🙏

看起来clang对charconv的支持还不够好,我已经合并了你们的修改。如果仍然有问题,请让我知道。