1
我正嘗試着手編寫一本關於現代OpenGL的書。在這本書中,我需要鏈接一些庫(即freeglut
glew32
vermilion32
)。我已經下載了glew的源代碼並生成了lib。鏈接我生成的庫沒有問題,但它似乎作者使用pragma comment
,它會導致一些鏈接錯誤。無法打開文件'glew_static_vs2010.lib'和編譯註釋
LINK : fatal error LNK1104: cannot open file 'glew_static_vs2010.lib'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.EXE"' : return code '0x2'
在代碼中使用的頭文件中的一個(即vgl.h
),有這些線路
#ifndef __VGL_H__
#define __VGL_H__
// #define USE_GL3W
#ifdef USE_GL3W
#include <GL3/gl3.h>
#include <GL3/gl3w.h>
#else
#define GLEW_STATIC
#include <GL/glew.h>
#ifdef _MSC_VER
# ifdef _DEBUG
# if (_MSC_VER >= 1600)
# pragma comment (lib, "glew_static_vs2010_d.lib")
# else
# pragma comment (lib, "glew_static_d.lib")
# endif
# else
# if (_MSC_VER >= 1600)
# pragma comment (lib, "glew_static_vs2010.lib")
# else
# pragma comment (lib, "glew_static.lib")
# endif
# endif
#endif
#endif
#define FREEGLUT_STATIC
#include <GL/freeglut.h>
#ifdef _MSC_VER
# ifdef _DEBUG
# if (_MSC_VER >= 1600)
# pragma comment (lib, "freeglut_static_vs2010_d.lib")
# else
# pragma comment (lib, "freeglut_static_d.lib")
# endif
# else
# if (_MSC_VER >= 1600)
# pragma comment (lib, "freeglut_static_vs2010.lib")
# else
# pragma comment (lib, "freeglut_static.lib")
# endif
# endif
#endif
#define BUFFER_OFFSET(x) ((const void*) (x))
#endif /* __VGL_H__ */
我不知道爲什麼作者是以下這種方法。我怎樣才能克服這個問題?這是我的Makefile
CC = cl
CFLAGS = /EHsc /c
INCLUDES = \
/I D:\CPP_Projects\CommandPrompt\ModernOpenGL\Books\Opengl_Programming_Guide_8th\oglpg_8th_edition\include
LIBS = \
/LIBPATH:D:\CPP_Projects\CommandPrompt\ModernOpenGL\Books\Opengl_Programming_Guide_8th\oglpg_8th_edition\lib \
freeglut_staticd.lib glew32sd.lib vermilion32_d.lib
all: project
project: triangles.obj LoadShaders.obj
$(CC) /EHsc /Fetest.exe triangles.obj LoadShaders.obj \
/link $(LIBS)
triangles.obj: triangles.cpp
$(CC) $(CFLAGS) triangles.cpp $(INCLUDES)
LoadShaders.obj: LoadShaders.cpp
$(CC) $(CFLAGS) LoadShaders.cpp $(INCLUDES)
clean:
del *.exe *.obj
它仍然拋出這個錯誤'LINK:致命錯誤LNK1104:無法打開文件「glew_static_vs2010 .lib'' – CroCo