从64位应用程序使用32位共享库?

编程入门 行业动态 更新时间:2024-10-28 19:29:10
本文介绍了从64位应用程序使用32位共享库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我为我的渲染包装器创建了一个简单的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位共享库?

本文发布于:2023-05-25 12:58:32,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!