Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Can';我不知道如何使用SDL2正确格式化Makefile。未定义引用_C++_Ubuntu_Makefile_Sdl 2 - Fatal编程技术网

C++ Can';我不知道如何使用SDL2正确格式化Makefile。未定义引用

C++ Can';我不知道如何使用SDL2正确格式化Makefile。未定义引用,c++,ubuntu,makefile,sdl-2,C++,Ubuntu,Makefile,Sdl 2,生成文件: OBJS = Instantiation Exec_NAME = Test.exe CC = g++ #Compiler name COMPILER_FLAGS = -c -g -Wall -std=c++11 #Issue exists somewhere in these next 3 lines, but what, how, why :( ? INC = -I/SDLDEPS/include LIB = -L/SDLDEPS/lib LINKER_FLAGS = -lming

生成文件:

OBJS = Instantiation
Exec_NAME = Test.exe
CC = g++ #Compiler name
COMPILER_FLAGS = -c -g -Wall -std=c++11
#Issue exists somewhere in these next 3 lines, but what, how, why :( ?
INC = -I/SDLDEPS/include
LIB = -L/SDLDEPS/lib
LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2 #just saw this a lot, not sure what the mingw32 is.

#inclusion of $(INC) $(LIB) $(LINKER_FLAGS) not right
all: $(Exec_NAME)
$(Exec_NAME): $(OBJS).o
    $(CC) -o $(Exec_NAME) $(OBJS).o
Instantiation.o: $(OBJS).cpp
    $(CC) $(COMPILER_FLAGS) $(INC) $(LIB) $(LINKER_FLAGS) $(OBJS).cpp

clean:
        rm -f $(Exec_NAME) $(OBJS).o
rebuild:
        make clean
        make


我对使用makefiles进行链接和“高级”操作相当陌生。但是几个小时 谷歌搜索我不知道为什么我总是得到: /mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:13:未定义对
SDL\u DestroyWindow'/usr/bin/ld的引用:/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:14:未定义对
SDL\u的引用
/usr/bin/ld:/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:15:对
SDL\u Quit'/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window的未定义引用。cpp:19:对
SDL\u Init'的未定义引用
/usr/bin/ld:/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:23:对
SDL\u CreateWindow'/usr/bin/ld的未定义引用:/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:28:对
SDL\u CreateRenderer'的未定义引用
/usr/bin/ld:Instantiation.o:in function
Window::pollEvents():/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:38:未定义对
SDL\u PollEvent'的引用 /usr/bin/ld:Instantiation.o:in function
Window::Clear()const':/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:72:对
SDL\u SetRenderDrawColor'的未定义引用 /usr/bin/ld:/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:73:未定义对
SDL\u RenderClear'/usr/bin/ld的引用:/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:81:未定义对
SDL\u SetRenderDrawColor'的引用
/usr/bin/ld:/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:82:对
SDL\u renderfill'/usr/bin/ld的未定义引用:/mnt/c/users/nichorsin598/source/repos/Self/TestSDL/Window.cpp:88:对
SDL\u RenderPresent'的未定义引用

所有的SDL都是未定义的,但是我没有得到一个错误,说SDL.h是未定义的,所以它要么与库有关,要么与其他有关 文件路径是: TestSDL-基本目录 TestSDL\SDLDeps-包括两个文件夹include和lib 包括-包括所有.h文件 库-包括SDL2.dll、SDL2、SDL2Main、SDL2test
如果有人能帮忙,我将不胜感激。

对于不同的组件,有许多不同的
SDL2
库。我使用以下方式获取编译和链接器标志:

SDL2_INCS := $(shell pkg-config sdl2 --cflags) \
    $(shell pkg-config SDL2_image --cflags) \
    $(shell pkg-config SDL2_ttf --cflags) \
    $(shell pkg-config SDL2_net --cflags) \
    $(shell pkg-config SDL2_mixer --cflags)

SDL2_LIBS := $(shell pkg-config sdl2 --libs) \
    $(shell pkg-config SDL2_image --libs) \
    $(shell pkg-config SDL2_ttf --libs) \
    $(shell pkg-config SDL2_net --libs) \
    $(shell pkg-config SDL2_mixer --libs)

Instantiation.o: $(OBJS).cpp
    $(CC) $(COMPILER_FLAGS) $(SDL2_INCS) -o Instantiation.o $(SDL2_LIBS) $(OBJS).cpp

您应该能够向单个
pkg config
调用传递多个lib。
//Window.h I don't think Window.cpp is necessary as the issue is linking, I think.
#ifndef WINDOW_H
#define WINDOW_H
#include <string>
#include "SDLDeps/include/SDL.h"
//#include "SDL.h"
#include <iostream>

class Window {
private:
    std::string title;
    int width, height;

    bool closed;    
    
    bool init();

    SDL_Window* window;
    SDL_Renderer* renderer;
public:
    Window(const std::string&, int = 800, int = 600);
    ~Window();
    
    void pollEvents();
    void Clear() const;
    inline bool isClosed() { return closed; }
};
#endif // !WINDOW_H
//    Instantiation.cpp- just a file that includes files that I am compiling:
        #include "Window.cpp"
        #include "Main.cpp"
SDL2_INCS := $(shell pkg-config sdl2 --cflags) \
    $(shell pkg-config SDL2_image --cflags) \
    $(shell pkg-config SDL2_ttf --cflags) \
    $(shell pkg-config SDL2_net --cflags) \
    $(shell pkg-config SDL2_mixer --cflags)

SDL2_LIBS := $(shell pkg-config sdl2 --libs) \
    $(shell pkg-config SDL2_image --libs) \
    $(shell pkg-config SDL2_ttf --libs) \
    $(shell pkg-config SDL2_net --libs) \
    $(shell pkg-config SDL2_mixer --libs)

Instantiation.o: $(OBJS).cpp
    $(CC) $(COMPILER_FLAGS) $(SDL2_INCS) -o Instantiation.o $(SDL2_LIBS) $(OBJS).cpp