altairwei / WizNotePlus

A community-driven cross-platform note-taking client.
https://altairwei.github.io/WizNotePlus/
Other
571 stars 88 forks source link

请教一下mac arm64下如何正确编译 #262

Open uxbug opened 2 weeks ago

uxbug commented 2 weeks ago

参考wiki提示错误

ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/WizNotePlus.app/Contents/MacOS/WizNotePlus] Error 1
make[1]: *** [src/CMakeFiles/WizNotePlus.dir/all] Error 2
make: *** [all] Error 2
ERROR: conanfile.py (WizNotePlus/2.12.0): Error in build() method, line 169
    cmake.build()
    ConanException: Error 2 while executing cmake --build '/Users/apple/WizNotePlus/_build/build' '--' '-j4'

另外好像wiki里写的conan现在的版本已经是v2了,得安装v1版本才可以正常走通流程,不过最后还是报如上错误。

altairwei commented 2 weeks ago

Qt 5 没有提供 MacOS ARM64 的预构建库,所以目前参考 WiKi 是搞不定的。除非你知道怎么从源代码编译 Qt5,然后更改 conan 的编译设置,最终才有可能编译出 ARM 版本的 WizNotePlus

uxbug commented 2 weeks ago

预构建库是指qtquick之类的动态库文件嘛?

$ file libqtquick2plugin.dylib
libqtquick2plugin.dylib: Mach-O 64-bit dynamically linked shared library arm64

我这些应该都是arm64的,是否只需修改conan的编译设置即可,有没有参考的修改点,之前没用过conan,还望指点一二 感谢。

altairwei commented 2 weeks ago

libqtquick2plugin.dylib 是其中之一,虽然 WizNotePlus 没用到。你试试通过 conan profile 命令改一下架构。

uxbug commented 2 weeks ago

感谢回复,以下是我的conan环境 在执行conan profile new default --detect自动检测环境之后 $ conan profile show default

[build_requires]
[settings]
    os=Macos
    os_build=Macos
    arch=armv8
    arch_build=armv8
    compiler=apple-clang
    compiler.version=14
    compiler.libcxx=libc++
    build_type=Release
[options]
[env]

我查了下网上说armv8在conan配置里就代表arm64,我通过 conan profile update setting.arch=arm64 && conan profile update setting.arch_build=arm64修改的话,conan就报错了。 还有没有其他地方需要修改的?

altairwei commented 2 weeks ago

那就不用改 conan profile 了,就用你默认的。参考 Wiki 构建一下,然后把日志贴出来,我看看停在哪了。

uxbug commented 2 weeks ago

那就不用改 conan profile 了,就用你默认的。参考 Wiki 构建一下,然后把日志贴出来,我看看停在哪了。

哈哈,感谢您几天来的解答,刚准备修改回复内容来着,已经找到原因了,是我太蠢了,一开始没有用arm架构的qt,然后忘记清理_build目录重新build了,删除_build之后重新build解决,非常感谢您提供这么好的plus版本哈哈

altairwei commented 2 weeks ago

那就不用改 conan profile 了,就用你默认的。参考 Wiki 构建一下,然后把日志贴出来,我看看停在哪了。

哈哈,感谢您几天来的解答,刚准备修改回复内容来着,已经找到原因了,是我太蠢了,一开始没有用arm架构的qt,然后忘记清理_build目录重新build了,删除_build之后重新build解决,非常感谢您提供这么好的plus版本哈哈

这就构建成功了?用的哪个版本的 Qt ?去哪找到的预构建好的 Qt 库?

uxbug commented 2 weeks ago

那就不用改 conan profile 了,就用你默认的。参考 Wiki 构建一下,然后把日志贴出来,我看看停在哪了。

哈哈,感谢您几天来的解答,刚准备修改回复内容来着,已经找到原因了,是我太蠢了,一开始没有用arm架构的qt,然后忘记清理_build目录重新build了,删除_build之后重新build解决,非常感谢您提供这么好的plus版本哈哈

这就构建成功了?用的哪个版本的 Qt ?去哪找到的预构建好的 Qt 库?

嗯嗯 成功了,已经可以秒开了,我看brew预编译的有arm版的哈哈 具体操作如下 以下步骤在Macos arm系统中操作

安装brew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

安装conan v1

brew install conan@1

安装qt5

brew install qt@5

修改~/.bashrc添加qt和conan的环境

如果~/.bashrc中已经有这些内容可省略这一步 vim ~/.bashrc 加入以下内容


# qt5 env
export PATH="/opt/homebrew/opt/qt@5/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/qt@5/lib"
export CPPFLAGS="-I/opt/homebrew/opt/qt@5/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/qt@5/lib/pkgconfig"

conan env

export PATH="/opt/homebrew/opt/conan@1/bin:$PATH"

后续参考您的官方wiki
然后在最后build时候执行
`export QT_INSTALL_PREFIX=/opt/homebrew/Cellar/qt@5/5.15.13_1 && ./.ci/build.sh $(pwd) $(pwd)/_build`
即可
成功编译输出大致如下

.... Copying OS X content bin/WizNotePlus.app/Contents/Resources/locales/qt_tr.qm Copying OS X content bin/WizNotePlus.app/Contents/Resources/locales/qt_sv.qm Copying OS X content bin/WizNotePlus.app/Contents/Resources/locales/qt_uk.qm Copying OS X content bin/WizNotePlus.app/Contents/Resources/locales/qt_zh_CN.qm Copying OS X content bin/WizNotePlus.app/Contents/Resources/locales/qt_zh_TW.qm Copying OS X content bin/WizNotePlus.app/Contents/Resources/locales/wiznote_zh_CN.qm Copying OS X content bin/WizNotePlus.app/Contents/Resources/locales/wiznote_zh_TW.qm Copying OS X content bin/WizNotePlus.app/Contents/Resources/wiznote.icns 3 warnings generated. [100%] Linking CXX executable ../bin/WizNotePlus.app/Contents/MacOS/WizNotePlus

`$ file /Applications/WizNotePlus.app/Contents/MacOS/WizNotePlus`

/Applications/WizNotePlus.app/Contents/MacOS/WizNotePlus: Mach-O 64-bit executable arm64


安装后需执行`xattr -rc /Applications/WizNotePlus.app`
补充一下还需执行`codesign --force --deep --sign - /Applications/WizNotePlus.app` 否则SIP打开的机器无法运行