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

静态库错误 #297

Closed
yauntyour opened this issue Apr 1, 2023 · 6 comments
Closed

静态库错误 #297

yauntyour opened this issue Apr 1, 2023 · 6 comments

Comments

@yauntyour
Copy link

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

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
Copy link
Owner

lc-soft commented Apr 1, 2023

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

@yauntyour
Copy link
Author

yauntyour commented Apr 4, 2023 via email

@lc-soft
Copy link
Owner

lc-soft commented Apr 5, 2023

提供一下具体信息:

  • dll 是自行编译的还是在 releases 页面下载的?
  • 用的哪个版本?

@yauntyour
Copy link
Author

yauntyour commented Apr 8, 2023 via email

@lc-soft
Copy link
Owner

lc-soft commented Apr 9, 2023

我下载 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

@lc-soft lc-soft closed this as completed Apr 9, 2023
@yauntyour
Copy link
Author

yauntyour commented Apr 12, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants