问题描述
我正在尝试编译和运行使用 OpenGL、GLEW、GLFW 和 GLM 的教程 main.cpp。我通常使用 makefile 来清理、编译和运行我的程序。虽然清理和构建工作正常,但当它运行可执行文件时会输出以下错误:make: *** [Makefile:99: run] Error -1073741515
我尝试使用 VSCode 中的集成和外部终端来运行可执行文件,但它仍然无法打开。但是,当我尝试在普通命令提示符/PowerShell 上运行它时,它会清理、编译并运行得非常好。此外,当我注释掉 (ctrl + /
) 使用 GLEW 的每一行并尝试编译和运行时,它工作正常。
虽然是小问题,但我想通过解决这个问题来继续使用 VSCode 的集成终端。
main.cpp:
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <iostream>
using namespace glm;
int main() {
// Initialise GLFW
glewExperimental = true; // Needed for core profile
if( !glfwInit() )
{
fprintf( stderr,"Failed to initialize GLFW\n" );
return -1;
}
glfwWindowHint(GLFW_SAMPLES,4); // 4x antialiasing
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,4); // We want OpenGL 4.6
glfwWindowHint(GLFW_CONTEXT_VERSION_MInor,6);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE); // We don't want the old OpenGL
// Open a window and create its OpenGL context
GLFWwindow* window; // (In the accompanying source code,this variable is global for simplicity)
window = glfwCreateWindow( 1024,768,"Tutorial 01",NULL,NULL);
if( window == NULL ){
fprintf( stderr,"Failed to open GLFW window. If you have an Intel GPU,they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window); // Initialize GLEW
glewExperimental=true; // Needed in core profile
if (glewInit() != GLEW_OK) {
fprintf(stderr,"Failed to initialize GLEW\n");
return -1;
}
// Ensure we can capture the escape key being pressed below
glfwSetInputMode(window,GLFW_STICKY_KEYS,GL_TRUE);
do{
// Clear the screen. It's not mentioned before Tutorial 02,but it can cause flickering,so it's there nonetheless.
glClear( GL_COLOR_BUFFER_BIT );
// Draw nothing,see you in tutorial 2 !
// Swap buffers
glfwSwapBuffers(window);
glfwPollEvents();
} // Check if the ESC key was pressed or the window was closed
while( glfwGetKey(window,GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
glfwWindowShouldClose(window) == 0 );
}
制作文件:
#
# 'make' build executable file 'main'
# 'make clean' removes all .o and executable files
#
# define the Cpp compiler to use
CXX = g++
# define any compile-time flags
CXXFLAGS := -std=c++17 -Wall -Wextra -g
# define library paths in addition to /usr/lib
# if I wanted to include libraries not in /usr/lib I'd specify
# their path using -Lpath,something like:
LFLAGS += -LC:/mingw64/x86_64-w64-mingw32/bin
LFLAGS += -LC:/mingw64/x86_64-w64-mingw32/lib
# define output directory
OUTPUT := output
# define source directory
SRC := src
# define include directory
INCLUDE := include
# define lib directory
LIB := lib
ifeq ($(OS),Windows_NT)
MAIN := main.exe
SOURCEDirs := $(SRC)
INCLUDEDirs := $(INCLUDE)
LIBDirs := $(LIB)
FIXPATH = $(subst /,\,$1)
RM := del /q /f
MD := mkdir
else
MAIN := main
SOURCEDirs := $(shell find $(SRC) -type d)
INCLUDEDirs := $(shell find $(INCLUDE) -type d)
LIBDirs := $(shell find $(LIB) -type d)
FIXPATH = $1
RM = rm -f
MD := mkdir -p
endif
# define any directories containing header files other than /usr/include
INCLUDES := $(patsubst %,-I%,$(INCLUDEDirs:%/=%))
INCLUDES += -IC:/Users/kimda/Desktop/Projects/C++/Libraries/glm
INCLUDES += -IC:/mingw64/x86_64-w64-mingw32/include
# define the C libs
LIBS := $(patsubst %,-L%,$(LIBDirs:%/=%))
LIBS += -lglew32
LIBS += -lopengl32
LIBS += -lglfw3
LIBS += -lgdi32
LIBS += -lglu32
# define the C source files
SOURCES := $(wildcard $(patsubst %,%/*.cpp,$(SOURCEDirs)))
# define the C object files
OBJECTS := $(SOURCES:.cpp=.o)
#
# The following part of the makefile is generic; it can be used to
# build any executable just by changing the deFinitions above and by
# deleting dependencies appended to the file from 'make depend'
#
OUTPUTMAIN := $(call FIXPATH,$(OUTPUT)/$(MAIN))
all: $(OUTPUT) $(MAIN)
@echo Building complete!
$(OUTPUT):
@$(MD) $(OUTPUT)
$(MAIN): $(OBJECTS)
@$(CXX) $(CXXFLAGS) $(INCLUDES) -o $(OUTPUTMAIN) $(OBJECTS) $(LFLAGS) $(LIBS)
# this is a suffix replacement rule for building .o's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file)
# (see the gnu make manual section about automatic variables)
.cpp.o:
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
.PHONY: clean
clean:
@$(RM) $(OUTPUTMAIN)
@$(RM) $(call FIXPATH,$(OBJECTS))
@echo Cleanup complete!
run: clean all
@./$(OUTPUTMAIN)
@echo Executing complete!
在 VSCode 终端上清理、编译、运行:
Cleanup complete!
Building complete!
make: *** [Makefile:99: run] Error -1073741515
在命令提示符/Powershell 上清理、编译、运行:
Cleanup complete!
Building complete!
Executing complete!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)