Jump to content

  • Log In with Google      Sign In   
  • Create Account


unresolved external symbol problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
32 replies to this topic

#1 Levent Cpp   Members   -  Reputation: 143

Like
0Likes
Like

Posted 02 June 2014 - 12:48 PM

Hi I'm new to OpenGl i was working with VBOs first time using glMultiDrawElements so the identifier couldnt be found so i inculded glew:

#include <GL/glew.h>

and then i faced another problem (LINKER ERROR) :

 error LNK2001: unresolved external symbol __imp____glewMultiDrawElements

anyone can help me with that.

My Code (In Case) :

#include <Windows.h>
#include <iostream>
#include <GL/glew.h>
#include <gl\GL.h>

#if defined(__APPLE__)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif



void init(void){
	glClearColor(0,0,0,0);
	glShadeModel(GL_FLAT);
}

void reshape(int w,int h){
	glViewport(0,0,(GLsizei)w,(GLsizei)h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	gluPerspective(45,1,0,200);
}



void display(void){		
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);

	static GLubyte oneIndices[] = {0, 1, 2, 3, 4, 5, 6};
	static GLubyte twoIndices[] = {7, 1, 8, 9, 10, 11};
	static GLsizei count[] = {7, 6};
	static const GLvoid * indices[2] = {oneIndices, twoIndices};

	glMultiDrawElements(GL_LINE_STRIP, count, GL_UNSIGNED_BYTE, indices, 2);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

	glFlush();

	glutSwapBuffers();
}

int main(int argc , char** argv){
	glutInit(&argc , argv);
	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
	glutInitWindowSize(250,250);
	glutInitWindowPosition(0,0);
	glutCreateWindow(argv[0]);
	init();
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutMainLoop();
	return 0;
}

Thanks.



Sponsor:

#2 Cornstalks   Crossbones+   -  Reputation: 6974

Like
3Likes
Like

Posted 02 June 2014 - 12:53 PM

Link to GLEW.
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#3 swiftcoder   Senior Moderators   -  Reputation: 9856

Like
3Likes
Like

Posted 02 June 2014 - 05:23 PM

It also helps to call glewInit(), once you have linked to it.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#4 Levent Cpp   Members   -  Reputation: 143

Like
0Likes
Like

Posted 03 June 2014 - 02:50 AM

sry.

 

same problem as before :

 error LNK2001: unresolved external symbol __imp____glewMultiDrawElements

i linked all OpenGL files correctly ( I Think ).

 

When i use glewInit Instead of glutInit :

error LNK2001: unresolved external symbol __imp____glewMultiDrawElements
error LNK2019: unresolved external symbol __imp__glewInit@0 referenced in function _main

i don't know what is the problem with linking files.

 

Thanks.



#5 swiftcoder   Senior Moderators   -  Reputation: 9856

Like
1Likes
Like

Posted 03 June 2014 - 03:59 AM


i linked all OpenGL files correctly

You need to link to GLEW, not just OpenGL.

 

When i use glewInit Instead of glutInit

You'll need both.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#6 Levent Cpp   Members   -  Reputation: 143

Like
0Likes
Like

Posted 03 June 2014 - 05:53 AM

i linked all glew files again it doesnt change .

 

I followed this path :

http://glew.sourceforge.net/install.html


#7 swiftcoder   Senior Moderators   -  Reputation: 9856

Like
1Likes
Like

Posted 03 June 2014 - 06:10 AM

Are you building the glew source into your program, or linking to glew32.lib? (the referenced page describes both approaches)

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#8 Levent Cpp   Members   -  Reputation: 143

Like
0Likes
Like

Posted 03 June 2014 - 06:25 AM

I went to Project setting and added glew32.lib in Additional Options after i set up the inculde lib and bin files



#9 BitMaster   Crossbones+   -  Reputation: 3885

Like
4Likes
Like

Posted 03 June 2014 - 06:48 AM

One major source of possible problems here is the target platform. Trying to link x86 libraries into x64 targets (or vice versa) will be silently ignored by many linkers (including MSVC's), leading to errors identical to not linking with the library at all. Are you certain you have downloaded the correct build for your target?

Edited by BitMaster, 03 June 2014 - 06:48 AM.


#10 Levent Cpp   Members   -  Reputation: 143

Like
0Likes
Like

Posted 03 June 2014 - 07:58 AM

By the way my system is X64 is that going to change something???



#11 Jan2go   Members   -  Reputation: 699

Like
3Likes
Like

Posted 03 June 2014 - 08:04 AM

By the way my system is X64 is that going to change something???

No, it depends on you build target whether you need to link against die x64 or x86 libraries. It doesn't matter if you're running a x64 or x86 (or something different) OS.

#12 Levent Cpp   Members   -  Reputation: 143

Like
0Likes
Like

Posted 03 June 2014 - 08:44 AM

Thanks but how can i solve the problem ?



#13 cgrant   Members   -  Reputation: 602

Like
1Likes
Like

Posted 03 June 2014 - 08:54 AM

Adding the dependency to the list is just part of the issue. The compiler/linker still have to be able to find the dependency. If the linker cannot find the library in its search directory, then you will still end up with unresolved symbols even though they were added to the list.



#14 Levent Cpp   Members   -  Reputation: 143

Like
0Likes
Like

Posted 03 June 2014 - 09:11 AM

how can i know the linker found it or not ?

i deleted the command : glMultiDrawElements , And i ran the program , it was successful.


Edited by haykan648, 03 June 2014 - 09:50 AM.


#15 Jan2go   Members   -  Reputation: 699

Like
2Likes
Like

Posted 03 June 2014 - 09:27 AM

how can i now the linker found it or not ?


The linker won't tell whether or not he found the file (although I have no idea why they don't do it). You have to check your linker paths ("Additional Linker Directories" in VS) and see if the path of you libary is included.

#16 Levent Cpp   Members   -  Reputation: 143

Like
0Likes
Like

Posted 03 June 2014 - 09:57 AM

yes it is included. i put everything i need in VC directory (in bin, library and include files) and i checked the {VS Directory}/bin  and  {VS Directory}/library and {VS Directory}/include in Additional Linker Directorys they were linked correctly .



#17 WiredCat   Members   -  Reputation: 238

Like
0Likes
Like

Posted 03 June 2014 - 10:37 AM

since you have all linked its easy to get it working:

first see this code dont add it to your app

 

 

in glew.h



#define glMultiDrawElements GLEW_GET_FUN(__glewMultiDrawElements)
GLEW_FUN_EXPORT PFNGLMULTIDRAWELEMENTSPROC __glewMultiDrawElements;
typedef void (GLAPIENTRY * PFNGLMULTIDRAWELEMENTSPROC) (GLenum mode, GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount);

so to get it working: (in your app) (ofc add #include glew.h or in my case gl/glew.h)

in header add: 



PFNGLMULTIDRAWELEMENTSPROC  glMultiDrawElements; //name it whatever you want

and in cpp file: you need to initalize it



	glMultiDrawElements = NULL;
	glMultiDrawElements        = (PFNGLMULTIDRAWELEMENTSPROC) wglGetProcAddress("glMultiDrawElements");

be happy its working ;p at least should be

 

if its still NULL then your card  does not support such kind of feature


Edited by WiredCat, 03 June 2014 - 10:38 AM.


#18 Jan2go   Members   -  Reputation: 699

Like
1Likes
Like

Posted 03 June 2014 - 10:38 AM

VC Directory? You are not talking about C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC (or whereever you installed VS) hopefully. I still think that either your library includes are wrong or you are linking against the wrong library. Can you upload the solution so we can take a look at your project settings?



#19 Levent Cpp   Members   -  Reputation: 143

Like
0Likes
Like

Posted 03 June 2014 - 11:11 AM

Sry i had a problem with git so i uploaded here :

http://uploadboy.com/kvwp4inyjad4.html

thank you all for your helps !



#20 Jan2go   Members   -  Reputation: 699

Like
2Likes
Like

Posted 03 June 2014 - 12:24 PM

You have specified the "glew32.lib glew32s.lib" under "Additional Include Directories". First, that is the place where you put the paths where the compiler should look for  #include "..." files. Libraries need to go into "Linker\Input\Additional Dependencies". Second, you can't put two libraries, paths, etc. in the same line; use one line per entry or separate the entries with a semicolon.

Also, you should only link glew32.lib or glew32s.lib, not both of them. glew32.lib is for dynamic linking (requires glew32.dll at runtime), glew32s.lib is for static linking (no dll required). If you go for static linking you need to #define GLEW_STATIC before you #include <glew.h>.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS