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

zig example program fail to link #3056

Closed
glyh opened this issue Nov 14, 2022 · 10 comments
Closed

zig example program fail to link #3056

glyh opened this issue Nov 14, 2022 · 10 comments
Labels
Milestone

Comments

@glyh
Copy link

glyh commented Nov 14, 2022

Xmake Version

v2.7.3+master.b448e00

Operating System Version and Architecture

Linux archlinux 6.0.2-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Sat, 15 Oct 2022 14:00:51 +0000 x86_64 GNU/Linux

Describe Bug

To reproduce:
1.xmake create -l zig -t console test
2. cd test
3. xmake

Expected Behavior

Link successfully

Project Configuration

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

target("test")
    set_kind("binary")
    add_files("src/*.zig")

--
-- If you want to known more usage about xmake, please see https://xmake.io
--
-- ## FAQ
--
-- You can enter the project directory firstly before building project.
--
--   $ cd projectdir
--
-- 1. How to build project?
--
--   $ xmake
--
-- 2. How to configure project?
--
--   $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
--
-- 3. Where is the build output directory?
--
--   The default output directory is `./build` and you can configure the output directory.
--
--   $ xmake f -o outputdir
--   $ xmake
--
-- 4. How to run and debug target after building project?
--
--   $ xmake run [targetname]
--   $ xmake run -d [targetname]
--
-- 5. How to install target to the system directory or other output directory?
--
--   $ xmake install
--   $ xmake install -o installdir
--
-- 6. Add some frequently-used compilation flags in xmake.lua
--
-- @code
--    -- add debug and release modes
--    add_rules("mode.debug", "mode.release")
--
--    -- add macro defination
--    add_defines("NDEBUG", "_GNU_SOURCE=1")
--
--    -- set warning all as error
--    set_warnings("all", "error")
--
--    -- set language: c99, c++11
--    set_languages("c99", "c++11")
--
--    -- set optimization: none, faster, fastest, smallest
--    set_optimize("fastest")
--
--    -- add include search directories
--    add_includedirs("/usr/include", "/usr/local/include")
--
--    -- add link libraries and search directories
--    add_links("tbox")
--    add_linkdirs("/usr/local/lib", "/usr/lib")
--
--    -- add system link libraries
--    add_syslinks("z", "pthread")
--
--    -- add compilation and link flags
--    add_cxflags("-stdnolib", "-fno-strict-aliasing")
--    add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
--
-- @endcode
--

Additional Information and Error Logs

zig version:

0.11.0-dev.43+b2f8c1f2e

log:

/usr/bin/zig build-exe -target x86_64-linux-gnu --strip -femit-bin=build/linux/x86_64/release/test build/.objs/test/linux/x86_64/release/src/main.zig.o build/.objs/test/linux/x86_64/release/src/test.zig.o
error: @programdir/modules/private/async/runjobs.lua:256: @programdir/actions/build/kinds/binary.lua:74: @programdir/core/sandbox/modules/os.lua:267: error: unrecognized parameter: '--strip'

stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:897]:
    [@programdir/core/sandbox/modules/os.lua:267]: in function 'runv'
    [@programdir/modules/core/tools/zig.lua:119]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:280]:
    [@programdir/actions/build/kinds/binary.lua:74]: in function 'callback'
    [@programdir/modules/core/project/depend.lua:193]: in function 'on_changed'
    [@programdir/actions/build/kinds/binary.lua:55]: in function '_do_link_target'
    [@programdir/actions/build/kinds/binary.lua:102]:
    [@programdir/actions/build/kinds/binary.lua:129]: in function '_link_target'
    [@programdir/actions/build/kinds/binary.lua:157]: in function 'jobfunc'
    [@programdir/modules/private/async/runjobs.lua:232]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:280]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/private/async/runjobs.lua:218]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:404]:

stack traceback:
	[C]: in function 'error'
	@programdir/core/base/os.lua:897: in function 'base/os.raiselevel'
	(...tail calls...)
	@programdir/modules/private/async/runjobs.lua:256: in field 'catch'
	@programdir/core/sandbox/modules/try.lua:123: in global 'try'
	@programdir/modules/private/async/runjobs.lua:218: in upvalue 'cotask'
	@programdir/core/base/scheduler.lua:404: in function <@programdir/core/base/scheduler.lua:397>
@glyh glyh added the bug label Nov 14, 2022
@waruqi
Copy link
Member

waruqi commented Nov 14, 2022

There is no longer a --strip flag after zig 0.9, but 0.7.1 works.

I've improved it, try again.

xmake update -s dev

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

glyh commented Nov 14, 2022

error: unzip or 7zip not found! we need install it first

It says I don't have unzip or 7zip, but I have them on my system.

> which unzip 
/sbin/unzip
> which 7z
/sbin/7z

Also AUR package xmake-git and xmake-dev-git is not working for me...

@waruqi
Copy link
Member

waruqi commented Nov 14, 2022

Only xmake installed from one-line script supports xmake update self-updating.

bash <(curl -fsSL https://xmake.io/shget.text) dev
source ~/.xmake/profile

@glyh
Copy link
Author

glyh commented Nov 14, 2022

Yeah it's working now for me, thank you for your patience.

@glyh glyh closed this as completed Nov 14, 2022
@glyh
Copy link
Author

glyh commented Jan 5, 2023

It's failing again.

@glyh glyh reopened this Jan 5, 2023
@waruqi
Copy link
Member

waruqi commented Jan 5, 2023

please provide logs

@glyh
Copy link
Author

glyh commented Jan 5, 2023

Xmake version: 2.7.4+dev.cea8d57

checking for platform ... linux
checking for architecture ... x86_64
checking for gcc ... /usr/bin/gcc
checkinfo: cannot runv(dmd --version), No such file or directory
checking for dmd ... no
checkinfo: cannot runv(ldc2 --version), No such file or directory
checking for ldc2 ... no
checkinfo: cannot runv(gdc --version), No such file or directory
checking for gdc ... no
checking for zig ... /usr/bin/zig
checking for /usr/bin/zig ... ok
checking for the zig compiler (zc) ... zig
checking for /usr/bin/zig ... ok
checking for the zig compiler (zc) ... zig
checking for flags (-O ReleaseFast) ... ok
> zig "-O" "ReleaseFast" "-target" "x86_64-linux-gnu"
checking for flags (--cache-dir build/.objs/a/linux/x86_64/release/zig-cache) ... ok
> zig "--cache-dir" "build/.objs/a/linux/x86_64/release/zig-cache" "-target" "x86_64-linux-gnu"
[ 20%]: compiling.release src/test.zig
/usr/bin/zig build-obj -target x86_64-linux-gnu -O ReleaseFast --cache-dir build/.objs/a/linux/x86_64/release/zig-cache -femit-bin=build/.objs/a/linux/x86_64/release/src/test.zig.o src/test.zig
[ 20%]: compiling.release src/main.zig
/usr/bin/zig build-obj -target x86_64-linux-gnu -O ReleaseFast --cache-dir build/.objs/a/linux/x86_64/release/zig-cache -femit-bin=build/.objs/a/linux/x86_64/release/src/main.zig.o src/main.zig
checking for /usr/bin/zig ... ok
checking for the zig linker (zcld) ... zig
[ 60%]: linking.release a
/usr/bin/zig build-exe -target x86_64-linux-gnu -fstrip -dead_strip -femit-bin=build/linux/x86_64/release/a build/.objs/a/linux/x86_64/release/src/test.zig.o build/.objs/a/linux/x86_64/release/src/main.zig.o
error: @programdir/modules/private/async/runjobs.lua:256: @programdir/actions/build/kinds/binary.lua:74: @programdir/core/sandbox/modules/os.lua:267: error: unrecognized parameter: '-fstrip'

stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:897]:
    [@programdir/core/sandbox/modules/os.lua:267]: in function 'runv'
    [@programdir/modules/core/tools/zig.lua:119]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:280]:
    [@programdir/actions/build/kinds/binary.lua:74]: in function 'callback'
    [@programdir/modules/core/project/depend.lua:193]: in function 'on_changed'
    [@programdir/actions/build/kinds/binary.lua:55]: in function '_do_link_target'
    [@programdir/actions/build/kinds/binary.lua:102]:
    [@programdir/actions/build/kinds/binary.lua:129]: in function '_link_target'
    [@programdir/actions/build/kinds/binary.lua:157]: in function 'jobfunc'
    [@programdir/modules/private/async/runjobs.lua:232]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:280]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/private/async/runjobs.lua:218]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:404]:

stack traceback:
	[C]: in function 'error'
	@programdir/core/base/os.lua:897: in function 'base/os.raiselevel'
	(...tail calls...)
	@programdir/modules/private/async/runjobs.lua:256: in field 'catch'
	@programdir/core/sandbox/modules/try.lua:123: in global 'try'
	@programdir/modules/private/async/runjobs.lua:218: in upvalue 'cotask'
	@programdir/core/base/scheduler.lua:404: in function <@programdir/core/base/scheduler.lua:397>

@waruqi
Copy link
Member

waruqi commented Jan 5, 2023

which your zig version, maybe this flag has also been deprecated in new zig.

@waruqi
Copy link
Member

waruqi commented Jan 5, 2023

I think you are using old zig (<= 0.9), please update your zig version to latest. zig 0.10 contains '-fstrip flag.

@glyh
Copy link
Author

glyh commented Jan 5, 2023

Yeah, it turns out to be that case.

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

2 participants