SFML community forums
Help => General => Topic started by: edumoette on July 10, 2012, 02:59:04 am
-
Been trying to follow the open gl tutorial. I copied this code down and analyzed it. I got these same errors when i copied it myself, so i decided to copy it off of the tutorial and i got the same two errors. What am i doing wrong?
Errors:
"
-------------- Build: Debug in SFML ---------------
Linking console executable: bin\Debug\SFML.exe
obj\Debug\main.o: In function `main':
C:/Users/Owner/Desktop/Everything C++/main.cpp:29: undefined reference to `glViewport@16'
C:/Users/Owner/Desktop/Everything C++/main.cpp:34: undefined reference to `glClear@4'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
2 errors, 0 warnings"
Here is the copy.paste code.
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
int main()
{
// create the window
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
window.setVerticalSyncEnabled(true);
// load resources, initialize the OpenGL states, ...
// run the main loop
bool running = true;
while (running)
{
// handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
// end the program
running = false;
}
else if (event.type == sf::Event::Resized)
{
// adjust the viewport when the window is resized
glViewport(0, 0, event.size.width, event.size.height);
}
}
// clear the buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw...
// end the current frame (internally swaps the front and back buffers)
window.display();
}
// release resources...
return 0;
}
-
Have you linked what needs to be linked?
You will then need to link your program to the OpenGL library. Unlike what it does with the headers, SFML can't provide a unified way of linking OpenGL. Therefore, you need to know which library to link to according to what OS you're using ("opengl32" on Windows, "GL" on Linux, etc.). Same thing for GLU, in case you use it too: "glu32" on Windows, "GLU" on Linux, etc.
-
I did see that part. I couldnt find any files named opengl32 so i just assumed it was already linked. Was i wrong?
-
OpenGL libraries are shipped with the compiler. Don't try to find the files, just add them to your linker settings.
In case you don't know exactly how to do that, don't hesitate to use Google. It has millions of useful links for such a simple task ;)