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

xmake对zig的支持有问题 #5963

Open
heheda123123 opened this issue Dec 13, 2024 · 13 comments
Open

xmake对zig的支持有问题 #5963

heheda123123 opened this issue Dec 13, 2024 · 13 comments
Labels

Comments

@heheda123123
Copy link
Contributor

Xmake 版本

v2.9.6+dev.ee024dc44

操作系统版本和架构

windows 11

描述问题

在xmake的文档中提到了三种用zig去编译c++项目的方式

$ xmake f --cc="zig cc" --cxx="zig cc" --ld="zig c++" -c
$ xmake

$ xmake f -p cross --cross=riscv64-linux-musl --toolchain=zig
$ xmake


$ xmake f --toolchain=zig -a arm64 -c
$ xmake

新建一个c++项目,尝试上面的方法,编译会报错

PS C:\Users\Administrator\temp\testzig> xmake f --cc="zig cc" --cxx="zig cc" --ld="zig c++" -c -v -D
checking for platform ... windows
checking for architecture ... x64
checking for cl.exe ... C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\bin\HostX64\x64\cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Microsoft C/C++ Compiler (x64) version ... 19.42.34435
checking for zig ... ok
checkinfo: cannot runv(nim.exe --version), No such file or directory
checking for nim ... no
checkinfo: cannot runv(nim.exe --version), No such file or directory
checking for nim ... no
checking for git ... ok
checkinfo: cannot runv(gzip.exe --version), No such file or directory
checking for gzip ... no
checking for 7z ... C:\Users\Administrator\xmake\winenv\bin\7z
git rev-parse HEAD
checking for zig ... no
checking for zig ... ok
checking for zig ... ok
checkinfo: info: Usage: zig [command] [options]

Commands:

  build            Build project from build.zig
  fetch            Copy a package into global cache and print its hash
  init             Initialize a Zig package in the current directory

  build-exe        Create executable from source or object files
  build-lib        Create library from source or object files
  build-obj        Create object from source or object files
  test             Perform unit testing
  run              Create executable and run immediately

  ast-check        Look for simple compile errors in any set of files
  fmt              Reformat Zig source into canonical form
  reduce           Minimize a bug report
  translate-c      Convert C code to Zig code

  ar               Use Zig as a drop-in archiver
  cc               Use Zig as a drop-in C compiler
  c++              Use Zig as a drop-in C++ compiler
  dlltool          Use Zig as a drop-in dlltool.exe
  lib              Use Zig as a drop-in lib.exe
  ranlib           Use Zig as a drop-in ranlib
  objcopy          Use Zig as a drop-in objcopy
  rc               Use Zig as a drop-in rc.exe

  env              Print lib path, std path, cache directory, and version
  help             Print this help and exit
  std              View standard library documentation in a browser
  libc             Display native libc paths file or validate one
  targets          List available compilation targets
  version          Print version number and exit
  zen              Print Zen of Zig and exit

General Options:

  -h, --help       Print command-specific usage

error: unknown command: c++.exe

checking for zig c++ ... ok
checking for the linker (ld) ... zig c++
checkinfo: info: Usage: zig [command] [options]

Commands:

  build            Build project from build.zig
  fetch            Copy a package into global cache and print its hash
  init             Initialize a Zig package in the current directory

  build-exe        Create executable from source or object files
  build-lib        Create library from source or object files
  build-obj        Create object from source or object files
  test             Perform unit testing
  run              Create executable and run immediately

  ast-check        Look for simple compile errors in any set of files
  fmt              Reformat Zig source into canonical form
  reduce           Minimize a bug report
  translate-c      Convert C code to Zig code

  ar               Use Zig as a drop-in archiver
  cc               Use Zig as a drop-in C compiler
  c++              Use Zig as a drop-in C++ compiler
  dlltool          Use Zig as a drop-in dlltool.exe
  lib              Use Zig as a drop-in lib.exe
  ranlib           Use Zig as a drop-in ranlib
  objcopy          Use Zig as a drop-in objcopy
  rc               Use Zig as a drop-in rc.exe

  env              Print lib path, std path, cache directory, and version
  help             Print this help and exit
  std              View standard library documentation in a browser
  libc             Display native libc paths file or validate one
  targets          List available compilation targets
  version          Print version number and exit
  zen              Print Zen of Zig and exit

General Options:

  -h, --help       Print command-specific usage

error: unknown command: c++.exe

checking for zig c++ ... ok
checking for the shared library linker (sh) ... zig c++
configure
{
    theme = default
    cxx = zig cc
    host = windows
    vs = 2022
    ndk_stdcxx = true
    cc = zig cc
    mode = release
    clean = true
    buildir = build
    network = public
    ld = zig c++
    ccache = true
    proxy = socks5://127.0.0.1:7890
    kind = static
    arch = x64
    proxy_pac = pac.lua
    plat = windows
}
PS C:\Users\Administrator\temp\testzig> xmake -v -D
checkinfo: info: Usage: zig [command] [options]

Commands:

  build            Build project from build.zig
  fetch            Copy a package into global cache and print its hash
  init             Initialize a Zig package in the current directory

  build-exe        Create executable from source or object files
  build-lib        Create library from source or object files
  build-obj        Create object from source or object files
  test             Perform unit testing
  run              Create executable and run immediately

  ast-check        Look for simple compile errors in any set of files
  fmt              Reformat Zig source into canonical form
  reduce           Minimize a bug report
  translate-c      Convert C code to Zig code

  ar               Use Zig as a drop-in archiver
  cc               Use Zig as a drop-in C compiler
  c++              Use Zig as a drop-in C++ compiler
  dlltool          Use Zig as a drop-in dlltool.exe
  lib              Use Zig as a drop-in lib.exe
  ranlib           Use Zig as a drop-in ranlib
  objcopy          Use Zig as a drop-in objcopy
  rc               Use Zig as a drop-in rc.exe

  env              Print lib path, std path, cache directory, and version
  help             Print this help and exit
  std              View standard library documentation in a browser
  libc             Display native libc paths file or validate one
  targets          List available compilation targets
  version          Print version number and exit
  zen              Print Zen of Zig and exit

General Options:

  -h, --help       Print command-specific usage

error: unknown command: c++.exe

checking for zig c++ ... ok
checking for the c++ compiler (cxx) ... zig c++
checkinfo: info: Usage: zig [command] [options]

Commands:

  build            Build project from build.zig
  fetch            Copy a package into global cache and print its hash
  init             Initialize a Zig package in the current directory

  build-exe        Create executable from source or object files
  build-lib        Create library from source or object files
  build-obj        Create object from source or object files
  test             Perform unit testing
  run              Create executable and run immediately

  ast-check        Look for simple compile errors in any set of files
  fmt              Reformat Zig source into canonical form
  reduce           Minimize a bug report
  translate-c      Convert C code to Zig code

  ar               Use Zig as a drop-in archiver
  cc               Use Zig as a drop-in C compiler
  c++              Use Zig as a drop-in C++ compiler
  dlltool          Use Zig as a drop-in dlltool.exe
  lib              Use Zig as a drop-in lib.exe
  ranlib           Use Zig as a drop-in ranlib
  objcopy          Use Zig as a drop-in objcopy
  rc               Use Zig as a drop-in rc.exe

  env              Print lib path, std path, cache directory, and version
  help             Print this help and exit
  std              View standard library documentation in a browser
  libc             Display native libc paths file or validate one
  targets          List available compilation targets
  version          Print version number and exit
  zen              Print Zen of Zig and exit

General Options:

  -h, --help       Print command-specific usage

error: unknown command: c++.exe

checking for zig c++ ... ok
checking for flags (-fvisibility-inlines-hidden) ... ok
> zig c++ "-fvisibility-inlines-hidden" "-target" "x86_64-windows-msvc"
checking for flags (-O3) ... ok
> zig c++ "-O3" "-target" "x86_64-windows-msvc"
checking for flags (-DNDEBUG) ... ok
> zig c++ "-DNDEBUG" "-target" "x86_64-windows-msvc"
[ 75%]: linking.release testzig.exe
"zig c++" -o build\windows\x64\release\testzig.exe build\.objs\testzig\windows\x64\release\src\main.cpp.obj -target x86_64-windows-msvc -s
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zigzig: : warning: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]zig:

zig: warning: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]zig:
warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: zig: warning: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]zig
argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]:
zigzig: warning: : zig: zigwarning: : argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]warning: warning: zig
warning: zig: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]

warning: zigzig
argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]: : argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]zig
warning: zig
warning: zig: : : argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]warning: warning: warning: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zigargument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zig: zig

: : warning: zig: zigwarning: warning: : argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]warning: zigargument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
warning: : argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]
zigzigargument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]warning: :
:
warning: zigargument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]warning: :
argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]zig: argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]warning: warning:

argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]argument unused during compilation: '-nostdinc++' [-Wunused-command-line-argument]

C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_typeinfo.cpp:16:12: error: C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_new_delete.cpp:57:32: cannot define or redeclare
      '~type_info' here because namespaceIn file included from error:  'std' C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/cxa_vector.cppdoes :nonot16  :
member nameddexcept.cpp
In file included from enclose C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxx\include/exception      namespace:'get_new_handler' 82:tion.cpp
In file included from C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxx\include/__exception/exception_ptr.h: 'type_info'21:private_typeinfo.cpp
├─ stdlib_new_delete.cpp
in namespaceIn file included from     C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxx\include/typeinfo16'std':73 |
:─ stdlib_exception.cpp
ty   pe_inC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_typeinfo.h57f: | o137:30:  : :~typerror:  e_ in
sf      totargetd(): of :
      | using declaration conflicts with declaration alreadyn~~~~~~~~~~~^
ew_handle C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_typeinfo.cpprin:22  nh scope:11:
=   137s  |  td :error:   _V:redefinitionCg of 'bad_cast'e
   RT22t_ | _nbadEe_Xwcast_POh:Ra:Tnd_STblD useaind_casrgt( ():) :;nto
      | ypee                          ~~~~~^_inf
xcepto;
      |
      |           ^
                             ^
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_typeinfo.h:151:5: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_typeinfo.h:74:24: note:
      previous definition is herenote:
  151 |     bad_cast()
      targetIn file included from C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_new_delete.cpp  of:nC:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/cxa_exception.cpp using declaration150o::
e1532   x:
: ce74In file included from pterror: C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxx\include/exception | :82:
In file included from C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxx\include/__exception/exception_ptr.h:
      _21:
In file included from C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxx\include/typeinfo:73VCRT_| :
noEX    ^
PC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_typeinfo.h:OR137:30:  TC:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_typeinfo.cpp:26member named
_S:      error: T11:D  'get_new_handler' in namespace 'std'C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp:class error:
      t17:targetyp12: of using declaration conflicts with declaration already in
edefinition In file included from   _ of implicitly
iscopeerror:
150      nC:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/cxa_noexception.cpp   |  f:redefinition of '~exception'17:
declared o
137 |     _VC    In file included from   R/17C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxx\include/exceptiondestructor T/ | :s_
 e82:
E   26xtIn file included from XExported C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxx\include/__exception/exception_ptr.hP | bab:21:
ddecause fIn file included from ::new_handC:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxx\include/typeinfo_cast::~bad_col:73:
ast() noexceptcrer nh = std::get_new_hC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_typeinfo.he
 Oa:p      tRT_t| yn137Sipd          ^
Toel:30: er()D using ::type_info;;
      | error: ni
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_typeinfo.cpp:d                             ^      |
      , MSVC looks for type_in                          ~~~~~^target
:31f
 of:11:  o:C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_typeinfo.husing ~:error:  declaration conflicts with74in t:out-of-linee declaration already in scopexh24 definition of
c
e: ep        'what' does not match any declarationnote:  tion(
 global namespac      in137) noexcepttarget  | e of using declaration

'std::bad_cast'
|
   |                         ^
74               ^ | _VCRT_EXPORT_2_31 | bad_cas errorVCRT_EXPORT_STD usins
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\include/cxxabi.h:tg generatedS30: .
TC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_exception.h:::::89:Dtype_27w13 c:h:info l a;asnote: t(s type_info )

note: //      | conflicting declaration        Exporprevious
c   t                              ^oned bec
30sdefinitiona | t iscC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_typeinfo.h u l:nsherea74oes:
e s24:xf    89 |  _LIBCXceptXor typeid, MSVC l  ABo
I_TYPo note:       E_V|
      vIktarget          ^~~~iS typs
rt of using declarationufeaC:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_typeinfo.cppo
_   :rli74 |   n38:t~f_13yeoV:pxception() noexcept
;Ce       // fo_error: | Rrward declarationredefinitionTinfo in the global namespace_EXPORT_S            ^

T
of            D | |  'bad_typeid'c                          ^
                       ^
lC:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp:21a
   :2438s: sC:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\include/cxxabi.h |  :bty30awarning: p:de27: _exception_:yi note: pnspecificationeifoconflicting   d:declarationin/[2] libcxxabi
├─ cxa_default_handlers.cpp
/b         30adeclaration  | d Eclax_doessptype soinot _LIrd Bt(matchCed X) becpreviousX a declaration uAnoeB[-Wmicrosoft-exception-spec]sxce fo.cpp
Ier _pttT   yexcept.cpp
      | pei            ^Y21d, M
P | coSEnC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_typeinfo.hV_s:174VtC:I  5Sch: la toryo* exception::pks fore_i twhnote: yna
      previous definition is fo; // forward decheret(lpe_a
)iratn   const noexc174ifepto | on
       i   n| pp
 bad_t                        ^
yt      phe global | eC:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_exception.hn                          ^:ia
94dm:(esp36) : noexcepanote: tce
      previousatexit.cpp
└─ cxa_exception_storage.cpp
             declaration| |  is                        ^1    ^here
 error generated

.
   94 |     _C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\include/cxxabi.hNOC:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_typeinfo.cpp:D:42I30:13:SCARD 27:v: ir tualerror: note:  chardefinitionconflicting   declarationofconst* what
(implicitly   ) 30
      declaredc |  onstdestructor
      c
| l   42a |                                    ^sbas
d _LIBC_C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cppXXABIt:_ypT21eY:id::~b24Pa:Ed__ typVIS typeerror: e_inredefinitionfi ofdo (;'what') no
   21 | /ec/xo cnseptforwart
       d c| deha            ^
r* exceptionC:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_typeinfo.cpp:47:13: c::wherror: larationout-of-line definition
       a| of
      'what't                          ^
() const noexcept does not match any declaration in 'std::bad_typeid'
      |
   47 | bad_typeid::what() const noexcept                       ^

      | C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_exception.h:94:36:             ^~~~
7 errors generated.
note:
      previous definition is here
   94 |     _NODISCARD virtual char const* what() const
      |                                    ^
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp:28:16: error: definition of implicitly
      declared destructor
   28 | bad_exce1p errorti generatedon::~b.
ad_exception() noexcept
      |                ^
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp:32:28: error: out-of-line definition of
      'what' does not match any declaration in 'std::bad_exception'
   32 | const char* bad_exception::what() const noexcept
      |                            ^~~~
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp:40:12: error: redefinition of 'bad_alloc'
   40 | bad_alloc::bad_alloc() noexcept
      | error: @programdir\core\main.lua:329: @programdir\actions\build\main.lua:148: @programdir\modules\async\runjobs.lua:325: @programdir\actions\build\kinds\binary.lua:53: @programdir\core\sandbox\modules\os.lua:378: execv(zig c++ -o build\windows\x64\release\testzig.exe build\.objs\testzig\windows\x64\release\src\main.cpp.obj -target x86_64-windows-msvc -s) failed(1)
           ^
stack traceback:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_exception.h:122:5: note:
      previous definition is here    [C]: in function 'error'

  122 |     bad_alloc() noexcept
      |     ^
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp:44:12: error: definition of implicitly
      declared destructor
   44 | bad_alloc::~bad_alloc() noexcept
      |            ^
    [@programdir\core\base\os.lua:1004]:
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp    [@programdir\core\sandbox\modules\os.lua:378]: in function 'execv'
:    [@programdir\modules\core\tools\gcc.lua:599]:
49    [C]: in function 'xpcall'
:12:     [@programdir\core\base\utils.lua:244]:
    [@programdir\core\tool\linker.lua:232]: in function 'link'
    [@programdir\actions\build\kinds\binary.lua:53]: in function 'callback'
    [@programdir\modules\core\project\depend.lua:217]: in function 'on_changed'
error:     [@programdir\actions\build\kinds\binary.lua:41]: in function '_do_link_target'
    [@programdir\actions\build\kinds\binary.lua:83]:
    [@programdir\actions\build\kinds\binary.lua:110]: in function '_link_target'
out-of-line definition of
    [@programdir\actions\build\kinds\binary.lua:138]: in function 'jobfunc'
          [@programdir\modules\async\runjobs.lua:241]:
    [C]: in function 'xpcall'
    [@programdir\core\base\utils.lua:244]: in function 'trycall'
    [@programdir\core\sandbox\modules\try.lua:117]: in function 'try'
    [@programdir\modules\async\runjobs.lua:224]: in function 'cotask'
    [@programdir\core\base\scheduler.lua:406]:
'what'
 stack traceback:
does    [C]: in function 'error'
        @programdir\core\base\os.lua:1004: in function 'base/os.raiselevel'
not match       (...tail calls...)
 any    @programdir\core\main.lua:329: in upvalue 'cotask'
declaration in  @programdir\core\base\scheduler.lua:406: in function <@programdir\core\base\scheduler.lua:399>
 'std::bad_alloc'
   49 | bad_alloc::what() const noexcept
      |            ^~~~
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp:56:23: error: redefinition of
      'bad_array_new_length'
   56 | bad_array_new_length::bad_array_new_length() noexcept
      |                       ^
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_exception.h:142:5: note:
      previous definition is here
  142 |     bad_array_new_length() noexcept
      |     ^
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp:56:23: error: constructor for
      'std::bad_array_new_length' must explicitly initialize the base class 'bad_alloc' which does not have a default
      constructor
   56 | bad_array_new_length::bad_array_new_length() noexcept
      |                       ^
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.42.34433\include/vcruntime_exception.h:117:24: note:

      'std::bad_alloc' declared here
  117 | _VCRT_EXPORT_STD class bad_alloc
      |                        ^
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp:60:23: error: definition of implicitly
      declared destructor
   60 | bad_array_new_length::~bad_array_new_length() noexcept
      |                       ^
C:\Users\Administrator\scoop\apps\zig\0.13.0\lib\libcxxabi\src/stdlib_exception.cpp:65:23: error: out-of-line definition of
      'what' does not match any declaration in 'std::bad_array_new_length'
   65 | bad_array_new_length::what() const noexcept
      |                       ^~~~
1 warning and 11 errors generated.
PS C:\Users\Administrator\temp\testzig>

但是如果手动去调用zig c++编译是没问题的

PS C:\Users\Administrator\temp\testzig\src> zig c++ -target aarch64-linux-gnu .\main.cpp -o main
PS C:\Users\Administrator\temp\testzig\src> file main
main: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 2.0.0, with debug_info, not stripped
PS C:\Users\Administrator\temp\testzig\src>

期待的结果

xmake正确调用zig进行交叉编译

工程配置

已提供

附加信息和错误日志

已提供

@Issues-translate-bot
Copy link

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


Title: xmake has a problem with zig support

@heheda123123
Copy link
Contributor Author

得这样明确指定p和a才行

xmake f --toolchain=zig -a arm64 -p mingw -a x86_64 -c

上面失败是因为 x86_64-windows-msvc 这个默认目标不行

@Issues-translate-bot
Copy link

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


You have to specify p and a clearly like this

xmake f --toolchain=zig -a arm64 -p mingw -a x86_64 -c

The above fails because the default target x86_64-windows-msvc does not work

@heheda123123
Copy link
Contributor Author

heheda123123 commented Dec 14, 2024

windows上gnu的libc可以用了,但是如果依赖是通过cmake构建的会提示zig c++不是可用的编译器
我单独写了个bat把zig c++包装起来,加到PATH里面,
但是xmake这边报错了,报错如下,是我的用法不对吗

PS C:\Users\Administrator\temp\testzig> xmake f --cc="zig cc" --cxx="myzig" --ld="myzig" -c -p mingw -a x86_64 -v -D
checking for mingw directory ... C:\me\tools\winlibs_mingw64
configure
{
    proxy = socks5://127.0.0.1:7890
    ld = myzig
    mingw = C:\me\tools\winlibs_mingw64
    network = public
    buildir = build
    cc = zig cc
    ccache = true
    kind = static
    theme = default
    mode = release
    proxy_pac = pac.lua
    plat = mingw
    arch = x86_64
    host = windows
    clean = true
    ndk_stdcxx = true
    cxx = myzig
}
PS C:\Users\Administrator\temp\testzig> xmake -v -D
error: @programdir\core\main.lua:329: @programdir\actions\build\main.lua:148: @programdir\modules\async\runjobs.lua:325: ...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37: cannot find known tool script for myzig
stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:1004]:
    [...amdir\core\sandbox\modules\import\core\tool\compiler.lua:37]: in function 'load'
    [@programdir\modules\private\action\build\object.lua:40]: in function 'script'
    [@programdir\modules\private\action\build\object.lua:122]: in function 'build_object'
    [@programdir\modules\private\action\build\object.lua:147]: in function 'jobfunc'
    [@programdir\modules\async\runjobs.lua:241]:

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:1004: in function '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>
PS C:\Users\Administrator\temp\testzig>

myzig.bat内容如下,单独用来编译程序是没问题的

@echo off
setlocal enabledelayedexpansion

rem Store the base command
set cmd=zig c++

rem Loop through all arguments and append them
set args=
for %%x in (%*) do (
    set args=!args! %%x
)

rem Execute the command with arguments
echo Executing: %cmd%%args%
%cmd%%args%


@heheda123123 heheda123123 reopened this Dec 14, 2024
@star-hengxing
Copy link
Contributor

See #5915

@heheda123123
Copy link
Contributor Author

如果我把bat改名为zig.bat。在PATH环境变量放到最前面,同时修改bat

@echo off
setlocal enabledelayedexpansion

rem Store the base command
set cmd=C:\Users\Administrator\scoop\shims\zig.EXE c++

rem Loop through all arguments and append them
set args=
for %%x in (%*) do (
    set args=!args! %%x
)

rem Execute the command with arguments
echo Executing: %cmd%%args%
%cmd%%args%

这样用,xmake的逻辑会很奇怪

xmake f --cxx="zig" --ld="zig" -c -p mingw -a x86_64 -v -D

xmake会拼接build-obj到zig后

@heheda123123
Copy link
Contributor Author

heheda123123 commented Dec 14, 2024

总结一下,windows下,xmake配合zig的问题
1 如果我用原样的zig去构建,指定cxx、ld等参数为 zig c++。当依赖是用cmake构建的时候就会出错 zig c++.exe is not a full path
2 如果我包装的bat名字不叫zig.bat。比如叫myzig.bat。 xmake直接会报错 cannot find known tool script for myzig
3 如果我包装的bat名字叫zig.bat。xmake构建的时候又会自动给zig命令后拼接build-obj,变成了zig c++ build-obj

如果手动指定了cxx、ld等参数是不是就应该原样传入

@waruqi
Copy link
Member

waruqi commented Dec 14, 2024

不要单独指定,走 toolchain=zig , 会有 wrapper

#5921
#5967

@heheda123123
Copy link
Contributor Author

更新到dev之后没问题了

@Issues-translate-bot
Copy link

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


After updating to dev, there is no problem

@heheda123123
Copy link
Contributor Author

heheda123123 commented Dec 15, 2024

使用dev分支

xmake f --toolchain=zig -p mingw -a x86_64 -c -v -D -v -D

创建一个c++项目,修改xmake.lua

add_rules("mode.debug", "mode.release")
add_requires("cpp-ipc master")
set_languages("cxx20")

target("testcppipc")
    set_kind("binary")
    add_files("src/*.cpp")

输出存在颜色相关的乱码
另外编译这个库也失败了
mutouyun/cpp-ipc#136
输出片段如下

checking for ping ... ok
pinging the host(github.com) ... 106 ms
git -c core.fsmonitor=false clean -d -f -x
Removing build_c858331d/
git -c core.fsmonitor=false reset --hard
HEAD is now at 2673453 Try to fix permission issues under linux
←[0mchecking for ninja ... ←[38;5;2;1mok←[0m
←[0mchecking for C:\Users\ADMINI~1\AppData\Local\Temp\.xmake\241215\zigcc\cc.cmd ... ←[38;5;2;1mok←[0m
←[0m←[2mchecking for the assember (as) ... ←[38;5;2;1mcc.cmd←[0m
←[0mchecking for C:\Users\ADMINI~1\AppData\Local\Temp\.xmake\241215\zigcc\ar.cmd ... ←[38;5;2;1mok←[0m
←[0m←[2mchecking for the static library archiver (ar) ... ←[38;5;2;1mar.cmd←[0m
←[0mchecking for C:\Users\ADMINI~1\AppData\Local\Temp\.xmake\241215\zigcc\ranlib.cmd ... ←[38;5;2;1mok←[0m
←[0m←[2mchecking for the archive index generator (ranlib) ... ←[38;5;2;1mranlib.cmd←[0m
←[0mchecking for C:\Users\ADMINI~1\AppData\Local\Temp\.xmake\241215\zigcc\c++.cmd ... ←[38;5;2;1mok←[0m
←[0m←[2mchecking for the shared library linker (sh) ... ←[38;5;2;1mc++.cmd←[0m
←[0mchecking for pkg-config ... ←[38;5;2;1mok←[0m
←[0mchecking for cmake ... ←[38;5;2;1mC:\Program Files\CMake\bin\cmake←[0m
←[0mchecking for pkg-config ... ←[38;5;2;1mok←[0m

@heheda123123 heheda123123 reopened this Dec 15, 2024
@waruqi
Copy link
Member

waruqi commented Dec 16, 2024

输出存在颜色相关的乱码

不清楚,如果是偶发的就暂时忽略,一些其他子进程也会 break 掉 console color code 导致乱码,比如 git submodule update 等,有些 case 避免不了。

另外编译这个库也失败了
mutouyun/cpp-ipc#136

这个跟 xmake 也没啥关系吧,另外包目前仅仅支持常规 gcc/clang/msvc 系切换,其他工具链,暂时没精力维护,ci 上也没压测过,是否编译通过,看你人品,你可以自己排查改进,这边没人力提供支持。

@Issues-translate-bot
Copy link

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


The output contains color-related garbled characters.

I'm not sure. If it's accidental, just ignore it for now. Some other sub-processes will also break the console color code and cause garbled characters, such as git submodule update, etc. Some cases cannot be avoided.

In addition, compiling this library also failed.
mutouyun/cpp-ipc#136

This has nothing to do with xmake. In addition, the package currently only supports regular gcc/clang/msvc system switching. I have no energy to maintain other tool chains for the time being, and there is no stress test on ci. Whether the compilation passes depends on your character. You can check and improve yourself.

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

4 participants