我正在尝试运行此测试程序并继续收到此错误消息:
g ++ objects / src_files / display.o objects / src_files / main.o -o program -L / usr / local / lib
objects / src_files / main.o:在函数main':
main.cpp:(.text+0x16): undefined reference to
SDL_Init'中
collect2:错误:ld返回1退出状态
make:*** [program] Error 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
我使用:make -f MAKEFILE运行MAKEFILE 我还能尝试什么?
由于
答案 0 :(得分:2)
在Makefile中更改
CFLAGS = -Wall -pedantic -ansi -lSDL
LDFLAGS =
要
CFLAGS = -Wall -pedantic -ansi
LDFLAGS = -lSDL
-lSDL
实际上是一个链接器标志,而不是编译器。