Why can't I use `libmime` in my code? (OSError: mime.so: undefined symbol: magic_load)

78 Views Asked by At

I try to use libmagic in my c code. I compile the following code like this (gcc mime.c -shared -o mime.so). Unfortunately it throws me this error when using it: OSError: mime.so: undefined symbol: magic_load

mime.c

#include <stdio.h>
#include <magic.h>

void get(char* argv[]) {
    magic_t myt = magic_open(MAGIC_CONTINUE|MAGIC_ERROR/*|MAGIC_DEBUG*/|MAGIC_MIME);
    magic_load(myt,NULL);
    char value = magic_file(myt, argv[1]);
    magic_close(myt);

    return value;
}

How can I fix this?

1

There are 1 best solutions below

0
Acorn On

You need to link with libmagic, try something like:

-lmagic