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

LLVM库无法引入 #6445

Open
AI1379 opened this issue Feb 25, 2025 · 7 comments
Open

LLVM库无法引入 #6445

AI1379 opened this issue Feb 25, 2025 · 7 comments
Labels

Comments

@AI1379
Copy link

AI1379 commented Feb 25, 2025

Xmake 版本

xmake v2.9.8+20250225

操作系统版本和架构

Linux 5.15.167.4-microsoft-standard-WSL2 ArchWSL2

描述问题

无法引入LLVM库。尝试了多种方法均无法实现,或者有其他bug,比如找不到系统头文件等。

使用xrepo

// test.cpp
#include <cstdlib>
#include <iostream>

int main() {
  std::cout << "Hello, World!" << std::endl;
  return EXIT_SUCCESS;
}
-- xmake.lua
set_project("test")

set_version("1.0.0")

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

set_languages("c89", "cxxlatest")

add_requires("llvm", {kind = "library", configs = {mlir = true}})

target("test1")
    set_kind("binary")
    add_files("*.cpp")
    add_packages("llvm", {components = "mlir"})

此时会报错:

error: /usr/include/c++/14.2.1/cstdlib:79:15: fatal error: stdlib.h: No such file or directory
   79 | #include_next <stdlib.h>
      |               ^~~~~~~~~~
compilation terminated.
  > in test.cpp
warning: unknown component(mlir) in add_packages(llvm, {components = {mlir}})

删除xmake.lua中的add_packages后就恢复正常了。

此外,如果改为components = 'clang'就不会有这个warning,但是依然无法编译。

使用cmake

set_project("test")

set_version("1.0.0")

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

set_languages("c89", "cxxlatest")

add_requires(
    "cmake::LLVM",
    {
        alias = "llvm-dev",
        system = true
    }
)

target("test1")
    set_kind("binary")
    add_files("*.cpp")
    add_packages("llvm-dev")

此时运行xmake build -vD后会报错:

checking for platform ... linux
checking for architecture ... x86_64
checking for gcc ... /usr/sbin/gcc
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
checking for git ... /usr/sbin/git
checking for gzip ... /usr/sbin/gzip
checking for tar ... /usr/sbin/tar
finding LLVM from cmake ..
checking for cmake ... /usr/sbin/cmake
finding it from the generated CMakeLists.txt:
cmake_minimum_required(VERSION 3.31.5)
project(find_package)
find_package(LLVM REQUIRED )
if(LLVM_FOUND)
   add_executable(test_LLVM test.cpp)
   target_include_directories(test_LLVM PRIVATE LLVM_INCLUDE_DIR LLVM_INCLUDE_DIRS LLVM_INCLUDE_DIR LLVM_INCLUDE_DIRS)
   target_include_directories(test_LLVM PRIVATE LLVM_CXX_INCLUDE_DIRS)
   target_link_libraries(test_LLVM PRIVATE LLVM_LIBRARY LLVM_LIBRARIES LLVM_LIBS LLVM_LIBRARY LLVM_LIBRARIES LLVM_LIBS)
endif(LLVM_FOUND)

/usr/sbin/cmake /tmp/.xmake1000/250225/_B7C2144C07D9422084CDF1EA336CA050.dir
-- The C compiler identification is GNU 14.2.1
-- The CXX compiler identification is GNU 14.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/sbin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/sbin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAVE_FFI_CALL
-- Performing Test HAVE_FFI_CALL - Success
-- Found FFI: /usr/lib/libffi.so
-- Looking for histedit.h
-- Looking for histedit.h - found
-- Found LibEdit: /usr/include (found version "2.11")
-- Found ZLIB: /usr/lib/libz.so (found version "1.3.1")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found LibXml2: /usr/lib/libxml2.so (found version "2.13.6")
-- Found CURL: /usr/lib/libcurl.so (found version "8.12.1")
-- Configuring done (4.9s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp/.xmake1000/250225/_B7C2144C07D9422084CDF1EA336CA050.dir
finding includes from /tmp/.xmake1000/250225/_B7C2144C07D9422084CDF1EA336CA050.dir/CMakeFiles/test_LLVM.dir/flags.make
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.31

# compile CXX with /usr/sbin/c++
CXX_DEFINES = 

CXX_INCLUDES = 

CXX_FLAGS = -O3 -DNDEBUG


finding links from /tmp/.xmake1000/250225/_B7C2144C07D9422084CDF1EA336CA050.dir/CMakeFiles/test_LLVM.dir/link.txt
/usr/sbin/c++ -O3 -DNDEBUG -Wl,--dependency-file=CMakeFiles/test_LLVM.dir/link.d CMakeFiles/test_LLVM.dir/test.cpp.o -o test_LLVM

checking for cmake::LLVM ... no
note: the following packages were not found on your system, try again after installing them:
  -> cmake::LLVM latest
error: @programdir/core/main.lua:329: @programdir/core/sandbox/modules/import/core/base/task.lua:65: stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:1086]:
    [...modules/private/action/require/impl/install_packages.lua:790]: in function '_install_packages'
    [...modules/private/action/require/impl/install_packages.lua:852]:
    [@programdir/modules/private/action/require/install.lua:85]:
    [@programdir/actions/config/main.lua:390]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:246]:
    [@programdir/core/base/task.lua:504]: in function 'run'
    [@programdir/core/sandbox/modules/import/core/base/task.lua:63]: in function 'run'
    [@programdir/actions/build/main.lua:191]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:246]:
    [@programdir/core/base/task.lua:504]: in function 'run'
    [@programdir/core/main.lua:327]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:406]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:1075: in function 'base/os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:329: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:406: in function <@programdir/core/base/scheduler.lua:399>

然而,如果直接使用CMake:

cmake_minimum_required(VERSION 3.31.5)
project(find_package)
find_package(LLVM REQUIRED )
if(LLVM_FOUND)
   add_executable(test_LLVM test.cpp)
   message(STATUS "LLVM_INCLUDE_DIR: ${LLVM_INCLUDE_DIR}")
   target_include_directories(test_LLVM PRIVATE LLVM_INCLUDE_DIR LLVM_INCLUDE_DIRS LLVM_INCLUDE_DIR LLVM_INCLUDE_DIRS)
   target_include_directories(test_LLVM PRIVATE LLVM_CXX_INCLUDE_DIRS)
   target_link_libraries(test_LLVM PRIVATE LLVM_LIBRARY LLVM_LIBRARIES LLVM_LIBS LLVM_LIBRARY LLVM_LIBRARIES LLVM_LIBS)
endif(LLVM_FOUND)

此时可以正常输出:

-- The C compiler identification is GNU 14.2.1
-- The CXX compiler identification is GNU 14.2.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/sbin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/sbin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test HAVE_FFI_CALL
-- Performing Test HAVE_FFI_CALL - Success
-- Found FFI: /usr/lib/libffi.so
-- Looking for histedit.h
-- Looking for histedit.h - found
-- Found LibEdit: /usr/include (found version "2.11")
-- Found ZLIB: /usr/lib/libz.so (found version "1.3.1")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found LibXml2: /usr/lib/libxml2.so (found version "2.13.6")
-- Found CURL: /usr/lib/libcurl.so (found version "8.12.1")
-- Configuring done (5.3s)
-- Generating done (0.0s)

期待的结果

至少一项引入llvm的方式可用

工程配置

如上

附加信息和错误日志

如上

@AI1379 AI1379 added the bug label Feb 25, 2025
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: LLVM library cannot be imported

@star-hengxing
Copy link
Contributor

如果使用系统包管理的 llvm,可以直接 add_requires("llvm") 或者 add_requires("pacman::llvm")

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


If you use llvm managed by the system package, you can directly use add_requires("llvm") or add_requires("pacman::llvm")

@AI1379
Copy link
Author

AI1379 commented Feb 28, 2025

如果使用系统包管理的 llvm,可以直接 add_requires("llvm") 或者 add_requires("pacman::llvm")

这样确实可以暂时解决引入llvm的问题,但是还是没解决 cmake::LLVM 和 xrepo 那边的问题啊

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


If you use llvm managed by the system package, you can directly add_requires("llvm") or add_requires("pacman::llvm")

This can indeed temporarily solve the problem of introducing llvm, but it still does not solve the problem of cmake::LLVM and xrepo.

@star-hengxing
Copy link
Contributor

cmake::LLVM

cmake::xxx 是 hack 实现,大部分情况下不推荐使用。

xrepo::llvm

llvm 每次 ci 全量构建都会浪费很多时间,而且还需要懂打包的人来处理才行,暂时没这么多精力。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


cmake::LLVM

cmake::xxx is a hack implementation and is not recommended in most cases.

xrepo::llvm

llvm every time you build ci full amount, it will waste a lot of time, and it also requires people who know how to pack it to handle it. I don’t have so much energy for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants