当前位置:首页 » 编程软件 » 编译sdl2

编译sdl2

发布时间: 2022-08-10 02:10:51

A. 关于linux下连接动态库问题

gcc编译时,当使用动态库编译可以按照几种写法
1.gcc test.c ./libSDL2-2.so
2.gcc test.c -lSDL2-2
3.gcc test.c -L/home/test -lSDL2-2
一般的编译参数都是按照2或3去写
2写法的含义是从/lib或者/usr/lib目录下寻找名称为SDL2-2的库,即寻找/lib/libSDL2-2.so或者/usr/lib/libSDL2-2.so文件进行链接,当然如果没有动态库就会去找静态库,再没有应该就会在编译时报错
3写法的含义是从-L参数首先从指定的目录中寻找需要链接的库文件,随后再去寻找系统文件夹中是否存在需要的库
1写法的含义是将当前目录下的./libSDL2-2.so.0文件链接进最终文件,因此执行readelf -a a.out后在动态库部分所看到的路径就是./libSDL2-2.so.0,进而在执行文件时仅会从当前目录下寻找libSDL2-2.so.0文件,当执行文件时所在的目录下没有该文件时就会出现找不到库文件的操作

你第二次操作时,因为function.so库文件与a.out文件在同一个目录,同时也是在该目录下执行的ldd操作及运行a.out,a.out在加载动态库时从当前目录下找到了所需要的库文件,此时能够执行成功(ldd命令实质是一个脚本,通过设置环境变量运行动态库链接器来输出所有待链接的动态库)。
你可以试试将a.out拷贝至其他目录再次运行,将出现和第一次操作时一样的现象,找不到function.so文件。

具体的解决方法就是修改编译参数,将./libSDL2-2.so.0修改为-lSDL2-2并将libSDL2-2.so.0文件拷贝至/usr/lib目录下,并且可能因为没有修改链接器的缓存文件(将可能找不到带版本号后缀的动态库),需要在/usr/lib目录下建立一个文件连接(ln -s libSDL2-2.so.0 libSDL2-2.so)或者直接修改名称为libSDL2-2.so

B. 如何安装/编译在Linux / Ubuntu的SDL2 C C 05

1.使用apt-get 安装开发包
sudo apt-get install libsdl2-dev
2.编辑源文件, hello.c

#include <SDL2/SDL.h>int main(){ SDL_Window* window =0; SDL_Renderer* render=0; SDL_Init(SDL_INIT_EVERYTHING); window=SDL_CreateWindow("hello",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,640,480,SDL_WINDOW_SHOWN); render=SDL_CreateRenderer(window,-1,0); SDL_SetRenderDrawColor(render,0,255,0,255); SDL_RenderClear(render); SDL_RenderPresent(render); SDL_Delay(3000); SDL_DestroyWindow(window); SDL_DestroyRenderer(render); SDL_Quit(); return 0;}

3.编译
gcc hello.c -lSDL2
如果编译成功,会生成a.out可执行文件

4.运行
./a.out

C. 别踩白块c语言程序编译

只是禅模式的,如果是学习用的,知道一个模式的应该其他也会了,如果是想玩的话下正版吧= =

#include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h"
#include<string.h>
// 使用的头文件
int W; // 窗口宽
int H; // 窗口高
int PH; // 游戏区的高
int i, df = 0; // 定义的变量
char sorry[] = "游戏不适合你的手机", win[9] = "You win!", lose[10] =
"You lose", str[19] = "得分:";
Uint32 began = 0;
float time = 0.0; // 定义的计时变量
bool quit = false; // 退出标志
float X = 0, Y = 0; // 用于获取触控位置的坐标
SDL_Event event;
// 定义一个事件
SDL_Window *w = NULL; // 创建一个窗口指针
SDL_Renderer *ren = NULL; // 创建一个渲染器指针
SDL_Surface *sur = NULL; // 表面
SDL_Surface *sur1 = NULL; // 得分表面
SDL_Surface *text = NULL; // 标题文本区表面
SDL_Texture *tex = NULL; // 画刷
SDL_Texture *tex1 = NULL; // 画刷
SDL_Texture *tex2 = NULL; // 画刷
TTF_Font *font = NULL; // 定义一个字体
SDL_Color color, fontcolor; // 定义字体颜色
SDL_Rect rect[4]; // 屏幕出现的四个黑块
SDL_Rect title; // 标题区
SDL_Rect pp, over;
void change(); // 使方块动起来
void init(); // 启动sdl及相关
void draw(); // 画图
void start(); // 初始化相关数据
void end(); // 游戏结尾
int main(int argc, char **argv)
{ // 主函数
init();
start();
began = SDL_GetTicks(); // 得到开始时间
while (quit == false)
{
draw(); // 画图
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_FINGERDOWN:
X = event.tfinger.x * W;
Y = event.tfinger.y * H;
// 获取x,y的坐标
if (Y > rect[0].y)
if ((X > rect[0].x) && (X < (W / 4 + rect[0].x))) // 判断坐标
{
change();
df = df + 1;
}
else // 如果触屏位置不对
{
quit = true;
if (df < 3)
sur1 = TTF_RenderUTF8_Blended(font, sorry, color);
else
sur1 = TTF_RenderUTF8_Blended(font, lose, color);
}
break;
case SDL_FINGERUP:
break;
default:;
}
if (df > 100) // 如果在30秒内得分超过100
{
quit = true;
sur1 = TTF_RenderUTF8_Blended(font, win, color);
}
}
time = 30 - ((SDL_GetTicks() - began) / 1000); // 计算剩余时间
if (time == 0.0) // 当时间结束
{
quit = true;
sprintf(str, "时间到,得分:%d", df);
sur1 = TTF_RenderUTF8_Blended(font, str, color);
}
}
tex1 = SDL_CreateTextureFromSurface(ren, sur1); // 把表面转换成画刷
SDL_RenderCopy(ren, tex1, NULL, &over);
SDL_RenderPresent(ren);
SDL_Delay(3000); // 暂停3秒
end();
return 0;
}

void change()
{
for (int i = 0; i < 3; i++)
rect[i].x = rect[i + 1].x;
rect[3].x = (random() % 4) * W / 4; // 最上层产生随机的黑块
}

void init()
{
SDL_Init(SDL_INIT_EVERYTHING);
w = SDL_CreateWindow("别踩白块儿", 0, 0, W, H, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_BORDERLESS); // 配置窗口参数并创建
//
//
ren = SDL_CreateRenderer(w, -1, SDL_RENDERER_PRESENTVSYNC); // 为创建的窗口配置渲染器
TTF_Init(); // 启动font
font = TTF_OpenFont("/system/fonts/DroidSansFallback.ttf", 60); // 打开系统自带字体并设置大小为60
}

void draw()
{
sur = SDL_CreateRGBSurface(0, W, H, 32, 0, 0, 0, 0); // 先把表面刷白
SDL_FillRect(sur, NULL, 0xffffff);
for (int i = 0; i < 4; i++)
SDL_FillRect(sur, &rect[i], 0x00000); // 再把黑块逐个贴上表面
tex = SDL_CreateTextureFromSurface(ren, sur); // 把表面转换成画刷*/
sprintf(str, "得分:%d", df);
sur1 = TTF_RenderUTF8_Blended(font, str, color);
tex1 = SDL_CreateTextureFromSurface(ren, sur1); // 把表面转换成画刷
sprintf(str, "时间:%.2f\"", time);
text = TTF_RenderUTF8_Blended(font, str, fontcolor);
tex2 = SDL_CreateTextureFromSurface(ren, text); // 把表面转换成画刷
SDL_RenderCopy(ren, tex, NULL, NULL);
SDL_RenderCopy(ren, tex2, NULL, &title);
SDL_RenderCopy(ren, tex1, NULL, &pp);
SDL_RenderPresent(ren);
SDL_FreeSurface(sur);
SDL_DestroyTexture(tex);
SDL_FreeSurface(sur1);
SDL_FreeSurface(text);
SDL_DestroyTexture(tex1);
SDL_DestroyTexture(tex2);
}

void start()
{
SDL_GetWindowSize(w, &W, &H); // 得到屏幕分辨率
PH = H * 7 / 8;
color =
{
255, 215, 0};
fontcolor =
{
0, 0, 0}; // 字体颜色赋值
float a = PH * 3 / 4 + H / 8;
float wight = W / 4;
float hight = PH / 4;
rect[0].x = 0;
rect[0].y = a;
rect[1].x = wight;
rect[1].y = a - hight;
rect[2].x = wight * 2;
rect[2].y = a - 2 * hight;
rect[3].x = 3 * wight;
rect[3].y = a - 3 * hight;
for (int i = 0; i < 4; i++)
{ // 为黑块的高和宽赋值
rect[i].h = hight;
rect[i].w = wight;
}
title =
{
1.10, 0, W / 2, W / 8};
pp =
{
W / 2, 0, W / 2, W / 8};
over =
{
0, H / 4, W, H / 4};
}

void end()
{
TTF_CloseFont(font);
TTF_Quit();

D. LINUX下要在C中嵌入Python,编译的时候怎样解决库的连接问题

gcc编译时,当使用动态库编译可以按照几种写法1.gcctest.c./libSDL2-2.so2.gcctest.c-lSDL2-23.gcctest.c-L/home/test-lSDL2-2一般的编译参数都是按照2或3去写2写法的含义是从/lib或者/usr/lib目录下寻找名称为SDL2-2的库,即寻找/lib/libSDL2-2.so或者/usr/lib/libSDL2-2.so文件进行链接,当然如果没有动态库就会去找静态库,再没有应该就会在编译时报错3写法的含义是从-L参数首先从指定的目录中寻找需要链接的库文件,随后再去寻找系统文件夹中是否存在需要的库1写法的含义是将当前目录下的./libSDL2-2.so.0文件链接进最终文件,因此执行readelf-aa.out后在动态库部分所看到的路径就是./libSDL2-2.so.0,进而在执行文件时仅会从当前目录下寻找libSDL2-2.so.0文件,当执行文件时所在的目录下没有该文件时就会出现找不到库文件的操作你第二次操作时,因为function.so库文件与a.out文件在同一个目录,同时也是在该目录下执行的ldd操作及运行a.out,a.out在加载动态库时从当前目录下找到了所需要的库文件,此时能够执行成功(ldd命令实质是一个脚本,通过设置环境变量运行动态库链接器来输出所有待链接的动态库)。你可以试试将a.out拷贝至其他目录再次运行,将出现和第一次操作时一样的现象,找不到function.so文件。具体的解决方法就是修改编译参数,将./libSDL2-2.so.0修改为-lSDL2-2并将libSDL2-2.so.0文件拷贝至/usr/lib目录下,并且可能因为没有修改链接器的缓存文件(将可能找不到带版本号后缀的动态库),需要在/usr/lib目录下建立一个文件连接(ln-slibSDL2-2.so.0libSDL2-2.so)或者直接修改名称为libSDL2-2.so

E. 如何成功运行SDL官方提供的Android平台的Demo

操作步骤:
第一步:准备SDL源代码包;
1. 去官网下载最新版SDL2-2.0.3.tar.gz;
2. 解压后,可以在根目录下找到android-project目录和README-android.txt,前者是一个一个Android工程模板,后者是关于如何使用该工程的文档说明。
3. 调整目录,使其成为一个可编译的工程:
(1) 将android-project目录剪切到与SDL2-2.0.3同级的目录;
(2) 然后将SDL2-2.0.3目录拷贝到android-project\jni目录下,并重命名为SDL;
第二步:为SDL增加main函数
(1) 下载wiki.libsdl.org/Tutorials#Android.c文件;
(2) 下载之后将其放入android-project\jni\src目录;
(3) 将main.c加入android-project\jni\src\Android.mk: 在Android.mk中默认有个YourSourceHere.c,将其替换为main.c即可;
第三步:编译libSDL2.so和libmain.so
注:请确认NDK的bin目录已经配置到环境变量PATH中去;
打开cmd命令窗口,进入到android-project目录,然后执行"ndk-build"命令进行编译。编译成功后会在android-project根目录下生成libs目录,下面有各个平台的需要的这两个so文件。
第四步:修改build target配置文件
默认的工程是使用的=android-12,必须使这个target与系统配置的一致,否则编译会失败. 具体的配置位于android-project/project.properties和android-project/default.properties中。由于adt-bundle-windows-x86_64-20130729.zip包对应的是android-18,因此需要将这两个文件中的配置全部改为android-18.
第五步:导入Eclipse运行
依次选择File->New->Android->Android Project from Existing Code,然后选择android-project目录将工程文件导入到Eclipse中。
然后选择按照正常的Android工程运行即可。这个时候程序闪一下什么都没有,因为没有添加资源。可下载一个bmp图片放到android-project/assets中,这个目录是由eclipse自动生成的。然后运行就可以看到通过SDL渲染出来的图片了。

F. LINUX编译SDL库(下面指令的含义)

./configure 是一个配置命令,告诉你需要在PC机上编译,然后用于arm,可能是参数变化了

G. LINUX编译SDL库(下面指令的含义)

./configure
是一个配置命令,告诉你需要在PC机上编译,然后用于arm,可能是参数变化了

H. 如何在MFC对话框中使用SDL2

方法/步骤
新建MFC应用程序,工程名称为MFCSDL

本例使用基于对话框的程序,注意勾选“基于对话框”

在MFCSDLDlg.h中添加SDL library 头文件和库文件应用,并定义所需变量。
#include "../SDL2-2.0.3/include/sdl.h"
#pragma comment(lib, "../SDL2-2.0.3/lib/x86/SDL2.lib")
#define WINDOW_W 640
#define WINDOW_H 480
#define NUM_SPRITES 100
#define MAX_SPEED 1
static SDL_Window* window;
static SDL_Renderer *renderer;
static SDL_Texture * sprite;
static int window_w, window_h;
static int sprite_w, sprite_h;
static SDL_Rect *positions, *velocities;
添加WM_KICKIDLE消息,该消息为微软保留消息,不公开,用它可以避免自己再重载实现消息循环。
具体过程如下:
1. 在 MFCSDLdlg.h文件加入
afx_msg LRESULT OnKickIdle(WPARAM wParam, LPARAM lParam);
2. 在MFCSDLDlg.cpp中加入消息映射
BEGIN_MESSAGE_MAP(CMFCSDLDlg, CDialogEx)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_KICKIDLE,OnKickIdle)
ON_WM_CLOSE()
END_MESSAGE_MAP()
3.添加OnKickIdle消息实现。
LRESULT CMFCSDLDlg::OnKickIdle(WPARAM wParam, LPARAM lParam)
{

SDL_Event event;
int done = 0;
while (!done)
{
/* Check for events */
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_WINDOWEVENT:
switch (event.window.event) {
case SDL_WINDOWEVENT_EXPOSED:
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
break;
}
break;
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
MoveSprites(renderer, sprite);
}

return 0; //一定要返回0
}
在OnInitDialog函数中加入初始化代码。

BOOL CMFCSDLDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();

// 设定此对话方块的图示。当应用程式的主视窗不是对话方块时,
// 框架会自动从事此作业
SetIcon(m_hIcon, TRUE); // 设定大图示
SetIcon(m_hIcon, FALSE); // 设定小图示

// TODO: 在此加入额外的初始设定
window = SDL_CreateWindowFrom(m_hWnd);
SDL_SetWindowTitle(window, "SDL Native Window Test");
renderer = SDL_CreateRenderer(window, -1, 0);
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
sprite = LoadSprite(renderer, "icon.bmp");

SDL_GetWindowSize(window, &window_w, &window_h);
SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h);
positions = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
velocities = (SDL_Rect *) SDL_malloc(NUM_SPRITES * sizeof(SDL_Rect));
if (!positions || !velocities) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
// quit(2);
}
srand(time(NULL));
for (int i = 0; i < NUM_SPRITES; ++i) {
positions[i].x = rand() % (window_w - sprite_w);
positions[i].y = rand() % (window_h - sprite_h);
positions[i].w = sprite_w;
positions[i].h = sprite_h;
velocities[i].x = 0;
velocities[i].y = 0;
while (!velocities[i].x && !velocities[i].y) {
velocities[i].x = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
velocities[i].y = (rand() % (MAX_SPEED * 2 + 1)) - MAX_SPEED;
}
}
return TRUE; // 传回 TRUE,除非您对控制项设定焦点
}
在MFCSDLDlg.cpp中,添加LoadSprite函数,注意是static 全局函数,放在所有函数最上方。其作用是加载一个图片精灵,本例使用一个笑脸图片。
static SDL_Texture *
LoadSprite(SDL_Renderer *renderer, char *file)
{
SDL_Surface *temp;
SDL_Texture *sprite;

/* Load the sprite image */
temp = SDL_LoadBMP(file);
if (temp == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
return 0;
}

/* Set transparent pixel as the pixel at (0,0) */
if (temp->format->palette) {
SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels);
}

/* Create textures from the image */
sprite = SDL_CreateTextureFromSurface(renderer, temp);
if (!sprite) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
SDL_FreeSurface(temp);
return 0;
}
SDL_FreeSurface(temp);

/* We're ready to roll. :) */
return sprite;
}
在LoadSprite后添加MoveSprites函数,其作用是将精灵循环移动,实现动态效果。
static void
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
{
if(renderer==NULL||sprite==NULL)
return;
int sprite_w, sprite_h;
int i;
SDL_Rect viewport;
SDL_Rect *position, *velocity;

/* Query the sizes */
SDL_RenderGetViewport(renderer, &viewport);
SDL_QueryTexture(sprite, NULL, NULL, &sprite_w, &sprite_h);

/* Draw a gray background */
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);

/* Move the sprite, bounce at the wall, and draw */
for (i = 0; i < NUM_SPRITES; ++i) {
position = &positions[i];
velocity = &velocities[i];
position->x += velocity->x;
if ((position->x < 0) || (position->x >= (viewport.w - sprite_w))) {
velocity->x = -velocity->x;
position->x += velocity->x;
}
position->y += velocity->y;
if ((position->y < 0) || (position->y >= (viewport.h - sprite_h))) {
velocity->y = -velocity->y;
position->y += velocity->y;
}

/* Blit the sprite onto the screen */
SDL_RenderCopy(renderer, sprite, NULL, position);
}

/* Update the screen! */
SDL_RenderPresent(renderer);
}
8
以上完成,按F7编译,将icon.bmp文件拷贝到程序执行文件加下,运行程序,可看到如图效果。

I. sdl2/sdl.h头文件有什么用

stdlib 头文件即standard library标准库头文件 stdlib 头文件里包含了C、C++语言的最常用的系统函数 该文件包含了的C语言标准库函数的定义 stdlib.h里面定义了五种类型、一些宏和通用工具函数。 类型例如size_t、wchar_t、div_t、ldiv_t和lldiv_t; 宏例如EXIT_FAILURE、EXIT_SUCCESS、RAND_MAX和MB_CUR_MAX等等; 常用的函数如malloc()、calloc()、realloc()、free()、system()、atoi()、atol()、rand()、srand()、exit()等等。 具体的内容你自己可以打开编译器的include目录里面的stdlib.h头文件看看。

J. 手机c语言编程软件哪个好

1:C4droid中文版

C4droid中文版可以说是款Android设备上的最强的 C/C++ IDE,支持多种图形库: SDL、SDL2 (需安装sdl plugin for c4droid)、QT(需安装CuteLoadear)等,还支持导出APK!

热点内容
服务器换电脑需要什么东西 发布:2024-05-05 09:52:28 浏览:753
老算盘算法 发布:2024-05-05 09:43:10 浏览:840
ps存储显示不含通道 发布:2024-05-05 09:32:35 浏览:102
如何用安卓做一个识物界面表 发布:2024-05-05 09:29:28 浏览:98
如何编译linux内核模块 发布:2024-05-05 09:27:25 浏览:168
为什么apple验证无法连接服务器 发布:2024-05-05 09:20:35 浏览:660
linuxscript 发布:2024-05-05 09:19:49 浏览:324
asp编程词典 发布:2024-05-05 09:09:50 浏览:526
引流群控脚本 发布:2024-05-05 08:42:14 浏览:178
sql测试题和答案 发布:2024-05-05 08:42:09 浏览:893