0

我正在尝试使用 libical 构建一个 MWE,其中一个示例几乎是从 libical 文档中剪切和粘贴的,如下所示:

#include <stdlib.h>

#include <libical/ical.h>

const char* calendar_file = "orage_export.ics";

//*****************************************************************************

char* read_stream(char* s, size_t size, void* d)
    {
    return fgets(s, size, (FILE*)d);
    } // read_stream()

//*****************************************************************************

int main()
    {
    char* line;
    icalcomponent* component;
    icalparser* parser = icalparser_new();

    // open file (first command-line argument)
    FILE* stream = fopen(calendar_file, "r");
    if(stream == NULL)
        {
        printf("unable to open %s\n", calendar_file);
        exit(-1);
        }

    // Associate the FILE with the parser so that read_stream  will have access to it
    icalparser_set_gen_data(parser, stream);
    do
        {
        // Read the file, line-by-line, and parse the data
        line = icalparser_get_line(parser, read_stream);
        component = icalparser_add_line(parser, line);

        // If icalparser has finished parsing a component, it will return it
        if(component != 0)
            {
            // Print the parsed component
            printf("%s", icalcomponent_as_ical_string(component));
            icalparser_clean(parser);
            printf("\n---------------\n");
            icalcomponent_free(component);
            }
        }
    while(line != 0);

    fclose(stream);

    return 0;
    }

但是我遇到了无法解决的链接问题。显然,我正在链接(最新版本的)libical + pthreads。然后我得到了一个未定义的对 ucal_getKeywordValuesForLocale_66 的引用,我可以通过添加 libicui18n.a 来解决它。但后来我得到“icu_66::UnicodeString 的vtable”、“icu_66::UnicodeString::setTo”和“icu_66::~UnicodeString”等未定义的参考错误,这些错误看起来很像与ICU组件相关的C++错误。但是我正在构建一个普通的 C 程序?

我需要哪些库才能使上述 MWE 正常工作?为什么在构建 vanilla C 程序时会出现基于类的链接错误?

我在 Linux Mint 20.2 上,并使用除 libical 本身之外的所有库的 repo 版本。

彼得

编辑:事实上,回答了我自己的问题!

仔细(正确地?)查看输出,未定义的问题与 libicui18n 相关,因此根本不是 iCal 问题。嗬!

解决方法是注意到 iCal 人员提供了一个 pkg-config 脚本,因此添加pkg-config --libs --cflags libical到编译器行是有效的。(我猜 ICU 依赖项是隐式固定的。)

4

0 回答 0