I'm following this tutorial for openGL along with SDL. I'm mildly familiar with SDL and have slightly dipped my toes in openGL. So I'm reading that tutorial and things are going great until I try to actually compile the code... I'm using Cmake to compile the code. It's also important to note that I've just stuck all of the glew headers and libs in with all of the SDL2 libs and headers.
Here's my cmakelists file-
cmake_minimum_required(VERSION 3.7)
project(opengl)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
add_executable(opengl src/main.cpp)
target_link_libraries(opengl ${SDL2_LIBRARIES})
Here's my SDL2-Config.cmake file-
set(SDL2_INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}/include")
# Support both 32 and 64 bit builds
if (${CMAKE_SIZEOF_VOID_P} MATCHES 8)
set(SDL2_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/x64/SDL2.lib;${CMAKE_CURRENT_LIST_DIR}/lib/x64/SDL2main.lib;${CMAKE_CURRENT_LIST_DIR}/lib/x64/glew32.lib;" )
else ()
set(SDL2_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/lib/x86/SDL2.lib;${CMAKE_CURRENT_LIST_DIR}/lib/x86/SDL2main.lib;${CMAKE_CURRENT_LIST_DIR}/lib/x86/glew32.lib;")
endif ()
string(STRIP "${SDL2_LIBRARIES}" SDL2_LIBRARIES)
and here's my main.cpp file-
#include <GL/glew.h>
#include <iostream>
#include <SDL.h>
#include "SDL_opengl.h"
#define GL3_PROTOTYPES 1
#undef main
int main()
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* window = SDL_CreateWindow("My Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 512, 512, SDL_WINDOW_OPENGL);
SDL_GLContext context = SDL_GL_CreateContext(window);
glewInit();
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetSwapInterval(1);
glewExperimental = GL_TRUE;
while(true){
//set color
glClearColor( 1.0, 0.0, 0.5, 1.0 );
// clear back buffer
glClear( GL_COLOR_BUFFER_BIT );
// swap back and front buffer
SDL_GL_SwapWindow(window);
}
return 0;
}
Now this all looks good to me, but I'm no expert.
The confusing part is that the glew functions such as glewInit(), among others, work fine! But when it comes to compile the code I am smacked in the face with two unresolved externals. heres the error code-
PS C:\C++Dev\SDLDEV\openGL\build> cmake --build .
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
main.cpp
main.obj : error LNK2019: unresolved external symbol __imp_glClear referenced in function main [C:\C++Dev\SDLDEV\openGL
\build\opengl.vcxproj]
main.obj : error LNK2019: unresolved external symbol __imp_glClearColor referenced in function main [C:\C++Dev\SDLDEV\o
penGL\build\opengl.vcxproj]
C:\C++Dev\SDLDEV\openGL\build\Debug\opengl.exe : fatal error LNK1120: 2 unresolved externals [C:\C++Dev\SDLDEV\openGL\b
uild\opengl.vcxproj]
any help is very much appreciated!