lc-soft / LCUI

C library for building user interfaces
https://lcui-dev.github.io
MIT License
4.12k stars 356 forks source link

静态库错误 #297

Closed yauntyour closed 1 year ago

yauntyour commented 1 year ago

在包含编译时遇到如下问题:

PS K:\CCXXProgram\lcui-app> K:/X64/MSYS2/mingw64/bin/g++.exe -fdiagnostics-color=always -g main.cpp -o bin\app.exe -L bin\ -lLCUI
K:/X64/MSYS2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\YAUNTY~1\AppData\Local\Temp\cc2YjwJ9.o:K:\CCXXProgram\lcui-app/main.cpp:53: undefined reference to `Widget_AddTaskByStyle(LCUI_WidgetRec_*, int)'
collect2.exe: error: ld returned 1 exit status

代码:

#include <stdio.h>
#include <stdlib.h>

#include "include/LCUI.h"
#include "include/LCUI/gui/css_fontstyle.h"
#include "include/LCUI/gui/widget.h"
#include "include/LCUI/gui/widget_style.h"
#include "include/LCUI/gui/widget/textview.h"
#include "include/LCUI/gui/widget/button.h"
#include "include/LCUI/gui/widget/textedit.h"

#define TEXT_LEN 256

void But_a(LCUI_Widget self, LCUI_WidgetEvent e, void *arg)
{
    LCUI_Widget in_a = ((LCUI_Widget *)e->data)[0];
    LCUI_Widget text = ((LCUI_Widget *)e->data)[1];

    wchar_t *str = (wchar_t *)malloc(TEXT_LEN);
    memset(str, 0, TEXT_LEN);

    TextEdit_GetTextW(in_a, 0, TEXT_LEN - 1, (wchar_t *)str);
    TextView_SetTextW(text, str);

    free(str);
}

int main(int argc, char const *argv[])
{
    LCUI_Init();

    LCUI_Widget root = LCUIWidget_GetRoot();

    LCUI_Widget text = LCUIWidget_New("textview");
    LCUI_Widget but_a = LCUIWidget_New("button");
    LCUI_Widget in_a = LCUIWidget_New("textedit");

    LCUI_Widget in_a_stu[] = {
        in_a, text};

    TextEdit_SetPlaceHolder(in_a, "Please input...");

    TextView_SetText(text, "text");
    Button_SetText(but_a, "save");

    Widget_SetStyle(text, key_color, RGB(56, 132, 255), color);
    Widget_SetStyle(text, key_font_size, 24, px);

    Widget_Append(root, text);
    Widget_Append(root, in_a);
    Widget_Append(root, but_a);

    return LCUI_Main();
}

INFO

之所以使用相对包含include "XXXX.h"是因为在此之前,我已经利用Python对所有的头文件包含进行修正了。

经测试是没有依赖问题的。

但是出现了undefined reference,经过排查发现,是***这个dll里面没有这个东西。

头文件就定义了个寂寞

所以就想着issue一下看看是不是编译的时候忘记加源文件

lc-soft commented 1 year ago

这么奇怪?我看 widget_style.h 有导出 Widget_AddTaskByStyle,widget_style.c 里也有它的定义。

yauntyour commented 1 year ago

确实是这样的,直接用源文件的包含方式却没有这个问题。


发件人: Liu @.> 发送时间: 2023年4月1日 22:47 收件人: lc-soft/LCUI @.> 抄送: yauntyour @.>; Author @.> 主题: Re: [lc-soft/LCUI] 静态库错误 (Issue #297)

这么奇怪?我看 widget_style.h 有导出 Widget_AddTaskByStyle,widget_style.c 里也有它的定义。

― Reply to this email directly, view it on GitHubhttps://github.com/lc-soft/LCUI/issues/297#issuecomment-1492990789, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APBW4NP443S6V2ACGH4BPDTW7A5YNANCNFSM6AAAAAAWPNIJQE. You are receiving this because you authored the thread.Message ID: @.***>

lc-soft commented 1 year ago

提供一下具体信息:

yauntyour commented 1 year ago

就是release的最新版本,并不是我自己编译的。 😉

Yauntyour,yours.


From: Liu @.> Sent: Wednesday, April 5, 2023 8:45:38 PM To: lc-soft/LCUI @.> Cc: yauntyour @.>; Author @.> Subject: Re: [lc-soft/LCUI] 静态库错误 (Issue #297)

提供一下具体信息:

— Reply to this email directly, view it on GitHubhttps://github.com/lc-soft/LCUI/issues/297#issuecomment-1497427799, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APBW4NND5ZYUWSO2BSCX7WDW7VSPFANCNFSM6AAAAAAWPNIJQE. You are receiving this because you authored the thread.Message ID: @.***>

lc-soft commented 1 year ago

我下载 Releases 页面中的 LCUI-2.2.0_x64-windows.lcpkg.zip 测试了一下。

运行 dumpbin LCUI.lib /EXPORTS 命令输出的内容中有 Widget_AddTaskByStyle

image

编写测试程序直接调用 Widget_AddTaskByStyle(),能够编译通过:

image

然而改用你贴的代码后,编译会报错:

image

css_fontstyle.h 前面插入它所依赖的头文件LCUI/font.hLCUI/gui/css_library.h 后,可编译通过:

image

复制 exe 和 dll 文件到 dist 目录内:

image

然后运行 exe 文件,效果如下图所示:

image

yauntyour commented 1 year ago

OK啊,收到! 原来是我改包含路径的问题😂😂 [cid:55311e7b-a7dd-40be-b623-0b9a1d04eae7] 我回头改改吧


发件人: Liu @.> 发送时间: 2023年4月9日 20:41 收件人: lc-soft/LCUI @.> 抄送: yauntyour @.>; Author @.> 主题: Re: [lc-soft/LCUI] 静态库错误 (Issue #297)

我下载 Releases 页面中的 LCUI-2.2.0_x64-windows.lcpkg.zip 测试了一下。

运行 dumpbin LCUI.lib /EXPORTS 命令输出的内容中有 Widget_AddTaskByStyle:

[image]https://user-images.githubusercontent.com/1730073/230772274-e465875c-1fde-4b72-a104-b38334b3cb46.png

编写测试程序直接调用 Widget_AddTaskByStyle(),能够编译通过:

[image]https://user-images.githubusercontent.com/1730073/230772492-979e96a0-a554-4464-8659-5fe16828bde3.png

然而改用你贴的代码后,编译会报错:

[image]https://user-images.githubusercontent.com/1730073/230772564-71afeda5-2ad9-416c-b7c2-b925cc3bd05a.png

在 css_fontstyle.h 前面插入它所依赖的头文件 LCUI/font.h 和 LCUI/gui/css_library.h 后,可编译通过:

[image]https://user-images.githubusercontent.com/1730073/230772762-35525cda-f801-4acb-a267-34e005b5c547.png

复制 exe 和 dll 文件到 dist 目录内:

[image]https://user-images.githubusercontent.com/1730073/230772927-988c7440-e09c-4da8-8932-225b1c3475e7.png

然后运行 exe 文件,效果如下图所示:

[image]https://user-images.githubusercontent.com/1730073/230772973-f252bfb8-b1fc-4e48-b075-2f781d1bedfc.png

— Reply to this email directly, view it on GitHubhttps://github.com/lc-soft/LCUI/issues/297#issuecomment-1501120968, or unsubscribehttps://github.com/notifications/unsubscribe-auth/APBW4NIM2ZAIPMOTUL6YJQTXAKU6ZANCNFSM6AAAAAAWPNIJQE. You are receiving this because you authored the thread.Message ID: @.***>