C Implementation

Jun 20, 2014 at 9:17 PM
Edited Jun 20, 2014 at 9:27 PM

I’m currently trying to get this code to work on a C platform. Unfortunately I am only an intermediate programmer so I really don’t understand how all the files interact. I am including the header files config.h, interface.h, and publictypes.h in the project, but it appears that the definitions for the API functions reside in interface.cpp. If I include this source file into my project then it will no longer compile correctly because I am using C and it appears there are C++ objects and other constructs defined in the functions. For example the function JpegLsEncode() needs the JLSOutputStream class to work, but I don't understand how classes are able to be used in C.

I have a feeling I am approaching this from the wrong direction. Does there need to be something like a library file that I associate with my source file? I just don’t understand how a C program is able to access the functions listed inside the extern “C” in interface.cpp because then many more header files are needed to define things that are used. Once those are included the program is no longer in C. Was this written to only be used by a C++ compiler that was written in C or can a C compiler use it?

I apologize for my ignorance but I would appreciate any help you could provide me. Is there any kind of idiot proof guide or explanation for how to use the API functions in C? I read about people referring the samples but my issue is a bit different because I am doing something wrong not only in the implementation but getting the program to build. I have never used a compiler like GCC before, only IDEs with built in compilers. Do I need to learn the command prompt route for this to work?

Thanks for any help you can provide,
Jun 21, 2014 at 12:25 PM
Hi Nick,

The CharLS source code needs to be compiled with a C++ compiler (C++ 03 for v1.0 and a C++ 11 compatible compiler for the current GIT version). Depending on the platform you can create a dynamic linked library or a static library. CharLS comes with CMake makefiles that you can use to create a makefile your your environment, but I don't know if there a CMake version for your system.

It seems that for your project you need to compile CharLS as a static library using a C++ compiler. Then you can use this generated .lib file and link that with your C application. You can use a C compiler to compile your own code.

I don't know if a C++ compiler exists for your platform. If not the second best option is to find a C++ cross compiler that can target your platform\CPU and copy the binary .lib file to your target system.

Jun 24, 2014 at 3:59 PM
Thank you very much Victor! It makes much more sense now.