How can i add a C library to my C++ sdl project?

I’m trying to add libxmp, which is a c library, to my sdl c++ project, but getting erros whenever i try to run my code "F:\codeblocks\sdlgame\main.cpp|13|error: invalid conversion from ‘void*’ to ‘xmp_context’ {aka ‘char*’} [-fpermissive]| " if i create a C project and try to run the same code it works. I’m not sure if sdl works with c and c++ code at the same time without work arounds.

This probably isn’t an SDL issue. Some C code is valid C++ and some isn’t. One of the things C allows but C++ doesn’t is implicit cast from void * to other pointer types. In C++, you need an explicit cast, like “xmp_context my_context=static_cast<xmp_context>(xmp_thing_that_returns_a_void_pointer());” or “xmp_context my_context=(xmp_context)xmp_thing_that_returns_a_void_pointer();”. This is one of the dumber C++ design choices IMHO, especially since they added “auto” typing, but we’ve still got to live with it.

To combine C which isn’t valid C++ in the same project with C++, you can compile the C code separately as C and link the object file. Make sure you’re not trying to compile it as C++. If there’s stuff in the header file that isn’t valid C++, you can make a modified header for it that fixes the issues and #include that rather than the standard header, or you can make a wrapper library in C with a valid C++ header.

In any case, both the header you’re #including in any of your C++ files and all your C++ code that interfaces with the C library has to be valid C++.

thanks for the help i’ll try to do it.