Skip to content

动态库/静态库热加载出错 #3052

@SineStriker

Description

@SineStriker

Xmake 版本

2.7.2

操作系统版本和架构

Windows 10 amd64

描述问题

使用XMake先编译动态库,然后把动态库改成静态库,MSVC报找不到符号,必须把构建目录全删了重新来才行。

源码:https://github.com/SineStriker/xmake-examples

编译器版本:MSVC 2019

完整复现方式

  • 设置编译动态库

    • 修改libshared/xmake.lua第九行为
      set_config("libshared_build_static", "off")
  • 第一次构建

    PS > xmake f2
    checking for architecture ... x64
    checking for Microsoft Visual Studio (x64) version ... 2019
    create ok!
    
    PS > xmake b
    [ 25%]: cache compiling.release libshared\src\shared.cpp
    [ 25%]: cache compiling.release main.c
    [ 50%]: linking.release libshared.dll
    [ 75%]: linking.release main.exe
    [100%]: build ok!
    
    PS > xmake r
    plugin_func v0
  • 设置编译动态库

    • 修改libshared/xmake.lua第九行为
      set_config("libshared_build_static", "on")
  • 第二次构建

    PS > xmake f2
    checking for Microsoft Visual Studio (x64) version ... 2019
    create ok!
    
    PS > xmake b 
    [ 25%]: cache compiling.release libshared\src\shared.cpp
    [ 50%]: archiving.release libshared.lib
    [ 75%]: linking.release main.exe
    error: main.c.obj : error LNK2019: 无法解析的外部符号 __imp_plugin_func,函数 main 中引用了该符号
    build\windows\x64\release\main.exe : fatal error LNK1120: 1 个无法解析的外部命令
  • 此时必须将build目录删掉,重新配置编译,才会成功,否则一直是以上的错。

期待的结果

...

工程配置

...

附加信息和错误日志

...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions