Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS CLion xmake生成的cmakelists编译报错 #3074

Closed
wumo opened this issue Nov 17, 2022 · 5 comments
Closed

macOS CLion xmake生成的cmakelists编译报错 #3074

wumo opened this issue Nov 17, 2022 · 5 comments
Milestone

Comments

@wumo
Copy link

wumo commented Nov 17, 2022

Xmake 版本

2.7.3

操作系统版本和架构

macOS Ventura

描述问题

xmake生成范例项目代码,生成cmakelists.txt然后编译报错

期待的结果

正常编译运行

工程配置

add_rules("mode.debug", "mode.release")

target("lumos")
    set_kind("shared")
    add_files("src/interface.cpp")

target("lumos_demo")
    set_kind("binary")
    add_deps("lumos")
    add_files("src/main.cpp")

附加信息和错误日志

====================[ Build | lumos_demo | Debug ]==============================
"/Users/wumo/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/222.4345.21/CLion.app/Contents/bin/cmake/mac/bin/cmake" --build /Users/wumo/CLionProjects/lumos/cmake-build-debug --target lumos_demo -j 8
[0/1] Re-running CMake...
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/wumo/CLionProjects/lumos/cmake-build-debug
[1/2] Linking CXX shared library ../build/macosx/x86_64/release/liblumos.dylib
FAILED: ../build/macosx/x86_64/release/liblumos.dylib 
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -dynamiclib -Wl,-headerpad_max_install_names -target -isysroot -stdlib=libc++ -o ../build/macosx/x86_64/release/liblumos.dylib -install_name @rpath/liblumos.dylib CMakeFiles/lumos.dir/src/interface.cpp.o  -lz && :
clang: warning: argument unused during compilation: '-arch arm64' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-dynamiclib' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-stdlib=libc++' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-install_name @rpath/liblumos.dylib' [-Wunused-command-line-argument]
Undefined symbols for architecture arm64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
@wumo wumo added the bug label Nov 17, 2022
@waruqi
Copy link
Member

waruqi commented Nov 17, 2022

感觉跟 xmake 关系不大,xmake 已经正常生成了动态库 target

add_library(lumos SHARED "")

然后 cmake 添加了 -dynamiclib flag 来作为动态库去 link

但是被 clang 给忽略了,然后作为可执行程序去 link 了,所以报错。。

clang: warning: argument unused during compilation: '-dynamiclib' [-Wunused-command-line-argument]

我手动添加 -shared flag 以及 xmake 直接编译link 传的 -shared 都能正常过掉的。。

但是 cmake 里面 macosx 上编译动态库,传入的是 -dynamiclib 而不是 -shared,按理 -dynamiclib 也是应该等价可用的,但是现在被clang 忽略了。

反正要么是 cmake 的问题,要么是 clang 的问题,跟 xmake 好像没啥关系。。

@waruqi waruqi removed the bug label Nov 17, 2022
@waruqi waruqi transferred this issue from xmake-io/xmake-idea Nov 17, 2022
@wumo
Copy link
Author

wumo commented Nov 24, 2022

@waruqi 我发现只要注释掉

target_link_options(lumos PRIVATE
        -target
        -isysroot
        -stdlib=libc++
)

就可以成功链接

@wumo
Copy link
Author

wumo commented Nov 24, 2022

@waruqi
又试了几次,-target会导致 未定义符号_main,而-isysroot会导致找不到-lz

waruqi added a commit that referenced this issue Nov 25, 2022
@waruqi
Copy link
Member

waruqi commented Nov 25, 2022

应该可以了,更新到 dev 试试

xmake update -s dev

@waruqi waruqi added this to the v2.7.4 milestone Nov 25, 2022
@wumo
Copy link
Author

wumo commented Nov 25, 2022

@waruqi ok了

@waruqi waruqi closed this as completed Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants