What I can''t understand is why the both 2 individual .cpp files compile but the solution does not build. The code that won't compile even though I follow the instructions is
// Two-Dimensional Sierpinski Gasket
// Generated using randomly selected vertices and bisection
#include "Angel.h"
#include <GL/glut.h>
#include <GL/glew.h>
#pragma comment(lib, "glew32.lib")
const int NumPoints = 5000;
//----------------------------------------------------------------------------
void
init( void )
{
vec2 points[NumPoints];
// Specifiy the vertices for a triangle
vec2 vertices[3] = {
vec2( -1.0, -1.0 ), vec2( 0.0, 1.0 ), vec2( 1.0, -1.0 )
};
// Select an arbitrary initial point inside of the triangle
points[0] = vec2( 0.25, 0.50 );
// compute and store N-1 new points
for ( int i = 1; i < NumPoints; ++i ) {
int j = rand() % 3; // pick a vertex at random
// Compute the point halfway between the selected vertex
// and the previous point
points[i] = ( points[i - 1] + vertices[j] ) / 2.0;
}
// Create a vertex array object
GLuint vao;
glGenVertexArrays( 1, &vao );
glBindVertexArray( vao );
// Create and initialize a buffer object
GLuint buffer;
glGenBuffers( 1, &buffer );
glBindBuffer( GL_ARRAY_BUFFER, buffer );
glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW );
// Load shaders and use the resulting shader program
GLuint program = InitShader( "vshader21.glsl", "fshader21.glsl" );
glUseProgram( program );
// Initialize the vertex position attribute from the vertex shader
GLuint loc = glGetAttribLocation( program, "vPosition" );
glEnableVertexAttribArray( loc );
glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(0) );
glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background
}
//----------------------------------------------------------------------------
void
display( void )
{
glClear( GL_COLOR_BUFFER_BIT ); // clear the window
glDrawArrays( GL_POINTS, 0, NumPoints ); // draw the points
glFlush();
}
//----------------------------------------------------------------------------
void
keyboard( unsigned char key, int x, int y )
{
switch ( key ) {
case 033:
exit( EXIT_SUCCESS );
break;
}
}
//----------------------------------------------------------------------------
int
main( int argc, char **argv )
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGBA );
glutInitWindowSize( 512, 512 );
// If you are using freeglut, the next two lines will check if
// the code is truly 3.2. Otherwise, comment them out
glutInitContextVersion( 3, 1 );
glutInitContextProfile( GLUT_CORE_PROFILE );
glutCreateWindow( "Sierpinski Gasket" );
glewInit();
init();
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glutMainLoop();
return 0;
}
I get this strange error message when I try to build the example project from Edward Angel's OpenGL site:
1>------ Build started: Project: 6E test, Configuration: Release Win32 ------
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewBindBuffer
1>example1.obj : error LNK2001: unresolved external symbol __imp____glutCreateWindowWithExit#8
1>example1.obj : error LNK2001: unresolved external symbol __imp____glutInitWithExit#12
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewVertexAttribPointer
1>example1.obj : error LNK2001: unresolved external symbol __imp__glewInit#0
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewGenVertexArrays
1>example1.obj : error LNK2001: unresolved external symbol __imp__glutInitContextProfile#4
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewUseProgram
1>example1.obj : error LNK2001: unresolved external symbol __imp__glutInitContextVersion#8
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewBufferData
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewBindVertexArray
1>example1.obj : error LNK2001: unresolved external symbol __imp__glutInitDisplayMode#4
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewGetAttribLocation
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewGenBuffers
1>example1.obj : error LNK2001: unresolved external symbol __imp__glutKeyboardFunc#4
1>example1.obj : error LNK2001: unresolved external symbol __imp__glutMainLoop#0
1>example1.obj : error LNK2001: unresolved external symbol __imp__glutInitWindowSize#8
1>example1.obj : error LNK2001: unresolved external symbol __imp__glutDisplayFunc#4
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewEnableVertexAttribArray
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewCreateShader
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewGetShaderInfoLog
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewLinkProgram
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewCompileShader
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewShaderSource
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewGetProgramiv
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewGetShaderiv
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewGetProgramInfoLog
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewCreateProgram
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewAttachShader
1>C:\Users\student\Downloads\6E_example1_VC10\6E test\Release\6E test.exe : fatal error LNK1120: 29 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It looks to me like I've tried to link in incompatible libraries, what does the above look like to you? The complete source code I try to run (with Windows 7) is
// Two-Dimensional Sierpinski Gasket
// Generated using randomly selected vertices and bisection
#pragma comment(lib, "glew32.lib")
#include "Angel.h"
const int NumPoints = 5000;
//----------------------------------------------------------------------------
void
init( void )
{
vec2 points[NumPoints];
// Specifiy the vertices for a triangle
vec2 vertices[3] = {
vec2( -1.0, -1.0 ), vec2( 0.0, 1.0 ), vec2( 1.0, -1.0 )
};
// Select an arbitrary initial point inside of the triangle
points[0] = vec2( 0.25, 0.50 );
// compute and store N-1 new points
for ( int i = 1; i < NumPoints; ++i ) {
int j = rand() % 3; // pick a vertex at random
// Compute the point halfway between the selected vertex
// and the previous point
points[i] = ( points[i - 1] + vertices[j] ) / 2.0;
}
// Create a vertex array object
GLuint vao;
glGenVertexArrays( 1, &vao );
glBindVertexArray( vao );
// Create and initialize a buffer object
GLuint buffer;
glGenBuffers( 1, &buffer );
glBindBuffer( GL_ARRAY_BUFFER, buffer );
glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW );
// Load shaders and use the resulting shader program
GLuint program = InitShader( "vshader21.glsl", "fshader21.glsl" );
glUseProgram( program );
// Initialize the vertex position attribute from the vertex shader
GLuint loc = glGetAttribLocation( program, "vPosition" );
glEnableVertexAttribArray( loc );
glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(0) );
glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background
}
//----------------------------------------------------------------------------
void
display( void )
{
glClear( GL_COLOR_BUFFER_BIT ); // clear the window
glDrawArrays( GL_POINTS, 0, NumPoints ); // draw the points
glFlush();
}
//----------------------------------------------------------------------------
void
keyboard( unsigned char key, int x, int y )
{
switch ( key ) {
case 033:
exit( EXIT_SUCCESS );
break;
}
}
//----------------------------------------------------------------------------
int
main( int argc, char **argv )
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_RGBA );
glutInitWindowSize( 512, 512 );
// If you are using freeglut, the next two lines will check if
// the code is truly 3.2. Otherwise, comment them out
glutInitContextVersion( 3, 1 );
glutInitContextProfile( GLUT_CORE_PROFILE );
glutCreateWindow( "Sierpinski Gasket" );
glewInit();
init();
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glutMainLoop();
return 0;
}
#pragma comment(lib, "glew32.lib")
#include "Angel.h"
namespace Angel {
// Create a NULL-terminated string by reading the provided file
static char*
readShaderSource(const char* shaderFile)
{
FILE* fp = fopen(shaderFile, "r");
if ( fp == NULL ) { return NULL; }
fseek(fp, 0L, SEEK_END);
long size = ftell(fp);
fseek(fp, 0L, SEEK_SET);
char* buf = new char[size + 1];
fread(buf, 1, size, fp);
buf[size] = '\0';
fclose(fp);
return buf;
}
// Create a GLSL program object from vertex and fragment shader files
GLuint
InitShader(const char* vShaderFile, const char* fShaderFile)
{
struct Shader {
const char* filename;
GLenum type;
GLchar* source;
} shaders[2] = {
{ vShaderFile, GL_VERTEX_SHADER, NULL },
{ fShaderFile, GL_FRAGMENT_SHADER, NULL }
};
GLuint program = glCreateProgram();
for ( int i = 0; i < 2; ++i ) {
Shader& s = shaders[i];
s.source = readShaderSource( s.filename );
if ( shaders[i].source == NULL ) {
std::cerr << "Failed to read " << s.filename << std::endl;
exit( EXIT_FAILURE );
}
GLuint shader = glCreateShader( s.type );
glShaderSource( shader, 1, (const GLchar**) &s.source, NULL );
glCompileShader( shader );
GLint compiled;
glGetShaderiv( shader, GL_COMPILE_STATUS, &compiled );
if ( !compiled ) {
std::cerr << s.filename << " failed to compile:" << std::endl;
GLint logSize;
glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &logSize );
char* logMsg = new char[logSize];
glGetShaderInfoLog( shader, logSize, NULL, logMsg );
std::cerr << logMsg << std::endl;
delete [] logMsg;
exit( EXIT_FAILURE );
}
delete [] s.source;
glAttachShader( program, shader );
}
/* link and error check */
glLinkProgram(program);
GLint linked;
glGetProgramiv( program, GL_LINK_STATUS, &linked );
if ( !linked ) {
std::cerr << "Shader program failed to link" << std::endl;
GLint logSize;
glGetProgramiv( program, GL_INFO_LOG_LENGTH, &logSize);
char* logMsg = new char[logSize];
glGetProgramInfoLog( program, logSize, NULL, logMsg );
std::cerr << logMsg << std::endl;
delete [] logMsg;
exit( EXIT_FAILURE );
}
/* use program object */
glUseProgram(program);
return program;
}
} // Close namespace Angel block
Update
I changed the code to begin like below and it's still not building and I still get the build error.
#pragma comment(lib, "glew32.lib")
#define GLEW_STATIC 1
#include "Angel.h"
#include <GL\glew.h>
Update 150529
I can build the freeglut GLUT examples so GLUT appears correctly installed with VC, but then when I doubleclick one of the example builds it says that freeglut.dll is not installed on my system. I still get the same compilation error when trying to build Angel's example. Why? What am I doing wrong? What should I do?
1>------ Build started: Project: 6E test, Configuration: Release Win32 ------
1> example1.cpp
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\Angel.h(65): warning C4305: 'initializing' : truncation from 'double' to 'const GLfloat'
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(698): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(699): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(700): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(721): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(723): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(726): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(742): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1> InitShader.cpp
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\Angel.h(65): warning C4305: 'initializing' : truncation from 'double' to 'const GLfloat'
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(698): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(699): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(700): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(721): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(723): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(726): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>c:\users\student\downloads\6e_example1_vc10\6e test\code\mat.h(742): warning C4244: '=' : conversion from 'double' to 'GLfloat', possible loss of data
1>..\CODE\InitShader.cpp(13): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\stdio.h(218) : see declaration of 'fopen'
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewBindBuffer
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewVertexAttribPointer
1>example1.obj : error LNK2001: unresolved external symbol __imp__glewInit#0
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewGenVertexArrays
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewUseProgram
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewBufferData
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewBindVertexArray
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewGetAttribLocation
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewGenBuffers
1>example1.obj : error LNK2001: unresolved external symbol __imp____glewEnableVertexAttribArray
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewCreateShader
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewGetShaderInfoLog
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewLinkProgram
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewCompileShader
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewShaderSource
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewGetProgramiv
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewGetShaderiv
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewGetProgramInfoLog
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewCreateProgram
1>InitShader.obj : error LNK2001: unresolved external symbol __imp____glewAttachShader
1>C:\Users\student\Downloads\6E_example1_VC10\6E test\Release\6E test.exe : fatal error LNK1120: 20 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Update
I tried asking about this again and it still won't work:
Linker error with glew and Visual Studio on windows 7
You're missing GLEW (The OpenGL Extension Wrangler Library). You can link this in with the following pragma somewhere in your source code:
#pragma comment(lib, "glew32.lib")
Or you can modify the linker flags in the project settings. This assumes that you have the GLEW library installed. On my system, I installed it at the following path:
C:\Program Files (x86)/Microsoft Visual Studio 10.0/VC/lib/glew32.lib
The path may be different on your system, and there are other ways of linking with GLEW if you don't want to install it.
You can let go of GLEW. All it does is to get the GL (and WGL) extensions loaded. Nevertheless you can do it yourself:
1.include the headers (google the file names for download):
#include<GL/glext.h>
#include<GL/wglext.h>
2.declare the function pointers:
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
PFNWGLMAKECONTEXTCURRENTARBPROC wglMakeContextCurrentARB;
//etc.
3.load the function pointers via wglGetProcAddress:
glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)wglGetProcAddress("glGenVertexArrays");
glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)wglGetProcAddress("glBindVertexArray");
wglMakeContextCurrentARB = (PFNWGLMAKECONTEXTCURRENTARBPROC)wglGetProcAddress("wglMakeContextCurrentARB");
//etc
4.let the example code use them (no changes)!
glGenVertexArrays( 1, &vao );
//etc
Related
I am using Visual Studio 2010.
And I have got this error message:
Error 9 error LNK2001: unresolved external symbol __imp____glewUseProgram C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 10 error LNK2001: unresolved external symbol __imp____glewUseProgram C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 11 error LNK2001: unresolved external symbol __imp____glewGetProgramInfoLog C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 12 error LNK2001: unresolved external symbol __imp____glewGetProgramiv C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 13 error LNK2001: unresolved external symbol __imp____glewLinkProgram C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 14 error LNK2001: unresolved external symbol __imp____glewAttachShader C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 15 error LNK2001: unresolved external symbol __imp____glewGetShaderInfoLog C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 16 error LNK2001: unresolved external symbol __imp____glewGetShaderiv C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 17 error LNK2001: unresolved external symbol __imp____glewCompileShader C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 18 error LNK2001: unresolved external symbol __imp____glewShaderSource C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 19 error LNK2001: unresolved external symbol __imp____glewCreateShader C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 20 error LNK2001: unresolved external symbol __imp____glewCreateProgram C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\InitShader.obj lab22
Error 21 error LNK2001: unresolved external symbol __imp____glewVertexAttribPointer C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 22 error LNK2001: unresolved external symbol __imp____glewEnableVertexAttribArray C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 23 error LNK2001: unresolved external symbol __imp____glewGetAttribLocation C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 24 error LNK2001: unresolved external symbol __imp____glewBufferData C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 25 error LNK2001: unresolved external symbol __imp____glewBindBuffer C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 26 error LNK2001: unresolved external symbol __imp____glewGenBuffers C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 27 error LNK2001: unresolved external symbol __imp____glewBindVertexArray C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 28 error LNK2001: unresolved external symbol __imp____glewGenVertexArrays C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 29 error LNK2019: unresolved external symbol __imp__glewInit#0 referenced in function _main C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 30 error LNK2001: unresolved external symbol __imp__glewExperimental C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\lab22\lab22.obj lab22
Error 31 error LNK1120: 21 unresolved externals C:\Users\LENOVO\Desktop\Tugas\Smst5\Komgraf\lab\lab22\Debug\lab22.exe lab22
this is my program
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glut32.lib")
#include "include\Angel.h"
const int NumPoints = 3;
void
init( void )
{
// Specifiy the vertices for a triangle
vec2 vertices[3] = {
vec2( -0.75, -0.75 ), vec2( 0.0, 0.75 ), vec2( 0.75, -0.75 )
};
// Create a vertex array object
GLuint vao[1];
glGenVertexArrays( 1, vao );
glBindVertexArray( vao[0] );
// Create and initialize a buffer object
GLuint buffer;
glGenBuffers( 1, &buffer );
glBindBuffer( GL_ARRAY_BUFFER, buffer );
glBufferData( GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW );
// Load shaders and use the resulting shader program
GLuint program = InitShader( "vshader21.glsl", "fshader21.glsl" );
glUseProgram( program );
// Initialize the vertex position attribute from the vertex shader
GLuint loc = glGetAttribLocation( program, "vPosition" );
glEnableVertexAttribArray( loc );
glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0,
BUFFER_OFFSET(0) );
glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background
}
void
display( void )
{
glClear( GL_COLOR_BUFFER_BIT ); // clear the window
glDrawArrays( GL_TRIANGLES, 0, NumPoints ); // draw the points
glFlush();
}
void
keyboard( unsigned char key, int x, int y )
{
switch ( key ) {
case 033:
exit( EXIT_SUCCESS );
break;
}
}
int
main( int argc, char **argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA );
glutInitWindowSize( 512, 512 );
glutCreateWindow( "Red Triangle" );
glewExperimental=GL_TRUE;
glewInit();
init();
glutDisplayFunc( display );
glutKeyboardFunc( keyboard );
glutMainLoop();
return 0;
}
I think I already install glut,freeglut and glew correctly, I already edit my linker but its still error. I put glut, freeglut, and glew folder in my project and in my visual studio but it still show that error. for the first project I can compile, now I'm using Angle.h and it cannot compile
Since you are using pre-processor hacks to link against the rest of your libraries, I imagine you probably want to do this:
#pragma comment(lib, "glew32.lib")
Usually you would use project settings to set up linked libraries, but a lot of tutorials use the pre-processor directive because it avoids having to walk users through configuring Visual Studio projects (which differs with every new version).
first time posting a question here to stackoverflow. Sorry if I butcher the formatting!
I am attempting to follow a basic tutorial on openCV, namely this one:
http://aishack.in/tutorials/tracking-colored-objects-in-opencv/
I have looked at various tutorial online on how to install openCV, including:
Setup OpenCV-2.3 for Visual Studio 2010
and
opencv.willowgarage.com/wiki/VisualC%2B%2B
without much luck.
The current version I have running right now is OpenCV 2.3.0.
I am currently running on Windows 7 with Microsoft Visual C++ Express 2010.
Whenever I try to build and run my code, I get the following errors:
1>------ Build started: Project: Camera, Configuration: Debug Win32 ------
1>camera.obj : error LNK2019: unresolved external symbol _cvReleaseImage referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetThresholdedImage##YAPAU_IplImage##PAU1##Z)
1>camera.obj : error LNK2019: unresolved external symbol _cvInRangeS referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetThresholdedImage##YAPAU_IplImage##PAU1##Z)
1>camera.obj : error LNK2019: unresolved external symbol _cvCvtColor referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetThresholdedImage##YAPAU_IplImage##PAU1##Z)
1>camera.obj : error LNK2019: unresolved external symbol _cvCreateImage referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetThresholdedImage##YAPAU_IplImage##PAU1##Z)
1>camera.obj : error LNK2019: unresolved external symbol _cvGetSize referenced in function "struct _IplImage * __cdecl GetThresholdedImage(struct _IplImage *)" (?GetThresholdedImage##YAPAU_IplImage##PAU1##Z)
1>camera.obj : error LNK2019: unresolved external symbol _cvReleaseCapture referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvWaitKey referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvShowImage referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvAdd referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvLine referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvGetCentralMoment referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvGetSpatialMoment referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvMoments referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvQueryFrame referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvNamedWindow referenced in function _main
1>camera.obj : error LNK2019: unresolved external symbol _cvCreateCameraCapture referenced in function _main
1>C:\Users\Kevin\Documents\Visual Studio 2010\Projects\Camera\Debug\Camera.exe : fatal error LNK1120: 16 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
My code is as follows:
#include "cv.h"
#include "highgui.h"
IplImage* GetThresholdedImage(IplImage* img)
{
IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
cvCvtColor(img, imgHSV, CV_BGR2HSV);
IplImage* imgThreshed = cvCreateImage(cvGetSize(img), 8, 1);
cvInRangeS(imgHSV, cvScalar(20, 100, 100), cvScalar(30, 255, 255), imgThreshed);
cvReleaseImage(&imgHSV);
return imgThreshed;
}
int main()
{
CvCapture* capture = 0;
capture = cvCaptureFromCAM(1);
if(!capture)
{
printf("Could not initialize capturing...\n");
getchar();
return -1;
}
cvNamedWindow("video");
cvNamedWindow("thresh");
IplImage* imgScribble = NULL;
while(1)
{
IplImage* frame = 0;
frame = cvQueryFrame(capture);
if(!frame)
break;
//cvErode(frame, frame, 0, 2); // ADD this line
//initalize the scribble frame if has not already been done yet
if(imgScribble == NULL)
{
imgScribble = cvCreateImage(cvGetSize(frame), 8, 3);
}
IplImage* imgYellowThresh = GetThresholdedImage(frame);
CvMoments *moments = (CvMoments*)malloc(sizeof(CvMoments));
cvMoments(imgYellowThresh, moments, 1);
// The actual moment values
double moment10 = cvGetSpatialMoment(moments, 1, 0);
double moment01 = cvGetSpatialMoment(moments, 0, 1);
double area = cvGetCentralMoment(moments, 0, 0);
// Holding the last and current ball positions
static int posX = 0;
static int posY = 0;
int lastX = posX;
int lastY = posY;
posX = moment10/area;
posY = moment01/area;
printf("position (%d,%d)\n", posX, posY);
// We want to draw a line only if its a valid position
if(lastX>0 && lastY>0 && posX>0 && posY>0)
{
// Draw a yellow line from the previous point to the current point
cvLine(imgScribble, cvPoint(posX, posY), cvPoint(lastX, lastY), cvScalar(0,255,255), 5);
}
cvAdd(frame, imgScribble, frame);
cvShowImage("thresh", imgYellowThresh);
cvShowImage("video", frame);
int c = cvWaitKey(5);
if((char)c==27 )
break;
// Release the thresholded image+moments... we need no memory leaks.. please
cvReleaseImage(&imgYellowThresh);
delete moments;
}
// We're done using the camera. Other applications can now use it
cvReleaseCapture(&capture);
cvReleaseCapture(&capture);
return 0;
}
I have installed Open CV to
C:\OpenCV2.3
I have added additional dependencies, additional directories, ect.
For the preferences for my project, they are as follows:
Additional Dependencies:
enter code here
opencv_core230.lib
opencv_highgui230.lib
opencv_legacy230.lib
opencv_video230.lib
opencv_ml230.lib
opencv_core230d.lib
opencv_highgui230d.lib
opencv_legacy230d.lib
opencv_video230d.lib
opencv_ml230d.lib
opencv_calib3d230d.lib
Aditional Library Directories:
C:\OpenCV2.3\build\x64\vc10\lib;C:\OpenCV2.3\build\x64\vc10\bin;C:\OpenCV2.3\build\x64\vc10\staticlib;%(AdditionalLibraryDirectories)
Additional Include Directories:
C:\OpenCV2.3\build\include\opencv;C:\OpenCV2.3\build\include\opencv2;C:\OpenCV2.3\build\include
I also included a path to the DLL's on my path variable for windows:
;C:\OpenCV2.3\build\x64\vc10\bin;C:\OpenCV2.3\build\bin;
I've looked at other forums, other stack overflow questions, ect without much help.
I have been trying to get this to work for the better part of a weekend. Any help would be much appreciated!
If you DID explicitly set up linking with all the necessary libraries, but linking errors still show, you might be mixing up 64/32 bit libraries and application.
I.e. make sure that all library includes point to 32 bit version of libraries if you are building 32 bit application.
I had a similar problem while I was trying to compile cvblob library (http://code.google.com/p/cvblob/) on Windows 7 32bit with Visual Studio 2010.
If everything else is done properly try my guess written below.
If not start with these tutorials:
Installing OpenCV: http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_install/windows_install.html#cpptutwindowsmakeown
Configuring your projects to build and work with opencv: http://docs.opencv.org/trunk/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#windows-visual-studio-how-to.
These silimar linker errors disappeared after changing some project
properties:
In VS 2010 open Your solution
Open solution explorer (View->Solution Explorer)
Find a project that generated these linker errors. (In my example it was a project called "cvblob" inside solution called "cvBlob"
generated by cmake.)
right click on that project
From the context menu select properties
On the left select Configuration properties -> General and find a field called "Target extension"
In Project Details find your project settings for "Configuration Type"
analyse them. In my particular problem of compiling cvblob I had to set Target extension to .lib and Configuration type to
Static library. This is also a solution for guys trying to compile
cvblob library in Visual Studio 2010.
Do the same for Debug and Release version if needed.
Errors I got were:
Error 24 error LNK2019: unresolved external symbol _cvSetImageROI
referenced in function
_cvSetImageROItoBlob C:\cvblob\build\lib\cvblob.obj cvblob
Error 25 error LNK2019: unresolved external symbol _cvSaveImage
referenced in function
_cvSaveImageBlob C:\cvblob\build\lib\cvblob.obj cvblob
Error 26 error LNK2019: unresolved external symbol _cvGetImageROI
referenced in function
_cvSaveImageBlob C:\cvblob\build\lib\cvblob.obj cvblob
Error 27 error LNK2001: unresolved external symbol
_cvError C:\cvblob\build\lib\cvcolor.obj cvblob
Error 28 error LNK2019: unresolved external symbol _cvError referenced
in function _cvRenderBlob C:\cvblob\build\lib\cvblob.obj cvblob
Error 29 error LNK2001: unresolved external symbol
_cvError C:\cvblob\build\lib\cvlabel.obj cvblob
Error 30 error LNK2001: unresolved external symbol
_cvError C:\cvblob\build\lib\cvcontour.obj cvblob
Error 31 error LNK2001: unresolved external symbol
_cvError C:\cvblob\build\lib\cvtrack.obj cvblob
Error 32 error LNK2019: unresolved external symbol _cvLine referenced
in function _cvRenderBlob C:\cvblob\build\lib\cvblob.obj cvblob
Error 33 error LNK2001: unresolved external symbol
_cvLine C:\cvblob\build\lib\cvcontour.obj cvblob
Error 34 error LNK2019: unresolved external symbol _cvRectangle
referenced in function
_cvRenderBlob C:\cvblob\build\lib\cvblob.obj cvblob
Error 35 error LNK2001: unresolved external symbol
_cvRectangle C:\cvblob\build\lib\cvtrack.obj cvblob
Error 36 error LNK2019: unresolved external symbol _cvSetZero
referenced in function _cvLabel C:\cvblob\build\lib\cvlabel.obj cvblob
Error 37 error LNK2019: unresolved external symbol _cvPutText
referenced in function
_cvRenderTracks C:\cvblob\build\lib\cvtrack.obj cvblob
Error 38 error LNK2019: unresolved external symbol _cvInitFont
referenced in function
_cvRenderTracks C:\cvblob\build\lib\cvtrack.obj cvblob
Error 39 error LNK1120: 9 unresolved
externals C:\cvblob\build\lib\libs\Release\cvblob.dll cvblob
I hope it will help someone compiling cvblob library in visual studio 2010.
I had similar problem in vs10 and i have forgot to add the cv210d.lib. Adding that to project properties->configuration properties-> Linker->Input->Aditional Dependencies helped me in solving this issue. I found from the question that opencv_cv230.lib was not included in additional dependencies adding that will help solving the issue.
I Had The Same Problem, in vs10
i've missed the "opencv_core246d.lib" to add. adding it to Linker->Input->Aditional Dependencies fixed error.
This might help with the newer version.
For version 2.4.8, adding opencv_imgproc248.lib resolves the following linking error:
error LNK2019: unresolved external symbol _cvRemap referenced in function _main
error LNK2019: unresolved external symbol _cvInitUndistortMap referenced in function _main
error LNK2019: unresolved external symbol _cvFindCornerSubPix referenced in function _main
error LNK2019: unresolved external symbol _cvCvtColor referenced in function _main
for me, this error got resolved by adding two lib name explicitly under input (configuration properties-->linker-->input-->additional dependencies).
when you install opencv , based on version it will have a number appended to it. For example I have opencv2.4.13 and it has 2413 appended to all its libraries, opencv_highgui2413.lib (opencv_highgui2413d.lib for debug build ).
Now,check which libraries have the functions that were shown in errors.
highgui has cvshowimage function --> you can get this by searing it online.
http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html
Then add that lib to input and build your solution.
Please help me with the missing LIBs for this MOZILLA program.
Trying to create cookie using nsICookieManager2
I have tried with all the existing libs in Mozilla SDK
Regards
C:\Code>cl.exe FFCookie.cpp /I "C:\xulrunner-sdk\include" mozalloc.lib xpcomglue.lib /link /LIBPATH:"C:\xulrunner-sdk\lib"
Symbols Missing:
FFCookie.obj : error LNK2019: unresolved external symbol "public: void
__thiscall nsCOMPtr_base::assign_from_gs_contractid_with_er ror(class nsGetServiceByContractIDWithError const &,struct nsID const &)"
(?assign_from_gs_contractid_with_error#nsCOMPtr_base##QA
EXABVnsGetServiceByContractIDWithError##ABUnsID###Z) referenced in
function "public: __thiscall nsCOMPtr::
nsCOMPtr(class
nsGetServiceByContractIDWithError const &)"
(??0?$nsCOMPtr#VnsICookieManager####QAE#ABVnsGe
tServiceByContractIDWithError###Z)
FFCookie.obj : error LNK2019: unresolved external symbol "public: void
__thiscall nsCOMPtr_base::assign_from_qi(class nsQueryInter face,struct nsID const &)"
(?assign_from_qi#nsCOMPtr_base##QAEXVnsQueryInterface##ABUnsID###Z)
referenced in function "public: __t hiscall nsCOMPtr::nsCOMPtr(class
nsQueryInterface)" (??0?$nsCOMPtr#VnsICookieMan
ager2####QAE#VnsQueryInterface###Z) FFCookie.exe : fatal error
LNK1120: 2 unresolved externals
#include "nsICookieManager.h"
#include "nsICookieManager2.h"
#include "nsServiceManagerUtils.h"
#include "nsComPtr.h"
#include "nsNetCID.h"
#include "nsStringAPI.h"
#include "mozilla-config.h"
int main()
{
nsresult rv;
nsCOMPtr<nsICookieManager> cookieManager = do_GetService (NS_COOKIEMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
if (cookieManager)
{
nsCOMPtr<nsICookieManager2> cookieManager2 = do_QueryInterface(cookieManager);
if (cookieManager2)
{
cookieManager2->Add(NS_LITERAL_CSTRING("ud.abc.com"),
NS_LITERAL_CSTRING("//"),
NS_LITERAL_CSTRING("TK"),
NS_LITERAL_CSTRING("abc"), 0x1, 0x1, 0, -1);
}
}
return 0;
}
Questions:
I dont find any info with function documentation regarding which LIB to include (as I find on MSDN)
Any clue on how to figure out LIB corresponding to particular function for MOZILLA.
The problem isn't with the lib, the symbol missing is defined in the xpcomglue library. However, you seem to have some compile parameters that don't match the parameters used to compile XULRunner/Firefox. The symbols your compiler is looking for contain "QAEX" as parameter description whereas the library defines them with "QAIX". Looking at the name mangling table, your compiler expects unsigned char where Mozilla has unsigned int. I suspect that the reason is you compiling your application without Unicode support - change main() into wmain()?
I trying to compile some OpenCv functions and I included the cvhaartraining.h from the directory C:\OpenCV2.2\modules\haartraining.
I put on Project > 'Your Project Name' Properties... > Configuration Properties > Linker > Input >
all the .lib files in the opencv library:
"C:\OpenCV2.2\lib\opencv_highgui220d.lib" "C:\OpenCV2.2\lib\opencv_core220d.lib" "C:\OpenCV2.2\lib\opencv_ml220d.lib" "C:\OpenCV2.2\lib\opencv_video220d.lib" "C:\OpenCV2.2\lib\opencv_legacy220d.lib" "C:\OpenCV2.2\lib\opencv_imgproc220d.lib" "C:\OpenCV2.2\lib\opencv_objdetect220d.lib" "C:\OpenCV2.2\lib\opencv_ts220.lib" "C:\OpenCV2.2\lib\opencv_calib3d220d.lib" "C:\OpenCV2.2\lib\opencv_contrib220d.lib" "C:\OpenCV2.2\lib\opencv_features2d220d.lib"
"C:\OpenCV2.2\lib\opencv_ffmpeg220d.lib" "C:\OpenCV2.2\lib\opencv_flann220d.lib" "C:\OpenCV2.2\lib\opencv_gpu220d.lib"
but it still won't link.
The error I get is:
vecToFiles.obj : error LNK2019: unresolved external symbol "void __cdecl cvShowVecSamples(char const *,int,int,double)" (?cvShowVecSamples##YAXPBDHHN#Z) referenced in function _main
vecToFiles.obj : error LNK2019: unresolved external symbol "int __cdecl cvCreateTrainingSamplesFromInfo(char const *,char const *,int,int,int,int)" (?cvCreateTrainingSamplesFromInfo##YAHPBD0HHHH#Z) referenced in function _main
vecToFiles.obj : error LNK2019: unresolved external symbol "void __cdecl cvCreateTestSamples(char const *,char const *,int,int,char const *,int,int,int,double,double,double,int,int,int)" (?cvCreateTestSamples##YAXPBD0HH0HHHNNNHHH#Z) referenced in function _main
vecToFiles.obj : error LNK2019: unresolved external symbol "void __cdecl cvCreateTrainingSamples(char const *,char const *,int,int,char const *,int,int,int,double,double,double,int,int,int)" (?cvCreateTrainingSamples##YAXPBD0HH0HHHNNNHHH#Z) referenced in function _main
vecToFiles\Debug\vecToFiles.exe : fatal error LNK1120: 4 unresolved externals
I think Im missing some .lib file, but I dont know which file.
Ill appreciate any help.
What extra lib files do you have? From googling it looks like it's compiled into a file called cvhaartraining.lib.
I am getting very strange errors and i am not able to understand what these errors actually mean when build my project in visual studio it gives me the following errors can anybody tells me what actually these error means i though that there are some configuration issues i am doing socket programming and network programming.
Here are the bunch of error your help weill be highly appreciated....
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(990,5): warning MSB8012: TargetPath(E:\Study\FWIF\demola\ext-libs\libcommoncpp2-1.6.0\w32\Debug\ccgnu2.dll) does not match the Linker's OutputFile property value (E:\Study\FWIF\demola\ext-libs\libcommoncpp2-1.6.0\w32\Debug\CapeCommon14.dll). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(992,5): warning MSB8012: TargetName(ccgnu2) does not match the Linker's OutputFile property value (CapeCommon14). This may cause your project to build incorrectly. To correct this, please make sure that $(OutDir), $(TargetName) and $(TargetExt) property values match the value specified in %(Link.OutputFile).
1> Creating library E:\Study\FWIF\demola\ext-libs\libcommoncpp2-1.6.0\w32\Debug\CapeCommon14.lib and object E:\Study\FWIF\demola\ext-libs\libcommoncpp2-1.6.0\w32\Debug\CapeCommon14.exp
1>socket.obj : error LNK2019: unresolved external symbol "public: bool __thiscall ost::IPV4Cidr::isMember(struct sockaddr const *)const " (?isMember#IPV4Cidr#ost##QBE_NPBUsockaddr###Z) referenced in function "public: bool __thiscall ost::IPV4Cidr::operator==(struct sockaddr const *)const " (??8IPV4Cidr#ost##QBE_NPBUsockaddr###Z)
1>in6addr.obj : error LNK2001: unresolved external symbol "public: bool __thiscall ost::IPV4Cidr::isMember(struct sockaddr const *)const " (?isMember#IPV4Cidr#ost##QBE_NPBUsockaddr###Z)
1>inaddr.obj : error LNK2001: unresolved external symbol "public: bool __thiscall ost::IPV4Cidr::isMember(struct sockaddr const *)const " (?isMember#IPV4Cidr#ost##QBE_NPBUsockaddr###Z)
1>peer.obj : error LNK2001: unresolved external symbol "public: bool __thiscall ost::IPV4Cidr::isMember(struct sockaddr const *)const " (?isMember#IPV4Cidr#ost##QBE_NPBUsockaddr###Z)
1>simplesocket.obj : error LNK2001: unresolved external symbol "public: bool __thiscall ost::IPV4Cidr::isMember(struct sockaddr const *)const " (?isMember#IPV4Cidr#ost##QBE_NPBUsockaddr###Z)
1>socket.obj : error LNK2019: unresolved external symbol "public: bool __thiscall ost::IPV4Cidr::isMember(struct in_addr const &)const " (?isMember#IPV4Cidr#ost##QBE_NABUin_addr###Z) referenced in function "public: bool __thiscall ost::IPV4Cidr::operator==(struct in_addr const &)const " (??8IPV4Cidr#ost##QBE_NABUin_addr###Z)
1>in6addr.obj : error LNK2001: unresolved external symbol "public: bool __thiscall ost::IPV4Cidr::isMember(struct in_addr const &)const " (?isMember#IPV4Cidr#ost##QBE_NABUin_addr###Z)
1>inaddr.obj : error LNK2001: unresolved external symbol "public: bool __thiscall ost::IPV4Cidr::isMember(struct in_addr const &)const " (?isMember#IPV4Cidr#ost##QBE_NABUin_addr###Z)
1>peer.obj : error LNK2001: unresolved external symbol "public: bool __thiscall ost::IPV4Cidr::isMember(struct in_addr const &)const " (?isMember#IPV4Cidr#ost##QBE_NABUin_addr###Z)
1>simplesocket.obj : error LNK2001: unresolved external symbol "public: bool __thiscall ost::IPV4Cidr::isMember(struct in_addr const &)const " (?isMember#IPV4Cidr#ost##QBE_NABUin_addr###Z)
1>E:\Study\FWIF\demola\ext-libs\libcommoncpp2-1.6.0\w32\Debug\CapeCommon14.dll : fatal error LNK1120: 2 unresolved externals
2>------ Build started: Project: buffer, Configuration: Debug Win32 ------
2> buffer.cpp
2>e:\study\fwif\demola\ext-libs\libcommoncpp2-1.6.0\demo\buffer.cpp(41): fatal error C1083: Cannot open include file: 'cc++/buffer.h': No such file or directory
========== Build: 0 succeeded, 2 failed, 0 up-to-date, 0 skipped ==========
For the errors in project 1, it looks like you have to add a library to the build to resolve the function call ost::IPV4Cidr::isMember(struct sockaddr const *)const. Possibly you are compiling with the wrong calling conventions for a library that you already included.
For the compile error in project buffer, you need to add the include path for that file cc++/buffer.h to the project.