Sreekanth Karumanaghat
Sreekanth Karumanaghat

Reputation: 3403

Using pre built static libraries android

I am using freeimage.so for my android project,How can I refer this library from the C code?Or is it needed to access the functions in this library? Further info:I have put the function in armeabi folder in the project Kindly provide me with your valuable suggestions Thank you in advance for your valuable efforts

Upvotes: 1

Views: 255

Answers (1)

Viktor Latypov
Viktor Latypov

Reputation: 14467

.so is a Dynamic library (a.k.a Shared Object), not a Static one.

To use .so file directly from C code you can use dlfcn POSIX API. It's just like LoadLibrary/GetProcAddress in WinAPI.

#include <dlfcn.h>

// sorry, I don't know the exact name of your FreeImage header file
#include "freeimage_header_file.h"

// declare the prototype
typedef FIBITMAP* ( DLL_CALLCONV* PFNFreeImage_LoadFromMemory )
         ( FREE_IMAGE_FORMAT, FIMEMORY*, int );

// declare the function pointer
PFNFreeImage_LoadFromMemory LoadFromMem_Function;

void some_function()
{
    void* handle = dlopen("freeimage.so", RTLD_NOW);

    LoadFromMem_Function = 
            ( PFNFreeImage_LoadFromMemory )dlsym(handle, "FreeImage_LoadFromMemory" );

    // use LoadFromMem_Function as you would use
    // statically linked FreeImage_LoadFromMemory
}

If you need a static one, fetch libfreeimage.a (or build one yourself) and add the linker instruction -lfreeimage.

Upvotes: 2

Related Questions