体系结构 x86_64 [MAC] 的 SDL2 未定义符号

问题描述

我正在关注 codergopher 的关于使用 SDL2 的 C++ 2D 平台游戏的教程。 我完全按照他在第三集中展示的方法来创建和渲染窗口。

但是当我“制作”游戏时它不起作用...

这是我的代码

main.cpp

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <iostream>

#include "RenderWindow.hpp"

#define WINDOW_TITLE "SDL2"
#define SCREEN_WIDTH 720
#define SCREEN_HEIGHT 480

int main(int argc,char* args[]) {
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUdio | SDL_INIT_JOYSTICK) != 0)
    std::cout << "SDL_Init has Failed. [DEBUG] > " << SDL_GetError() << std::endl;

    if (!(IMG_Init(IMG_INIT_PNG)))
        std::cout << "IMG_Init has Failed. [DEBUG] > " << SDL_GetError() << std::endl;

    RenderWindow window(WINDOW_TITLE,SCREEN_WIDTH,SCREEN_HEIGHT);

    return 0;
}

渲染窗口.hpp

#pragma once
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>

class RenderWindow {
    public:
        RenderWindow(const char* p_title,int p_w,int p_h); // p_ says it's a parameter
    private:
        SDL_Window* window;
        SDL_Renderer* renderer;
};

renderwindow.cpp

#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <iostream>

#include "RenderWindow.hpp"

RenderWindow::RenderWindow(const char* p_title,int p_h) :window(NULL),renderer(NULL) {
    window = SDL_CreateWindow(p_title,SDL_WINDOWPOS_UNDEFINED,p_w,p_h,SDL_WINDOW_SHOWN);

    if (window == NULL)
        std::cout << "Window Failed to init. [DEBUG] > " << SDL_GetError() << std::endl;

    renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED);
}

生成文件

game:
    g++ src/main.cpp -o play -I include -L lib -l SDL2_image -l SDL2_mixer -l SDL2_ttf -l SDL2-2.0.0

所以在我的 sdl2 项目库中使用我的终端输入:“make game”,当我按回车键时,我的控制台返回了那个错误

Undefined symbols for architecture x86_64:
  "RenderWindow::RenderWindow(char const*,int,int)",referenced from:
      _main in main-92fb24.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command Failed with exit code 1 (use -v to see invocation)
make: *** [game] Error 1

有什么问题,我该如何解决?? 预先感谢您的回答!! 祝你有美好的一天!

解决方

问题出在我的 Makefile 中

game:
    g++ src/main.cpp src/renderwindow.cpp -o play -I include -L lib -l SDL2_image -l SDL2_mixer -l SDL2_ttf -l SDL2-2.0.0

添加scr/renderwindow.cpp

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...