Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

c - Use 32bit shared library from 64bit application?

I have created a simple linux 32bit shared library(.so) for my rendering wrappers but i've hit a wall when i figured that i can only use them through 32bit applications....................

This is how my code looks like:

RendIFace.h:

//Basic renderer interface
struct Renderer
{
    int type;
    ...other things
};

GLRend.c:

#include "RendIFace.h"
struct Renderer* GLRendererCreate(int width,int height,int bytesPerPixel)
{
    struct Renderer* rend = (struct Renderer*)malloc(sizeof(Renderer));

    rend->type = GLR;
    ..other things

    return rend;
}

SDLRend.c:

#include "RendIFace.h"
struct Renderer* SDLRendererCreate(int width,int height,int bytesPerPixel)
{
    struct Renderer* rend = (struct Renderer*)malloc(sizeof(Renderer));

    rend->type = SDLR;
    ..other things

    return rend;
}

And i compile both as shared 32bit libraries(.so) and load them through the main application...

But now there is a big problem.My libraries are all 32bit and return 32bit pointers which means that i can't use them through an 64bit application without rebuilding all the library code base(!!!).

So i would like to ask more experienced people : How do i handle this issue ? Is it possible to use just a single shared library for both architectures ???

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You must be consistent. A 64-bit application can only use 64-bit libraries and a 32-bit application can only use 32-bit libraries. Both work; either choice is fine, and it's possible to compile the same code for both systems.

If you go for 'all 32-bit', use:

  • gcc -m32

If you go for 'all 64-bit', use:

  • gcc -m64

Sometimes, I'll tell make that the C compiler is gcc -m32 (or -m64) rather than just gcc to ensure the right value is used everywhere.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...