我正在尝试编译第一个练习,来自OpenGL红皮书的triangles.cpp(github源代码在这里:https://github.com/openglredbook/examples/tree/master/src)
我已经设法在Visual Studio 2015下使用CMAKE编译它并将整个内容构建到Visual Studio 2015文件中,并且代码正常运行,但我正在尝试手动编译使用Visual Studio命令行编译器cl
创建文件。
所以我试过了:
cl triangles.cpp LoadShaders.cpp /I ...\OGLPG-9th-Edition\OGLPG-9th-Edition\include /I ...\OGLPG-9th-Edition\OGLPG-9th-Edition\lib\glfw\include
此处包含...
以省略目录路径。显然,这没有链接,所以编译器给了我28个未定义的符号(链接)错误。
查看Visual Studio 2015中的链接器输出给出了这个:
/OUT:"C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\bin\01-triangles_d.exe" /MANIFEST /NXCOMPAT /PDB:"C:/Users/Owen/Downloads/OGLPG-9th-Edition/OGLPG-9th-Edition/bin/01-triangles_d.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" "lib\vermilion_d.lib" "glu32.lib" "opengl32.lib" "glfw3_d.lib" /IMPLIB:"C:/Users/Owen/Downloads/OGLPG-9th-Edition/OGLPG-9th-Edition/lib/01-triangles_d.lib" /DEBUG /MACHINE:X64 /INCREMENTAL /PGD:"C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\bin\01-triangles_d.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"01-triangles.dir\Debug\01-triangles_d.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:/Users/Owen/Downloads/OGLPG-9th-Edition/OGLPG-9th-Edition/lib" /LIBPATH:"C:/Users/Owen/Downloads/OGLPG-9th-Edition/OGLPG-9th-Edition/lib/Debug" /LIBPATH:"C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\lib\glfw" /TLBID:1
其中我认为要链接的相关库是:
"lib\vermilion_d.lib" "glu32.lib" "opengl32.lib" "glfw3_d.lib"
所以在编译器中我尝试:
cl triangles.cpp LoadShaders.cpp
/I C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\include
/I C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\lib\glfw\include
glu32.lib opengl32.lib
C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\lib\vermilion_d.lib
C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\lib\glfw3_d.lib
我继续收到链接错误。我在这里做错了什么/不包括什么?我不认为这是重复的,因为我在CL上找不到任何关于Windows编译的内容。
这是最终的编译器输出和错误:
Microsoft (R) Incremental Linker Version 14.00.23506.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:triangles.exe
triangles.obj
LoadShaders.obj
glu32.lib
opengl32.lib
C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\lib\vermilion_d.lib
C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\lib\glfw3_d.lib
triangles.obj : error LNK2019: unresolved external symbol _gl3wInit referenced in function _main
triangles.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
triangles.obj : error LNK2019: unresolved external symbol _glfwTerminate referenced in function _main
triangles.obj : error LNK2019: unresolved external symbol _glfwCreateWindow referenced in function _main
triangles.obj : error LNK2019: unresolved external symbol _glfwDestroyWindow referenced in function _main
triangles.obj : error LNK2019: unresolved external symbol _glfwWindowShouldClose referenced in function _main
triangles.obj : error LNK2019: unresolved external symbol _glfwPollEvents referenced in function _main
triangles.obj : error LNK2019: unresolved external symbol _glfwMakeContextCurrent referenced in function _main
triangles.obj : error LNK2019: unresolved external symbol _glfwSwapBuffers referenced in function _main
triangles.obj : error LNK2019: unresolved external symbol _gl3wDrawArrays referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
triangles.obj : error LNK2019: unresolved external symbol _gl3wBindBuffer referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
triangles.obj : error LNK2019: unresolved external symbol _gl3wEnableVertexAttribArray referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
triangles.obj : error LNK2019: unresolved external symbol _gl3wUseProgram referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
triangles.obj : error LNK2019: unresolved external symbol _gl3wVertexAttribPointer referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
triangles.obj : error LNK2019: unresolved external symbol _gl3wClearBufferfv referenced in function "void __cdecl display(void)" (?display@@YAXXZ)
triangles.obj : error LNK2019: unresolved external symbol _gl3wBindVertexArray referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
triangles.obj : error LNK2019: unresolved external symbol _gl3wGenVertexArrays referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
triangles.obj : error LNK2019: unresolved external symbol _gl3wCreateBuffers referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
triangles.obj : error LNK2019: unresolved external symbol _gl3wNamedBufferStorage referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
LoadShaders.obj : error LNK2019: unresolved external symbol _gl3wAttachShader referenced in function _LoadShaders
LoadShaders.obj : error LNK2019: unresolved external symbol _gl3wCompileShader referenced in function _LoadShaders
LoadShaders.obj : error LNK2019: unresolved external symbol _gl3wCreateProgram referenced in function _LoadShaders
LoadShaders.obj : error LNK2019: unresolved external symbol _gl3wCreateShader referenced in function _LoadShaders
LoadShaders.obj : error LNK2019: unresolved external symbol _gl3wDeleteShader referenced in function _LoadShaders
LoadShaders.obj : error LNK2019: unresolved external symbol _gl3wGetProgramiv referenced in function _LoadShaders
LoadShaders.obj : error LNK2019: unresolved external symbol _gl3wGetShaderiv referenced in function _LoadShaders
LoadShaders.obj : error LNK2019: unresolved external symbol _gl3wLinkProgram referenced in function _LoadShaders
LoadShaders.obj : error LNK2019: unresolved external symbol _gl3wShaderSource referenced in function _LoadShaders
C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\lib\vermilion_d.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'
C:\Users\Owen\Downloads\OGLPG-9th-Edition\OGLPG-9th-Edition\lib\glfw3_d.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'
triangles.exe : fatal error LNK1120: 28 unresolved externals