0

I'm trying to compile the first exercise, triangles.cpp from the OpenGL redbook (the github source is here: https://github.com/openglredbook/examples/tree/master/src)

I have managed to compile this under Visual Studio 2015 by using CMAKE and building the entire thing into a Visual Studio 2015 file, and the code runs properly, but I'm trying to manually compile the file by using the Visual Studio command line compiler, cl.

So I tried:

cl triangles.cpp LoadShaders.cpp /I ...\OGLPG-9th-Edition\OGLPG-9th-Edition\include /I ...\OGLPG-9th-Edition\OGLPG-9th-Edition\lib\glfw\include

The ... has been included here to omit the directory path. Obviously, this hasn't been linked so the compiler gives me 28 undefined symbol (linking) errors.

Looking at the linker output in Visual Studio 2015 gives me this:

/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 

Of which I believe the relevant libraries to link against are:

 "lib\vermilion_d.lib" "glu32.lib" "opengl32.lib" "glfw3_d.lib" 

So in the compiler I try:

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

For which I continue to get a linking error. What am I doing wrong here/not including? I don't think this is a duplicate as I couldn't find anything talking about windows compilation on CL.

Here's the final compiler output and error:

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
Owen Morgan
  • 494
  • 4
  • 6
  • I found a question which seems relevant with your problem. http://stackoverflow.com/questions/12124739/visual-c-library-directories-command-line-equivalent – 0Tech Jan 26 '17 at 13:32
  • Why have you opted to compile your files manually? CMake creates a ready-made solution for you, and fixes all the issues related to includes and linker settings. If that works, why try to do those things manually? – Bartvbl Jan 26 '17 at 13:47
  • :S It says it in your error log.. You are linking a 64bit library with a 32-bit program: `glfw3_d.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'` and `vermilion_d.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'`. Since you can't do that, it should be an error and not just a warning.. It fails to link and now you have unresolved symbols/linker errors. – Brandon Jan 26 '17 at 13:48

0 Answers0