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
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.
g++ command needs -lmagic.magic.h is most likely in a standard place, you should use #include .Tell us what your error is for more specific help.