我认真地认为我可能已经检查了 stackOverFlow 上的每个 mach-o 链接 id 错误帖子,但找不到解决我的问题的方法……我还不完全理解链接器的工作原理,所以我总是无法弄清楚如何修复这些错误出现时...
我一直在关注这些 YT 教程,一些名叫Konrad Jablonski的人提出了关于使用 C++ 制作 rpg 游戏 [使用 SDL2 和 SDL.image 框架]...我学到了很多关于 rpg 游戏逻辑的知识——这对某人来说绝对是一次很好的学习经历牢牢掌握基础知识,但对 C++ 来说是新手...
在教程的这一点上,他将一个类分成许多子类......一切都很好,直到我开始将一个类分解成许多不同的 .cpp 和 .h 文件......错误消息说:
- 架构 x86_64 的未定义符号:
- “cSprite::draw()”,引用自:
- gMain.o 中的 gMain::gameLoop()
* - ld:未找到架构 x86_64 的符号*
- clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
整个项目在编译之前都是没有错误的,我不完全理解编译器是如何工作的,所以我不知道在尝试调整它时从哪里开始......如果有人知道这些,我可以放这些类错误类型并希望提供帮助-如果不是,我仍然会很感激任何能引导我朝着正确方向前进的东西,只要弄清楚链接器是如何工作的……我还是 stackoverflow 的新手,所以我将无法+1 回复,直到我变得更加活跃,但当我有机会时,我会回报你
-------- gMain.cpp ---------
#include <iostream>
#include "stdafx.h"
#include "gMain.h"
using namespace std;
gMain::gMain(int passed_screenWidth, int passed_screenHeight)
{
screenWidth = passed_screenWidth;
screenHeight = passed_screenHeight;
// quit boolean
quit = false;
// create instance of cSDL class
csdl_setup = new cSDL_Setup(&quit, screenWidth, screenHeight);
grass = new cSprite(csdl_setup->getRenderer(), "data/images.jpeg", 0, 0, screenWidth, screenHeight);
bruce_Lee = new cSprite(csdl_setup->getRenderer(), "/Users/jamesbryant/Desktop/gamee/gamee/lee.bmp", 300, 250, 50, 100);
}
gMain::~gMain(void)
{
}
void gMain::gameLoop(void)
{
// game loop logic
while (!quit && csdl_setup->getMainEvent() ->type != SDL_QUIT)
{
csdl_setup->begin();
grass->draw();
bruce_Lee->draw();
csdl_setup->end();
}
}
------ gMain.h ------
#ifndef __game__gMain__
#define __game__gMain__
#pragma once
//#include <iostream>
//#include <SDL2/SDL.h>
//#include <SDL2_image/SDL_image.h>
//#include <SDL2/SDL_audio.h>
#include "cSDL_Setup.h"
#include "cSprite.h"
using namespace std;
class gMain
{
public:
gMain(int passed_screenWidth, int passed_screenHeight);
~gMain(void);
void gameLoop();
private:
int screenWidth;
int screenHeight;
bool quit;
//cSprite
class cSprite* grass;
class cSprite* bruce_Lee;
// cSDL_Setup class object
class cSDL_Setup* csdl_setup;
};
#endif /* defined(__game__gMain__) */
----- cSprite.cpp --------
#include "stdafx.h"
#include "cSprite.h"
//#include "gMain.h"
//#include <SDL2/SDL_main.h>
//#include <SDL2/SDL.h>
//#include "cSDL_Setup.h"
using namespace std;
void draw(SDL_Renderer, SDL_Texture, SDL_Rect);
cSprite::cSprite(SDL_Renderer* passed_renderer, string filePath, int x, int y, int w, int h)
{
renderer = passed_renderer;
//... image
image = NULL;
image = IMG_LoadTexture(renderer,filePath.c_str());
// image error message
if (image == NULL)
{
cout<<"Couldnt load image..."<<filePath.c_str()<<endl;
}
//image dimensions
rect->x = x;
rect->y = y;
rect->w = w;
rect->h = h;
};
cSprite::~cSprite(void)
{
SDL_DestroyTexture(image);
}
//get methods
//SDL_Rect* cSprite::getRect()
//{
// return rect;
//}
//get methods
//SDL_Texture* cSprite::getImage()
//{
// return image;
//}
void cSprite::draw()
{
SDL_RenderCopy(renderer, image, NULL, rect);
}
-------- cSprite.h --------
#ifndef __game__cSprite__
#define __game__cSprite__
#pragma once
#include <iostream>
#include <SDL2/SDL_main.h>
#include <SDL2/SDL.h>
using namespace std;
class cSprite
{
public:
cSprite(SDL_Renderer* passed_renderer, string filePath, int x, int y, int w, int h);
~cSprite(void);
void draw();
private:
SDL_Texture* image;
SDL_Rect* rect;
SDL_Renderer* renderer;
};
#endif /* defined(__game__cSprite__) */
------ cSDL_Setup.cpp --------
#include "stdafx.h"
#include "cSDL_Setup.h"
//#include "gMain.h"
using namespace std;
cSDL_Setup::cSDL_Setup(bool* quit, int screenWidth, int screenHeight)
{
// create window
window = NULL;
window = SDL_CreateWindow("rWDY_pWDR", 100, 100, screenWidth, screenHeight, SDL_WINDOW_RESIZABLE);
// if window couldnt be created...
if (window == NULL)
{
cout<<"Window couldnt be created..."<<endl;
*quit = true;
//exit(0);
}
//create renderer
renderer = NULL;
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
// initialize images
mainEvent = new SDL_Event();
}
cSDL_Setup::~cSDL_Setup(void)
{
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
delete mainEvent;
}
//get methods
SDL_Renderer* cSDL_Setup::getRenderer()
{
return renderer;
}
SDL_Event* cSDL_Setup::getMainEvent()
{
return mainEvent;
}
void cSDL_Setup::begin()
{
SDL_PollEvent(mainEvent);
SDL_RenderClear(renderer);
}
void cSDL_Setup::end()
{
SDL_RenderPresent(renderer);
}
------- cSDL_Setup.h -------
#ifndef __game__cSDL_Setup__
#define __game__cSDL_Setup__
#pragma once
//#include <iostream>
//#include "gMain.h"
using namespace std;
class cSDL_Setup
{
public:
cSDL_Setup(bool* quit, int screenWidth, int screenHeight); // 1 parameter(s): 'quit'
~cSDL_Setup(void);
// 'get' functions
SDL_Renderer* getRenderer();
SDL_Event* getMainEvent();
void begin();
void end();
private:
SDL_Window* window;
SDL_Renderer* renderer;
SDL_Event* mainEvent;
};
#endif /* defined(__game__cSDL_Setup__) */
-------- stdafx.h ---------
#ifndef gamee_stdafx_h
#define gamee_stdafx_h
#pragma once
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2_image/SDL_image.h>
#include <SDL2_mixer/SDL_mixer.h>
#endif