首页 文章

如何在程序中包含SDL(Linux) . 对SDL_Init()的未定义引用

提问于
浏览
0

我正在尝试一切来运行此测试程序并不断收到此错误消息:

克对象/ src_files / display.o对象/ src_files / main.o -o程序-L / USR /本地/ lib中的对象/ src_files / main.o:在功能 main': main.cpp:(.text+0x16): undefined reference to SDL_Init” collect2:错误:LD返回1个退出状态化妆: *** [程序]错误1

这是我的测试程序的样子:

#include <iostream>
#include <string>
#include <GL/glew.h>
#include <SDL2/SDL.h>
#include <glm/glm.hpp>
#include <display.hpp>

using namespace std;

int main(int argc, char **argv)
{
        SDL_Init(SDL_INIT_EVERYTHING);
        glm::vec3 my_v(0, 0, 0);
        string s  = "This is a Test";
        cout << s << endl;


        return 0;
}

这是我的MAKEFILE:

APP = program

CC = g++

SRCDIR  = src_files
OBJDIR  = objects

H_DIR = header_files
INC_DIR = include
LIB_DIR = /usr/local/lib

SRCS    := $(shell find $(SRCDIR) -name '*.cpp')
SRCDIRS := $(shell find . -name '*.cpp' -exec dirname {} \; | uniq)
OBJS    := $(patsubst %.cpp,$(OBJDIR)/%.o,$(SRCS))

CFLAGS  = -Wall -pedantic -ansi -lSDL
LDFLAGS = 

#update here
_H = $(HD_DIR)/display.hpp 
SDL_H = $(INC_DIR)/SDL.h
MAIN_H = $(_H) $(SDL_H)

all: $(APP)

$(APP) : buildrepo $(OBJS)
    $(CC) $(OBJS) $(LDFLAGS) -o $@

$(OBJDIR)/%.o: %.cpp
    $(CC) $(CFLAGS) -I$(INC_DIR) -I$(H_DIR) -c $< -o $@

#update here
$(OBJ_DIR)/main.o: $(MAIN_H)
$(OBJ_DIR)/display.o: $(_H) $(SDL_H)

clean:
    $(RM) $(OBJS)

distclean: clean
    $(RM) $(APP)

buildrepo:
    @$(call make-repo)

define make-repo
   for dir in $(SRCDIRS); \
   do \
    mkdir -p $(OBJDIR)/$$dir; \
   done
endef

我运行MAKEFILE:make -f MAKEFILE我还能尝试什么?

谢谢

1 回答

  • 2

    在Makefile中更改

    CFLAGS  = -Wall -pedantic -ansi -lSDL
    LDFLAGS =
    

    CFLAGS  = -Wall -pedantic -ansi 
    LDFLAGS = -lSDL
    

    -lSDL 实际上是一个链接器标志,而不是编译器 .

相关问题