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

编译windows动态库时无法把target:targetdir()添加到linkdirs中 #1465

Closed
wiy opened this issue Jun 22, 2021 · 6 comments
Closed

编译windows动态库时无法把target:targetdir()添加到linkdirs中 #1465

wiy opened this issue Jun 22, 2021 · 6 comments
Labels
Milestone

Comments

@wiy
Copy link

wiy commented Jun 22, 2021

当使用如下配置时, xmake无法把target:targetdir()添加到libpath中

add_includedirs("libgdal/include")

target("main")
    set_kind("shared")
    on_load(function(target)
        -- target:add("linkdirs", target:targetdir())
        target:add("linkdirs", ".\\build\\windows\\x64\\release")
        target:add("linkdirs", ".\\build\\windows\\x64\\fake")
        target:add("links", "gdal_i")
    end)
    add_files("main.cpp")

链接错误信息

[ 50%]: linking.release main.dll
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29910\\bin\\HostX64\\x64\\link.exe"
-dll -nologo -machine:x64 
-libpath:build\windows\x64\fake gdal_i.lib 
-out:build\windows\x64\release\main.dll 
build\.objs\main\windows\x64\release\main.cpp.obj
error: @programdir\modules\private\async\runjobs.lua:225: @programdir\actions\build\kinds\shared.lua:88: @programdir\modules\core\tools\link.lua:159: LINK : fatal error LNK1181: 无法打开输入文件“gdal_i.lib”

stack traceback:
    [C]: in function 'error'
    [@programdir\core\base\os.lua:796]: in function 'raise'
    [@programdir\modules\core\tools\link.lua:159]: in function 'catch'
    [@programdir\core\sandbox\modules\try.lua:127]: in function 'try'
    [@programdir\modules\core\tools\link.lua:140]:
    [C]: in function 'link'
    [@programdir\actions\build\kinds\shared.lua:88]: in function 'callback'       
    [@programdir\modules\core\project\depend.lua:186]: in function 'on_changed'   
    [@programdir\actions\build\kinds\shared.lua:54]: in function '_do_link_target'
    [@programdir\actions\build\kinds\shared.lua:109]:
    [@programdir\actions\build\kinds\shared.lua:130]: in function '_link_target'
    [@programdir\actions\build\kinds\shared.lua:152]: in function 'jobfunc'
    [@programdir\modules\private\async\runjobs.lua:201]:
    [C]: in function 'trycall'
    [@programdir\core\sandbox\modules\try.lua:121]: in function 'try'
    [@programdir\modules\private\async\runjobs.lua:194]: in function 'cotask'
    [@programdir\core\base\scheduler.lua:365]:

stack traceback:
        [C]: in function 'error'
        @programdir\core\base\os.lua:796: in function 'raise'
        @programdir\modules\private\async\runjobs.lua:225: in function 'catch'
        @programdir\core\sandbox\modules\try.lua:127: in function 'try'
        @programdir\modules\private\async\runjobs.lua:194: in function 'cotask'
        @programdir\core\base\scheduler.lua:365: in function <@programdir\core\base\scheduler.lua:362>
warning: target(main).add_linkdirs("build\windows\x64\fake") path not found at .\xmake.lua:9
可以明显看到, build\windows\x64\fake目录被添加到libpath中,但是build\windows\x64\release没有加进来

但是如果将shared改为binary

[ 50%]: linking.release main.exe
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.28.29910\\bin\\HostX64\\x64\\link.exe" 
-nologo -dynamicbase -nxcompat -machine:x64 
-libpath:build\windows\x64\release 
-libpath:build\windows\x64\fake gdal_i.lib 
-out:build\windows\x64\release\main.exe 
build\.objs\main\windows\x64\release\main.cpp.obj
[100%]: build ok!
warning: target(main).add_linkdirs("build\windows\x64\fake") path not found at .\xmake.lua:9
可以明显看到, build\windows\x64\fake目录和build\windows\x64\release都被添加到libpath中

Please provide compiling and running environment information:

  • xmake version: v2.5.4+202106150250
  • os: Windows 10
  • target platform: windows/x64/release
@wiy wiy changed the title 编译windows动态库时无法把target:targetdir()添加到linddirs中 编译windows动态库时无法把target:targetdir()添加到linkdirs中 Jun 22, 2021
@waruqi waruqi added the bug label Jun 22, 2021
@waruqi waruqi added this to the v2.5.5 milestone Jun 22, 2021
@waruqi
Copy link
Member

waruqi commented Jun 22, 2021

后两天我会修下

@wiy
Copy link
Author

wiy commented Jun 23, 2021

后两天我会修下

好的, 多谢

@waruqi
Copy link
Member

waruqi commented Jun 23, 2021

更新到 dev 再试试

@wiy
Copy link
Author

wiy commented Jun 24, 2021

更新到 dev 再试试

多谢, 能够正常编译了, 但是第一次编译时会有一条warning信息(不影响编译)

warning: target(ogr_FileGDB).add_linkdirs("build\windows\x64\release") path not found at @programdir\rules\utils\inherit_links\inherit_links.lua:43

复现情况 :

  1. 第一次xmake f -c;xmake c;xmake时会出现
  2. 再次使用xmake c;xmake编译时, 不会再出现
  3. 再次使用xmake f -c;xmake c;xmake不会出现
  4. 手动删除.xmakebuild目录后, 再次使用xmake f -c;xmake c;xmake时会出现

@waruqi
Copy link
Member

waruqi commented Jun 25, 2021

没事 你去加 build dir 到 linkdirs ,当然会这样了。。build 目录被你删了,不存在了 当然会有警告。。

@waruqi waruqi closed this as completed Jun 25, 2021
@wiy
Copy link
Author

wiy commented Jun 25, 2021

没事 你去加 build dir 到 linkdirs ,当然会这样了。。build 目录被你删了,不存在了 当然会有警告。。

哈哈, 是我大意了, 大晚上的脑子果然不好使, 多谢解答.

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