i have seen this error a lot in the setup of opengl, but now that it is working, there is this error now. all the rest is working just this and glClearColor isnt
i think that all the commands in gl.h and glew.h might not be working i havent tested yet, and yes they are added to the project as they should be, the libraries are loading well, but i just cant call functions from them. i was using glut and glew before with no problem, what might have happened in here?
#include<map>
#include<iostream>
#include<stdio.h>
#include<chrono>
#include<stdlib.h>
#define WIDTH 320
#define HEIGHT 200
struct key {
};
GLFWwindow* window;
GLFWmonitor* monitor;
bool running = 1, windowed;
std::map<int, key> keyMap;
void update(){}
void input(){}
void draw(){
glClear(GL_COLOR_BUFFER_BIT);
}
int main() {
glfwWindowHint(GLFW_SAMPLES, 1);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
if (!glfwInit()) fprintf(stderr, "opengl error\n");
window = glfwCreateWindow(WIDTH, HEIGHT, "end", NULL, NULL);
if (window == NULL) {std::cout << "window error\n" << std::endl; glfwTerminate();}
glfwMakeContextCurrent(window);
monitor = glfwGetPrimaryMonitor();
while (running)
{
update();
input();
draw();
}
glfwDestroyWindow(window);
glfwTerminate();
}
the errors are just these:
warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
error LNK2019: unresolved external symbol __imp__wglGetProcAddress#4 referenced in function "void __cdecl draw(void)" (?draw##YAXXZ)
error LNK1120: 1 unresolved externals
I can not for the life of me figure out why the implementation functions aren't being seen and the call to the constructor is unresolved. Any ideas would be appreciated.
Error:
1>Debug\MeGLWindow.obj : warning LNK4042: object specified more than once; extras ignored
1>MeApp.obj : error LNK2019: unresolved external symbol "public: __thiscall MeGLWindow::MeGLWindow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0MeGLWindow##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "public: __thiscall MeApp::MeApp(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0MeApp##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
1>C:\Users\FrizzleFry\documents\visual studio 2012\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe : fatal error LNK1120: 1 unresolved externals
App Header
#ifndef ME_APP
#define ME_APP
#include "MeGLWindow.h"
#include <string>
class MeApp {
private:
MeGLWindow* meWind;
std::string app;
public:
MeApp() {}
MeApp(std::string);
~MeApp();
void run();
};
#endif
The implementation
#include "MeApp.h"
#include <SDL.h>
#include <gl\glew.h>
#include <SDL_opengl.h>
#include <gl\glu.h>
#include <string>
MeApp::MeApp(std::string appName) {
app = appName;
meWind = new MeGLWindow(app);
}
MeApp::~MeApp() {
//delete[] meWind;
//meWind = NULL;
}
void MeApp::run() {
bool quit = false;
//Event handler
SDL_Event e;
//Enable text input
SDL_StartTextInput();
//While application is running
while( !quit )
{
//Handle events on queue
while( SDL_PollEvent( &e ) != 0 )
{
//User requests quit
if( e.type == SDL_QUIT )
{
quit = true;
}
//Handle keypress with current mouse position
else if( e.type == SDL_TEXTINPUT )
{
int x = 0, y = 0;
SDL_GetMouseState( &x, &y );
//handleKeys( e.text.text[ 0 ], x, y );
}
//meWind->show();
}
//Disable text input
SDL_StopTextInput();
}
}
The window header and implementation:
#ifndef ME_GL_WINDOW
#define ME_GL_WINDOW
#include "SDL.h"
#include "GL\glew.h"
#include "SDL_opengl.h"
#include "GL\glu.h"
#include <string>
class MeGLWindow {
private:
std::string appName;
int SCREEN_WIDTH, SCREEN_HEIGHT;
SDL_Window* meWind;
SDL_GLContext meContext;
public:
MeGLWindow() {}
MeGLWindow(std::string);
~MeGLWindow();
void show();
};
#endif
cpp
#include <SDL.h>
#include <gl\glew.h>
#include <SDL_opengl.h>
#include <gl\glu.h>
#include <string>
#include "MeGLWindow.h"
#include <iostream>
#include <string>
MeGLWindow::MeGLWindow(std::string app) {
appName = app;
if(SDL_Init( SDL_INIT_VIDEO) < 0) {
std::cout << "Failed to initilialize SDL!" << std::endl;
exit(1);
}
SCREEN_HEIGHT = 640;
SCREEN_WIDTH = 480;
//Use OpenGL 3.1 core
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
//Create window
meWind = SDL_CreateWindow( appName.c_str() , SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
if( meWind == NULL )
{
std::cout << "Failed to create window!" << std::endl;
exit(2);
}
meContext = SDL_GL_CreateContext( meWind );
if( meContext = NULL ) {
std::cout << "Failed to create GL Context!" << std::endl;
exit(3);
}
glewExperimental = GL_TRUE;
GLenum glewerror = glewInit();
if( glewerror != GLEW_OK )
{
std::cout << "Error initializing GLEW!" << std::endl;
exit(4);
}
//use vsync
if( SDL_GL_SetSwapInterval( 1 ) < 0 )
{
std::cout << "Unable to set vsync!" << std::endl;
//printf( "warning: unable to set vsync! sdl error: %s\n", sdl_geterror() );
}
//initialize opengl
//( !initgl() )
}
MeGLWindow::~MeGLWindow() {
//glDeleteProgram( gProgramID );
//Destroy window
SDL_DestroyWindow( meWind );
meWind = NULL;
//Quit SDL subsystems
SDL_Quit();
}
void MeGLWindow::show() {
glClear( GL_COLOR_BUFFER_BIT );
SDL_GL_SwapWindow( meWind );
}
call file
#include <SDL.h>
#include <gl\glew.h>
#include <SDL_opengl.h>
#include <gl\glu.h>
#include <stdio.h>
#include <string>
#include "MeApp.h"
int main( int argc, char* args[] )
{
MeApp app("My Application");
app.run();
return 0;
}
EDIT
Well, I thought that maybe the .obj file was corrupted and had tried deleting it and rebuilding. They were rebuilt but still gave me this error.
If I introduce non-sensical code (I added the line a in the MeGLWindow.h as a class member) and the build gloriously failed due to:
1>c:\users\frizzlefry\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\meglwindow.h(22): error C2146: syntax error : missing ';' before identifier 'MeGLWindow'
1>c:\users\frizzlefry\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\meglwindow.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>
1>Build FAILED.
I then went to the project directory and deleted the entire debug folder save the two .dll files.
I then deleted the nonsensical code and rebuilt the solution to no avail. I received the same unresolved external symbol error.
When I originally created the files, I accidently named the file meGLWindow.h and I started getting this error after renaming the file. It wouldn't let me just rename the file with a capital, it would say that the file already existed. So I renamed it to something different, (2MeGLWindow.h) and then deleted the original file in the project folder and renamed it back to MeGLWindow.h
Then this error occured (but I had added code and didn't think this was the cause) especially since if I remove the MeGLWindow function calls (like new MeGLWindow(app);) then no build error occurs. It's only if I try to have either the main function or the app class create an instance of MeGLWindow.
I'm considering just copy pasta into a new solution. But maybe there are some sort of list of source files in the solution that are pointing to the wrong meGLWindow.h file that I originally created?
EDIT2
Just got fed up, it was 5 files. I made a new project, copy pasted the header and cpp files and it works like a charm. I will never simply rename a header file ever again.
Warning LNK4042 is a bit deceptive, actually it means that object FILE was specified more that once, so for some reason you already have MeGLWindow.obj, and it does not contain a symbol for the MeGLWindow(std::string), hence the error. Possible reasons are:
Build can't delete old MeGLWindow.obj from the times when that constructor was not implemented yet.
Build doesn't even try to delete old MeGLWindow.obj.
Some other MeGLWindow.obj pops up in the build before the proper one.
Solution: try clean build/rebuild/manually deleting Debug/MeGLWindow.obj; Carefully check build options, output file names. Check security/UAC/access rights. Hopefully that helps.
I have recently purchased a new laptop and got a new version of VS from my school. And I'm having a little trouble setting up my libraries.
I created a basic SDL_Window, as well as a SDL_GLContext.
I'm able to include my libraries and run the program, but I can't call functions like glClearColor, or glGetString(GL_VERSION). I get a rather strage warning and an error that I have never seen before, I'm guessing it's related to the 2013 version?
I have tried ignoring all specific default libraries, as well as trying to change the programtype (Multithreaded DLL, those 4).
And I have made sure all the dll-files are in place in my system folder.
What makes me wonder is the fact that glewInit() works, but not glClearColor() etc...
Output:
1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib'
conflicts with use of other libs; use /NODEFAULTLIB:library
1>Window.obj : error LNK2019: unresolved external symbol
__imp__glClearColor#16 referenced in function "public: void __thiscall Window::initOpenGL(void)" (?initOpenGL#Window##QAEXXZ)
1>C:\Users\Aleksander\documents\visual studio 2013\Projects\OpenGL
Test\Debug\OpenGL Test.exe : fatal error LNK1120: 1 unresolved
externals
Header:
#pragma once
#include <SDL.h> //Tested OK
#include <SDL_image.h> //Tested OK
#include <SDL_mixer.h> //Tested OK
#include <SDL_net.h> //Tested OK
#include <OpenGL\glew.h> //?
#include <freeglut\freeglut.h> //?
#include <gl\GL.h> //?
#include <glm\glm.hpp> //Tested OK
#include <iostream> //Standard OK
#include <Box2D\Box2D.h> //Tested OK
using namespace std;
class Window {
SDL_Window *window;
SDL_GLContext context;
bool quit;
public:
Window();
~Window();
void initSDL();
void initOpenGL();
void run();
};
Source:
#include "Window.h"
Window::Window() {
printf("Starting window...\n");
//Initialize window
quit = false;
initSDL();
initOpenGL();
//Run window
run();
}
Window::~Window() {
printf("Closing window...\n");
//Clear window memory
SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
//Close window library
SDL_Quit();
}
void Window::initSDL() {
if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
quit = true;
printf("Unable to initialize SDL!\n");
}
else {
//Create window
const char *title = "OpenGL Test";
int pos = SDL_WINDOWPOS_CENTERED;
int w = 800;
int h = 600;
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
window = SDL_CreateWindow(title, pos, pos, w, h, flags);
//Create OpenGL context
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
context = SDL_GL_CreateContext(window);
}
}
void Window::initOpenGL() {
GLenum init = glewInit();
if (init != GLEW_OK) {
quit = true;
printf("Unable to initialize OpenGL!\n");
printf("Error: %s!\n", glewGetErrorString(init));
}
else {
//printf("Vendor: %s\n", glGetString(GL_VENDOR));
//printf("Version: %s\n", glGetString(GL_VERSION));
//printf("Renderer: %s\n", glGetString(GL_RENDERER));
}
}
void Window::run() {
printf("Window started running!\n");
SDL_Event event;
while (!quit) {
SDL_GL_SwapWindow(window);
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
}
}
}
}
I have problem with compiling c code which worked earlier before updating o OS X Mavericks.
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xutil.h>
#include <X11/Xlib.h>
#include <GL/glx.h>
char WINDOW_NAME[] = "Graphics Window";
char ICON_NAME[] = "Icon";
Display *display;
int screen;
Window main_window;
unsigned long foreground, background;
static int snglBuf[] = {GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 12, None};
static int dblBuf[] = {GLX_RGBA, GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1, GLX_DEPTH_SIZE, 12,GLX_DOUBLEBUFFER, None};
Bool doubleBuffer = True;
XVisualInfo *vi;
GLXContext cx;
Colormap cmap;
XSetWindowAttributes swa;
Bool recalcModelView = True;
int dummy;
void connectX()
{
display = XOpenDisplay(NULL);
if (display == NULL) {fprintf(stderr, "Cannot connect to X\n");
exit(1);}
screen = DefaultScreen(display);
if (!glXQueryExtension(display, &dummy, &dummy)){
fprintf(stderr, "X server has no OpenGL GLX Extension\n");
exit(1);}
vi = glXChooseVisual(display, screen, dblBuf);
if (vi == NULL){
fprintf(stderr, "Double Buffering not available\n");
vi = glXChooseVisual(display, screen, snglBuf);
if (vi == NULL) fprintf(stderr, "No RGB Visual with depth buffer\n");
doubleBuffer = False;
}
if (doubleBuffer == True) fprintf(stderr, "We have double buffering\n");
if (vi->class != TrueColor){
fprintf(stderr, "Need a TrueColor visual\n");
exit(1);
}
cx = glXCreateContext(display, vi , None, True);
if (cx == NULL){
fprintf(stderr, "No rendering context\n");
exit(1);
}
else printf(stderr, "We have a rendering context\n");
cmap = XCreateColormap(display, RootWindow(display, vi->screen),
vi->visual, AllocNone);
if (cmap == NULL){
fprintf(stderr, "Color map is not available\n");
exit(1);
}
swa.colormap = cmap;
swa.border_pixel = 0;
swa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask |
KeyPressMask;
}
Window openWindow(int x, int y, int width, int height,
int border_width, int argc, char** argv)
{
XSizeHints size_hints;
Window new_window;
new_window = XCreateWindow(display, RootWindow(display, vi->screen),
x,y, width, height, border_width, vi->depth, InputOutput,
vi->visual, CWBorderPixel | CWColormap | CWEventMask,
&swa);
size_hints.x = x;
size_hints.y = y;
size_hints.width = width;
size_hints.height = height;
size_hints.flags = PPosition | PSize;
XSetStandardProperties(display, new_window, WINDOW_NAME, ICON_NAME,
None, argv, argc, &size_hints);
XSelectInput(display, new_window, (ButtonPressMask | KeyPressMask |
StructureNotifyMask | ExposureMask));
return (new_window);
}
void init(void)
{
const GLubyte *renderer = glGetString(GL_RENDERER);
const GLubyte *vendor = glGetString(GL_VENDOR);
const GLubyte *version = glGetString(GL_VERSION);
const GLubyte *glslversion = glGetString(GL_SHADING_LANGUAGE_VERSION);
GLint major, minor;
//glGetIntegerv(GL_MAJOR_VERSION, &major);
//glGetIntegerv(GL_MINOR_VERSION, &minor);
printf("GL_VENDOR : %s\n", vendor);
printf("GL_RENDERER : %s\n", renderer);
printf("GL_VERSION (string) : %s\n", version);
//printf("GL_VERSION (int) : %d.%d\n", major, minor);
printf("GLSL Version : %s\n", glslversion);
}
void disconnectX()
{
XCloseDisplay(display);
exit(0);
}
void doKeyPressEvent(XKeyEvent *pEvent)
{
int key_buffer_size = 10;
char key_buffer[9];
XComposeStatus compose_status;
KeySym key_sym;
XLookupString(pEvent, key_buffer, key_buffer_size,
&key_sym, &compose_status);
switch(key_buffer[0]){
case 'q':
exit(0);
break;
}
}
void redraw(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glShadeModel(GL_SMOOTH);
glBegin(GL_POLYGON);
glColor3f(1.0,0.0,0.0);
glVertex2f(-0.9,-0.9);
glColor3f(0.0,1.0,0.0);
glVertex2f(0.9,-0.9);
glColor3f(0.0,0.0,1.0);
glVertex2f(0.0,0.9);
glEnd();
if (doubleBuffer) glXSwapBuffers(display,main_window); else
glFlush();
fprintf(stderr, "redraw called\n");
}
void doButtonPressEvent(XButtonEvent *pEvent)
{
fprintf(stderr, "Mouse button pressed\n");
}
int main (int argc, char** argv){
XEvent event;
connectX();
main_window = openWindow(10,20,500,400,5, argc, argv);
glXMakeCurrent(display, main_window, cx);
XMapWindow(display, main_window);
glClear(GL_COLOR_BUFFER_BIT);
init();
/*glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0,1.0, -1.0, 1.0,0.0,10.0);*/
while(1){
do{
XNextEvent(display, &event);
switch (event.type){
case KeyPress:
doKeyPressEvent(&event);
break;
case ConfigureNotify:
glViewport(0,0, event.xconfigure.width, event.xconfigure.height);
case Expose:
redraw();
break;
case ButtonPress:
doButtonPressEvent(&event);
break;
}
}
while (True); //XPending(display));
}
}
I get this error:
ld: symbol(s) not found for architecture x86_64 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
I've already install XQuartz and I'm using -I/opt/X11/include and -L/opt/X11/lib.
OpenGL programs which don't use X11 work perfectly.
#Giorgi Shavgulidze, I think my issue is similar. I had code that compiled fine with Mountain Lion. I upgraded to Mavericks. I go to recompile the code with Mavericks and Xcode 5.0.2, and glEnable(GL_SMOOTH) is causing an error. I just commented the line out and everything is fine. Why I do not know...
I know this is probably a little late for you, however, I believe this may help someone else.
I recently had essentially the exact same problem. It is important to note the difference between including something and linking to it in regards to compiling c code through methods such as gcc, as Andon mentioned above. A good SO post about this can be found here.
Your postbin shows that you are not linking properly to both OpenGL and X11. To link to them, you need to add links to your gcc command. My understanding is that you can either link to them through another path specific to your computer, via -L, or you can use pre-made links in your gcc command, which seems to be the far simpler option.
In regards to X11, while you do link to the directory holding the X11 libraries via -L/opt/X11/lib, you do not specify which library(s) you want to use. I believe the additional link you would need for X11 is -lX11.
In regards to OpenGL, you would use a different flag. While I have not used OpenGL (only used GL), my understanding is these are the appropriate flags you would have to use: -lGLU -lglut.
It is also important to note that order matters when linking and libraries should always go last.
I have included my gcc command, even though it is slightly different than what you would need, as an example.
gcc -I/opt/X11/include -L/opt/X11/lib -lX11 -lncurses -lGL spitmat8w_3.c -o hello
I'm running win 7 in virtual machine in my mac (parallels).
I wrote some small code and I try to run it and I get this problem:
C:\Users\Administrator\Documents\Visual Studio 10\Projects\test\Debug\test.exe : fatal error LNK1120: 1 unresolved externals
It tells me that he can't find the path in the users.
I check and all the path exists.
what I can do now?!
Edit: Here's the sample code being built:
#include<glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void myinit()
{
glClearColor(0.,0.,0.,0.);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-5., 5., -5., 5);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(200, 200);
glutInitWindowPosition(100, 100);
glutCreateWindow("Black Window");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
This is not a path problem, this is a linker error.
What linker is telling you is that you need an external library to complete compilation of your code (maybe you're using some function of another library and you forgot to add them in your project parameters).