Trying to use/include/compile 3rd party library, libmagic. C/C++ filetype detection

后端 未结 3 939
长发绾君心
长发绾君心 2021-01-21 10:18

After looking for a way to detect the filetype of a file stream, I found that the Unix file command uses libmagic and I\'m trying to make use of the library myself, but I can\'t

3条回答
  •  忘掉有多难
    2021-01-21 11:03

    I don't know why you think the above "obviously" doesn't work. See How to mix C and C++ in the C++ FAQ for details.

    Looks like magic.h has proper extern "C" { } enclosures. So, compiling your code with g++ should work nicely. You can #include in your .cpp file, and use all the libmagic functions.

    • Is there a particular error you're getting?
    • I have not checked your use of the libmagic functions.
    • You need to link with libmagic. Your g++ command needs -lmagic.
    • Since magic.h is most likely in a standard place, you should use #include .

    Tell us what your error is for more specific help.

提交回复
热议问题