从64位应用程序使用32位共享库? [英] Use 32bit shared library from 64bit application?
问题描述
我为我的渲染包装器创建了一个简单的linux 32位共享库(.so),但是当我想通过32位应用程序只能使用
时,我碰到了一堵墙。 .............
这就是我的代码的样子:
RendIFace.h:
//基本渲染器接口
结构渲染器
{
int类型;
...其他东西
};
GLRend.c:
#includeRendIFace.h
struct Renderer * GLRendererCreate(int width,int height,int bytesPerPixel)
{
struct Renderer * rend =(struct Renderer * )的malloc(的sizeof(渲染器));
rend-> type = GLR;
..其他的东西
return rend;
SDLRend.c:
#includeRendIFace.h
struct Renderer * SDLRendererCreate(int width,int height,int bytesPerPixel)
{
struct Renderer * rend =(struct Renderer *)malloc(sizeof(Renderer));
rend-> type = SDLR;
..其他的东西
return rend;
}
我将它们编译为共享的32位库(.so)并加载它们主要应用程序...
但现在有一个大问题。我的库都是32位并返回32位指针,这意味着我不能通过$ b使用它们$ b是一个64位应用程序,无需重新编译所有库代码库(!!!)。
所以我想问更多有经验的人:我该如何处理这个问题?是否可以在两种体系结构中只使用一个共享库?
您必须保持一致。 64位应用程序只能使用64位库,而32位应用程序只能使用32位库。两者都有效;任何选择都可以,并且可以为两个系统编译相同的代码。如果您选择'全部32位',请使用:
-
gcc -m32
如果您选择'全部64位',请使用:
gcc -m64
有时,我会告诉 make
C编译器是 gcc -m32
(或者 -m64
),而不仅仅是 gcc
以确保在任何地方使用正确的值。
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 ???
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.
这篇关于从64位应用程序使用32位共享库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!