- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在Linux/Mint下,我正在尝试编译这个源代码here .
我收到了很多“对 Xxx 的 undefined reference
”,因此在谷歌搜索一段时间后,以下是我安装的所有内容:
sudo apt-get install libboost-all-dev libsdl1.2-dev libsdl-image1.2-dev libsdl-net1.2-dev
sudo apt-get install libsdl-ttf2.0-dev libspeexdsp-dev libzzip-dev
sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev libswscale-dev
sudo apt-get install libsdl-mixer1.2-dev libsdl2-dev libsdl2-mixer-dev libsdl2-image-dev
在此之后,当我尝试启动 make
时,我仍然得到大量 undefined reference
:
.....blabla..........
font.cpp:(.text+0x388): undefined reference to `TTF_RenderUNICODE_Blended'
font.cpp:(.text+0x3ec): undefined reference to `SDL_UpperBlit'
font.cpp:(.text+0x3f8): undefined reference to `SDL_FreeSurface'
font.cpp:(.text+0x42a): undefined reference to `TTF_RenderUNICODE_Blended'
font.cpp:(.text+0x488): undefined reference to `SDL_UpperBlit'
font.cpp:(.text+0x494): undefined reference to `SDL_FreeSurface'
font.o: In function `Font::getWidth(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)':
font.cpp:(.text+0x566): undefined reference to `TTF_SizeUNICODE'
font.o: In function `Font::getWidth(wchar_t)':
font.cpp:(.text+0x5cc): undefined reference to `TTF_GlyphMetrics'
font.o: In function `Font::getHeight(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)':
font.cpp:(.text+0x634): undefined reference to `TTF_SizeUNICODE'
font.o: In function `Font::getSize(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, int&, int&)':
font.cpp:(.text+0x691): undefined reference to `TTF_SizeUNICODE'
topscores.o: In function `ScoresWindow::ScoresWindow(int, int, TopScores*, int)':
topscores.cpp:(.text+0xc85): undefined reference to `SDL_SetClipRect'
topscores.cpp:(.text+0xce9): undefined reference to `SDL_SetClipRect'
sound.o: In function `Sound::Sound()':
sound.cpp:(.text+0x48): undefined reference to `Mix_OpenAudio'
sound.o: In function `Sound::~Sound()':
sound.cpp:(.text+0xd1): undefined reference to `Mix_CloseAudio'
sound.cpp:(.text+0x128): undefined reference to `Mix_FreeChunk'
sound.cpp:(.text+0x140): undefined reference to `Mix_CloseAudio'
sound.o: In function `Sound::play(std::__cxx11::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)':
sound.cpp:(.text+0x269): undefined reference to `SDL_RWFromMem'
sound.cpp:(.text+0x276): undefined reference to `Mix_LoadWAV_RW'
sound.cpp:(.text+0x2d5): undefined reference to `Mix_VolumeChunk'
sound.cpp:(.text+0x2f0): undefined reference to `Mix_PlayChannelTimed'
sound.cpp:(.text+0x2f5): undefined reference to `SDL_PumpEvents'
collect2: error: ld returned 1 exit status
Makefile:52: recipe for target 'einstein' failed
make: *** [einstein] Error 1
查看 Makefile(这很容易理解),当我启动 sdl-config --libs
时,我得到 -L/usr/lib/x86_64-linux-gnu -lSDL
如果我这样做ls -alh/usr/lib/x86_64-linux-gnu
我会得到大量文件(即该目录存在)
我错过了什么?
最佳答案
这似乎是一个 SDL 1.2 项目。不需要所有这些 SDL2 软件包。
该项目存在多个问题:
Makefile
应该使用 pkg-config
在 Linux 上(或者由 CMake 之类的元数据生成),而不是 sdl-config
的混搭和原料-l
旗帜。已修复:
CXXFLAGS=-pipe -Wall $(OPTIMIZE) $(DEBUG) `pkg-config --cflags sdl SDL_mixer SDL_ttf zlib` -DPREFIX=L\"$(PREFIX)\" $(PROFILER)
LNFLAGS=`pkg-config --libs sdl SDL_mixer SDL_ttf zlib` $(PROFILER)
$(TARGET)
链接器选项位于错误的位置(在 $(OBJECTS)
之前)。已修复:
$(TARGET): $(OBJECTS)
$(CXX) $(OBJECTS) $(LNFLAGS) -o $(TARGET)
所有#include <SDL/*>
行应该有前导 SDL/
剥离; pkg-config --cflags
生成-I/usr/include/SDL
,不是-I/usr/include
.
应用所有这些修复后,它将构建在此 Ubuntu 16.04 安装上。
完整补丁:
diff --git a/Makefile b/Makefile
index e682bb1..08f5463 100644
--- a/Makefile
+++ b/Makefile
@@ -16,8 +16,8 @@ PREFIX=/usr/local
OPTIMIZE=#-O6 -march=pentium4 -mfpmath=sse -fomit-frame-pointer -funroll-loops
PROFILER=#-pg
DEBUG=#-ggdb
-CXXFLAGS=-pipe -Wall $(OPTIMIZE) $(DEBUG) `sdl-config --cflags` -DPREFIX=L\"$(PREFIX)\" $(PROFILER)
-LNFLAGS=-pipe -lSDL_ttf -lfreetype `sdl-config --libs` -lz -lSDL_mixer $(PROFILER)
+CXXFLAGS=-pipe -Wall $(OPTIMIZE) $(DEBUG) `pkg-config --cflags sdl SDL_mixer SDL_ttf zlib` -DPREFIX=L\"$(PREFIX)\" $(PROFILER)
+LNFLAGS=`pkg-config --libs sdl SDL_mixer SDL_ttf zlib` $(PROFILER)
INSTALL=install
TARGET=einstein
@@ -49,7 +49,7 @@ all: $(TARGET)
$(TARGET): $(OBJECTS)
- $(CXX) $(LNFLAGS) $(OBJECTS) -o $(TARGET)
+ $(CXX) $(OBJECTS) $(LNFLAGS) -o $(TARGET)
clean:
rm -f $(OBJECTS) core* *core $(TARGET) *~
diff --git a/font.h b/font.h
index 40d617b..2e8e44d 100644
--- a/font.h
+++ b/font.h
@@ -3,7 +3,7 @@
#include <string>
-#include <SDL/SDL_ttf.h>
+#include <SDL_ttf.h>
class Font
diff --git a/iconset.h b/iconset.h
index 4faf055..0f971ac 100644
--- a/iconset.h
+++ b/iconset.h
@@ -2,7 +2,7 @@
#define __ICONSET_H__
-#include <SDL/SDL.h>
+#include <SDL.h>
class IconSet
diff --git a/main.cpp b/main.cpp
index d103861..2d4c33f 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,8 +1,8 @@
#include <stdlib.h>
#include <iostream>
-#include <SDL/SDL.h>
-#include <SDL/SDL_main.h>
-#include <SDL/SDL_ttf.h>
+#include <SDL.h>
+#include <SDL_main.h>
+#include <SDL_ttf.h>
#include "main.h"
#include "utils.h"
#include "storage.h"
diff --git a/screen.cpp b/screen.cpp
index a64dd31..7e48934 100644
--- a/screen.cpp
+++ b/screen.cpp
@@ -1,4 +1,4 @@
-#include <SDL/SDL.h>
+#include <SDL.h>
#include "screen.h"
#include "exceptions.h"
#include "unicode.h"
diff --git a/screen.h b/screen.h
index 12e99ab..2b5253d 100644
--- a/screen.h
+++ b/screen.h
@@ -2,7 +2,7 @@
#define __SCREEN_H__
-#include "SDL/SDL.h"
+#include "SDL.h"
#include <vector>
#include <list>
diff --git a/sound.cpp b/sound.cpp
index 3725245..998245f 100644
--- a/sound.cpp
+++ b/sound.cpp
@@ -1,7 +1,7 @@
#include "sound.h"
#include <iostream>
-#include <SDL/SDL_events.h>
+#include <SDL_events.h>
#include "resources.h"
diff --git a/sound.h b/sound.h
index 44e587e..dc2a449 100644
--- a/sound.h
+++ b/sound.h
@@ -4,7 +4,7 @@
#include <string>
#include <map>
-#include <SDL/SDL_mixer.h>
+#include <SDL_mixer.h>
class Sound
diff --git a/utils.h b/utils.h
index f4188cb..9ce7cb1 100644
--- a/utils.h
+++ b/utils.h
@@ -1,7 +1,7 @@
#ifndef __UTILS_H__
#define __UTILS_H__
-#include <SDL/SDL.h>
+#include <SDL.h>
#include <string>
#ifdef WIN32
#include <sys/time.h>
diff --git a/widgets.h b/widgets.h
index ce417ba..0bd7753 100644
--- a/widgets.h
+++ b/widgets.h
@@ -4,7 +4,7 @@
#include <string>
#include <list>
#include <set>
-#include <SDL/SDL.h>
+#include <SDL.h>
#include "font.h"
关于c++ - 如何与SDL库链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51971681/
问题解决了 转到底部查看解决方案。 大家好,我用谷歌搜索了很长时间,但没有找到任何东西,所以,我们开始吧: 我有这样的设置: Compiler: MinGW IDE: Netbeans Library
如何在 SDL 中创建一个插入主窗口的新窗口?所以它可以是有重点的,有单独的绘图上下文和单独的处理事件。 最佳答案 窗中窗 您可以使用下面的示例在窗口中创建一个窗口。该示例将生成两个窗口,其中 sub
我是 SDL 的新手,我只是好奇为什么 sdl 使用静态和动态库?我的意思是,sdl.dll 中有哪些函数,为什么它是动态链接而不是静态链接?谢谢。 最佳答案 SDL.dll包含您在 SDL 中使用的
我通过 brew 在我的 mac 上安装了 SDL,但我无法包含它!这是我太简单的代码: #include int main(){ return 0; } 用cc编译时,CC找不到SDL.h
我正在尝试制作一个以恒定帧速率运行的 SDL 程序。但是我发现即使我的程序滞后很多并且跳过了很多帧(即使它以低帧运行并且没有渲染太多)。 你们有什么建议可以让我的程序运行更流畅吗? #include
我目前正在编写一款非常复杂和狡猾的游戏,它会让您充满敬畏和胜利 - 哦,好吧,这是 15 个谜题,我只是在熟悉 SDL。 我在窗口模式下运行,并使用 SDL_Flip 作为一般情况的页面更新,因为它会
我知道 SDL_TEXTUREACCESS_STATIC 和 SDL_TEXTUREACCESS_TARGET 之间的区别。我正在为一款游戏编写 SDL 后端,该游戏的平台无关核心不会告诉平台相关纹理
我们最近移植了 Bitfighter从 GLUT 到 SDL。这样做有很多好处,但也有一些缺点,特别是在窗口管理领域。 Bitfighter 在固定纵横比窗口(800x600 像素)中运行。用户可以将
我正在尝试使用 SDL 2.0 了解整个 2D 加速渲染过程。 所以我的问题是在屏幕上绘制圆圈最有效的方法是什么,为什么? 一些方法是: 首先创建一个软件表面,然后在该表面上绘制必要的像素,然后从该表
我正在尝试将纹理保存到 png 中,而我唯一得到的是 是屏幕的一部分的屏幕截图。 我的代码示例: src_texture = SDL_CreateTextureFromSurface( render
我正在使用 SDL1.2 在我的 openGL 框架中处理窗口管理。 程序运行时是否可以在不调用 SDL_Quit() 的情况下破坏窗口(表面)? ? 背景:我的框架实际上只是多媒体环境中的一个 gf
如何在 SDL 中缩放 Sprite ? 最佳答案 SDL 不直接提供缩放功能,但有 an additional library called SDL_gfx它提供旋转和缩放功能。还有another
我刚刚开始使用SDL2_ttf。我已经弄清楚如何使用 TTF_RenderText_Blished 在屏幕上获取一些文本,但是如何让它进行换行和自动换行? 似乎不支持\n;它只是创造一个空间而不是沿着
我安装了 FEDORA 和 SDL,并希望在编译时用 C 编程图形,我得到了很多对 SDL_MapRGB、SDL_Init 等的 undefined reference 我搜索了文件系统 SDL.dl
我在我的项目中使用 SDL 库,并且在 Windows 平台上工作。 当我决定将项目迁移到 SDL 2 时,我遇到了一个问题: SDL 1.2 中有一个选项可以将 stdout/stderr 的输出打
我正在尝试使用 Derelict 和 D 编写一个简单的图形测试程序。 当我尝试用 SDL 做几乎任何事情时,它都会出现段错误。这是有问题的代码: import std.stdio; import
我在考虑是否尝试使用 SDL 作为 DirectX 的替代品,似乎我只创建 2D 游戏,但是我找不到任何地方是否需要在最终用户计算机上安装 SDL 才能玩用 C# 开发的游戏,图形使用 SDL。 有人
我想使用 SDL_net 作为一个供少数程序使用的帮助程序库。然而,其中一些程序本身可能已经在使用 SDL。如果我理解正确的话,这意味着我在初始化/释放我的库时不能盲目使用 SDL_Init 和 SD
我希望我的游戏引擎停止将鼠标移动到中心(用于偏航和俯仰相机计算)。我写了一些应该处理它的代码,但鼠标在最小化时仍然移动。 void mainLoop() { // This is the ma
结构SDL_Keysym 有SDL_Scancode 和SDL_Keycode 成员。它们之间有什么区别?该文档并没有真正为我清除它。我都试过了,它们似乎做同样的事情。 最佳答案 参见 the SDL
我是一名优秀的程序员,十分优秀!