'Link problems for libical MWE
I am trying to build an MWE using libical with an example pretty much cut-and-pasted from the libical docs as follows:
#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;
}
But I am getting link issues that I cannot resolve. Obviously, I am linking against (the latest version of) libical + pthreads. I then got an undefined reference to ucal_getKeywordValuesForLocale_66 which I can resolve by adding libicui18n.a. But then I get undefined reference errors for "vtable for icu_66::UnicodeString", "icu_66::UnicodeString::setTo" and "icu_66::~UnicodeString" so on, which look very much like C++ errors associated with ICU components. But I am building a plain C program?
What is the set of libraries I need to get the MWE above working? And why am I getting what seem to be class-based link errors when building a vanilla C program?
I am on Linux Mint 20.2, and using the repo versions of all libraries other than libical itself.
Peter
EDIT: In fact, answered my own question!
Looking carefully (properly?) at the output, the undefined issues were connected to libicui18n, so not really an iCal problem at all. Doh!
The fix was to notice that the iCal folks had provided a pkg-config script so adding pkg-config --libs --cflags libical to the compiler line worked. (I guess the ICU dependencies are fixed implicitly.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
