First I downloaded glut from this source, http://user.xmission.com/~nate/glut.html"> Nate Robins. I put:
glut32.dll into C:\Windows\SysWOW64,
glut32.lib into C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib
glut.h into C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\GL
In Visual Studio, under C++ I created an empty project, changed the compiler to 64x. I made sure to select ALL Configurations and linked opengl32.lib,glu32.lib and glut32.lib.
In Tools -> Options -> VC++ Directories -> Include Files:C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include
In Configuration Properties → Linker → Additional Library Directories:C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib
/************************************
* Handout: example.cpp
*
* This program is to demonstrate the basic OpenGL program structure.
* Read the comments carefully for explanations.
************************************/
#define WINDOWS 1 /* Set to 1 for Windows, 0 else */
#define UNIX_LINUX 0 /* Set to 1 for Unix/Linux, 0 else */
#if WINDOWS
#include <windows.h>
#include <GL/glut.h>
#endif
#if UNIX_LINUX
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif
#include <stdio.h>
#include <math.h>
float f = 0.0;
void display(void);
void my_init(void);
void reshape(int w, int h);
void idle(void);
void main(int argc, char **argv)
{
/*---- Initialize & Open Window ---*/
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); // double-buffering and RGB color
// mode.
glutInitWindowSize(500, 500);
glutInitWindowPosition(30, 30); // Graphics window position
glutCreateWindow("Rectangle"); // Window title is "Rectangle"
/*--- Register call-back functions; any order is fine ---*/
/* Events: display, reshape, keyboard, mouse, idle, etc.
- display: Automatically called when the window is first opened.
Later, when the frame content needs to be changed, we need
to call display again From the Program to re-draw the objects.
This is essential for animation.
- reshape: Automatically called when the window is first opened,
or when the window is re-sized or moved by the user.
- keyboard: Automatically called when a keyboard event occurs.
- mouse: Automatically called when a mouse event occurs.
- idle: Automatically called when nothing occurs.
This is essential for animation.
* Once entering the event loop, the execution control always returns to
the event loop. When particular event occurs, the corresponding call-back
function is called; when that call-back function finishes, control again
goes back to the event loop, and the process is repeated.
*/
glutDisplayFunc(display); // Register our display() function as the display
// call-back function
glutReshapeFunc(reshape); // Register our reshape() function as the reshape
// call-back function
// glutMouseFunc(mouse); // for mouse
// glutKeyboardFunc(key); // for keyboard
glutIdleFunc(idle); // Register our idle() function
my_init(); // initialize variables
glutMainLoop(); // Enter the event loop
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT); // clear frame buffer (also called the
// color buffer)
glColor3f(0.0, 1.0, 1.0); // draw in cyan.
// The color stays the same until we
// change it next time.
glBegin(GL_POLYGON); // Draw a polygon (can have many vertices)
// The vertex coordinates change by different
// values of i; see also function idle().
glVertex2f(100, 100 + f);
glVertex2f(200, 100 + f);
glVertex2f(200, 300 + f);
glVertex2f(100, 300 + f);
glEnd();
glFlush(); // Render (draw) the object
glutSwapBuffers(); // Swap buffers in double buffering.
}
void my_init()
{
glClearColor(0.0, 0.0, 0.0, 0.0); // Use black as the color for clearing
// the frame buffer (also called the
// color buffer). This produces a
// black background.
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h); // Viewport within the graphics window.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h);
}
void idle(void)
{
f += 0.02; // smaller number gives a slower but smoother animation
if (f > 180.0) f = 0.0;
glutPostRedisplay(); // or call display()
}
My errors are
Error 17 error LNK1120: 16 unresolved externals C:\Projects\Project1\x64\Debug\Project1.exe Project1
Error 15 error LNK2001: unresolved external symbol _fltused C:\Projects\Project1\Project1\main.obj Project1
Error 13 error LNK2001: unresolved external symbol _RTC_InitBase C:\Projects\Project1\Project1\main.obj Project1
Error 14 error LNK2001: unresolved external symbol _RTC_Shutdown C:\Projects\Project1\Project1\main.obj Project1
Error 16 error LNK2001: unresolved external symbol mainCRTStartup C:\Projects\Project1\Project1\LINK Project1
Error 7 error LNK2019: unresolved external symbol __imp___glutCreateWindowWithExit referenced in function glutCreateWindow_ATEXIT_HACK C:\Projects\Project1\Project1\main.obj Project1
Error 2 error LNK2019: unresolved external symbol __imp___glutInitWithExit referenced in function glutInit_ATEXIT_HACK C:\Projects\Project1\Project1\main.obj Project1
Error 1 error LNK2019: unresolved external symbol __imp_exit referenced in function glutInit_ATEXIT_HACK C:\Projects\Project1\Project1\main.obj Project1
Error 10 error LNK2019: unresolved external symbol __imp_glutDisplayFunc referenced in function main C:\Projects\Project1\Project1\main.obj Project1
Error 12 error LNK2019: unresolved external symbol __imp_glutIdleFunc referenced in function main C:\Projects\Project1\Project1\main.obj Project1
Error 3 error LNK2019: unresolved external symbol __imp_glutInitDisplayMode referenced in function main C:\Projects\Project1\Project1\main.obj Project1
Error 4 error LNK2019: unresolved external symbol __imp_glutInitWindowPosition referenced in function main C:\Projects\Project1\Project1\main.obj Project1
Error 5 error LNK2019: unresolved external symbol __imp_glutInitWindowSize referenced in function main C:\Projects\Project1\Project1\main.obj Project1
Error 6 error LNK2019: unresolved external symbol __imp_glutMainLoop referenced in function main C:\Projects\Project1\Project1\main.obj Project1
Error 8 error LNK2019: unresolved external symbol __imp_glutPostRedisplay referenced in function "void __cdecl idle(void)" (?idle##YAXXZ) C:\Projects\Project1\Project1\main.obj Project1
Error 11 error LNK2019: unresolved external symbol __imp_glutReshapeFunc referenced in function main C:\Projects\Project1\Project1\main.obj Project1
Error 9 error LNK2019: unresolved external symbol __imp_glutSwapBuffers referenced in function "void __cdecl display(void)" (?display##YAXXZ) C:\Projects\Project1\Project1\main.obj Project1
Cannot figure out what I'm doing wrong.
You are using 32bit libraries but you are compiling a x64 executable and the linker cannot resolve the symbols.
Related
I am compiling a alglib sample program (with a few changes):
#pragma once
# include "Source\RFLearn.h" \\appropriate header for this simple .cpp program.
# include <LinAlg.h>
# include <stdint.h>
# include <chrono> // for in-game frame clock.
int RFLearn::test_function()
{
alglib::real_2d_array a, b, c;
int n = 2000;
int i, j;
double timeneeded, flops;
// Initialize arrays
a.setlength(n, n);
b.setlength(n, n);
c.setlength(n, n);
for (i = 0; i<n; i++)
for (j = 0; j<n; j++)
{
a[i][j] = alglib::randomreal() - 0.5;
b[i][j] = alglib::randomreal() - 0.5;
c[i][j] = 0.0;
}
// Set global threading settings (applied to all ALGLIB functions);
// default is to perform serial computations, unless parallel execution
// is activated. Parallel execution tries to utilize all cores; this
// behavior can be changed with alglib::setnworkers() call.
alglib::setglobalthreading(alglib::parallel);
// Perform matrix-matrix product.
flops = 2 * pow((double)n, (double)3);
auto timer_start = std::chrono::high_resolution_clock::now();
alglib::rmatrixgemm(
n, n, n,
1.0,
a, 0, 0, 0,
b, 0, 0, 1,
0.0,
c, 0, 0);
auto timer_end = std::chrono::high_resolution_clock::now();
auto duration = timer_end - timer_start;
timeneeded = static_cast<double>(duration.count());
// Evaluate performance
printf("Performance is %.1f GFLOPS\n", (double)(1.0E-9*flops / timeneeded));
return 0;
}
I am confident linAlg is correctly linked (as well as all of its dependencies, particularly ap.h and ap.cpp) (Preferences->C++->AllOptions->Additional Include Directories -> aglib's source directory. Changing the link provides a different set of linker errors. AlgLib is a header only-library so I don't think I need to compile any library and add it in the linker.
When compiling this code I get the errors:
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: double * __thiscall alglib::real_2d_array::operator[](int)" (??Areal_2d_array#alglib##QAEPANH#Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall alglib::real_2d_array::~real_2d_array(void)" (??1real_2d_array#alglib##UAE#XZ)
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: __thiscall alglib::real_2d_array::real_2d_array(void)" (??0real_2d_array#alglib##QAE#XZ)
1>RFLearn.obj : error LNK2001: unresolved external symbol "struct alglib::xparams const & const alglib::parallel" (?parallel#alglib##3ABUxparams#1#B)
1>RFLearn.obj : error LNK2001: unresolved external symbol "void __cdecl alglib::rmatrixgemm(int,int,int,double,class alglib::real_2d_array const &,int,int,int,class alglib::real_2d_array const &,int,int,int,double,class alglib::real_2d_array const &,int,int,struct alglib::xparams)" (?rmatrixgemm#alglib##YAXHHHNABVreal_2d_array#1#HHH0HHHN0HHUxparams#1##Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "double __cdecl alglib::randomreal(void)" (?randomreal#alglib##YANXZ)
1>RFLearn.obj : error LNK2001: unresolved external symbol "public: void __thiscall alglib::ae_matrix_wrapper::setlength(int,int)" (?setlength#ae_matrix_wrapper#alglib##QAEXHH#Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "void __cdecl alglib::setglobalthreading(struct alglib::xparams)" (?setglobalthreading#alglib##YAXUxparams#1##Z)
1>RFLearn.obj : error LNK2001: unresolved external symbol "struct alglib::xparams const & const alglib::xdefault" (?xdefault#alglib##3ABUxparams#1#B)
I intuit that the problem lies around here: http://www.alglib.net/translator/man/manual.cpp.html#gs_configuring
but I cannot make heads or tails of it. What's the next step?
I had a similar (not exact) problem and it went away just by adding the compiled the cpp files to my project and set "included in the project" to true.
I want to use the Eclipse Paho MQTT C library in a simple C++ program. For the library i used the the pre-build binaries for windows - see https://projects.eclipse.org/projects/technology.paho/downloads
C client for Windows 1.3.0 - 64 bit
I found the exact same issue in this talk LNK2019 error when compiling a Visual C++ Win32 project with Eclipse Paho MQTT.
For linkage in include I have the following setting:
C/C++ - Additional include: xxx\paho\eclipse-paho-mqtt-c-win64-1.3.0\include
Linker - additional Additional Library Directories
Linker - input - additional dependencies:
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3cs.lib
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3c.lib
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3a.lib
eclipse-paho-mqtt-c-win64-1.3.0\lib\paho-mqtt3as.lib
My code is as follows:
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern "C" {
#include <MQTTClient.h>
#include <MQTTClientPersistence.h>
}
#define ADDRESS "xxx"
#define CLIENTID "ExampleClientSub"
#define TOPIC "xxx"
#define PAYLOAD "Hello World!"
#define QOS 1
#define TIMEOUT 10000L
int main()
{
MQTTClient client;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
int rc;
int ch;
MQTTClient_create(&client, ADDRESS, CLIENTID,
MQTTCLIENT_PERSISTENCE_NONE, NULL);
conn_opts.keepAliveInterval = 20;
conn_opts.cleansession = 1;
conn_opts.username = "roman.busse";
conn_opts.password = "VojUriLKhOsmzUJQ1lld";
MQTTClient_setCallbacks(client, NULL, connlost, msgarrvd, delivered);
if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS)
{
printf("Failed to connect, return code %d\n", rc);
exit(EXIT_FAILURE);
}
printf("Subscribing to topic %s\nfor client %s using QoS%d\n\n"
"Press Q<Enter> to quit\n\n", TOPIC, CLIENTID, QOS);
MQTTClient_subscribe(client, TOPIC, QOS);
do
{
ch = getchar();
} while (ch != 'Q' && ch != 'q');
MQTTClient_unsubscribe(client, TOPIC);
MQTTClient_disconnect(client, 10000);
MQTTClient_destroy(&client);
return 0;
}
So like you can see i said to the compiler: "Yes this is a C lib". But all in all I get the same LNK2019 errors...
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _MQTTClient_setCallbacks
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_create referenced
in function _main paho_test C:\Users\rtreiber\documents\visual studio
2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_connect
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_disconnect
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_subscribe
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_unsubscribe
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_freeMessage
referenced in function "int __cdecl msgarrvd(void *,char *,int,struct
MQTTClient_message *)"
(?msgarrvd##YAHPAXPADHPAUMQTTClient_message###Z) paho_test C:\Users\rtreiber\documents\visual
studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_free referenced
in function "int __cdecl msgarrvd(void *,char *,int,struct
MQTTClient_message *)"
(?msgarrvd##YAHPAXPADHPAUMQTTClient_message###Z) paho_test C:\Users\rtreiber\documents\visual
studio 2017\Projects\paho_test\paho_test\paho_test.obj 1
Error LNK2019 unresolved external symbol _MQTTClient_destroy
referenced in function
_main paho_test C:\Users\rtreiber\documents\visual studio 2017\Projects\paho_test\paho_test\paho_test.obj 1 Error LNK1120 9
unresolved externals paho_test C:\Users\rtreiber\documents\visual
studio 2017\Projects\paho_test\Debug\paho_test.exe 1
So any ideas?
I have read all the previous replies or solutions for the same linker problem. I understand that the Linker is unable to access the library file that has the functions defined but still I have no luck in solving it!
The errors:
1>trial_12th.obj : error LNK2019: unresolved external symbol _viStatusDesc#12 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viClose#4 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viRead#16 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viWrite#16 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viOpen#20 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viOpenDefaultRM#4 referenced in function _main
1>C:\Users\41kchoudhary\Documents\Visual Studio 2010\Projects\trial_12th\Debug\trial_12th.exe : fatal error LNK1120: 6 unresolved externals
I am trying to send and receive data from a mixed-signal oscilloscope. In doing so I am required to write a .cpp file using the pre-defined commands/functions defined using Microsoft Visual Studio C++. I have read the user manual for using these commands, and I also have the header files and libraries required to implement it.
I am using the following code:
#include <visa.h>
#include "stdafx.h"
#include <stdio.h>
#include <memory.h>
int main(int argc, char* argv[])
{
ViSession rm = VI_NULL, vi = VI_NULL;
ViStatus status;
ViChar buffer[256];
ViUInt32 retCnt;
// Open a default session
status = viOpenDefaultRM(&rm);
if (status < VI_SUCCESS) goto error;
// Open the GPIB device at primary address 1, GPIB board 8
status = viOpen(rm, "USB::0x0699::0x0377::C011104::INSTR", VI_NULL, VI_NULL,
&vi);
if (status < VI_SUCCESS) goto error;
// Send an ID query.
status = viWrite(vi, (ViBuf) "*idn?", 5, &retCnt);
if (status < VI_SUCCESS) goto error;
// Clear the buffer and read the response
memset(buffer, 0, sizeof(buffer));
status = viRead(vi, (ViBuf) buffer, sizeof(buffer), &retCnt);
if (status < VI_SUCCESS) goto error;
// Print the response
printf("id: %s\n", buffer);
// Clean up
viClose(vi); // Not needed, but makes things a bit more
// understandable
viClose(rm); // Closes resource manager and any sessions
// opened with it
return 0;
error:
// Report error and clean up
viStatusDesc(vi, status, buffer);
fprintf(stderr, "failure: %s\n", buffer);
if (rm != VI_NULL) {
viClose(rm);
}
return 1;
}
You need to add either visa32.lib or visa64.lib to your linker settings.
One way to do that is to use a pragma in your compiler source file:
#pragma comment(lib,"visa32.lib")
If it is still not found then adjust your lib paths in your IDE or include the full path in the pragma.
I had the same issue. I figured out that you have to add visa32.lib in additional dependencies under the linker properties of your project
Go to your
project properties -> Linker -> Additional Dependencies-> Click Down Arrow -> "Edit -> Type visa32.lib
Click Ok, Ok
while i want to compile my opengl code i get the following errors:
Error 1 error LNK2019: unresolved external symbol __imp__glewInit#0
Error 2 error LNK2019: unresolved external symbol __imp__glewGetErrorString#4
Error 3 error LNK2001: unresolved external symbol __imp____glewAttachShader
Error 4 error LNK2001: unresolved external symbol __imp____glewCompileShader
Error 5 error LNK2001: unresolved external symbol __imp____glewCreateProgram
Error 6 error LNK2001: unresolved external symbol __imp____glewCreateShader
Error 7 error LNK2001: unresolved external symbol __imp____glewDeleteProgram
Error 8 error LNK2001: unresolved external symbol __imp____glewDisableVertexAttribArray
Error 9 error LNK2001: unresolved external symbol __imp____glewEnableVertexAttribArray
Error 10 error LNK2001: unresolved external symbol __imp____glewGetAttribLocation
Error 11 error LNK2001: unresolved external symbol __imp____glewGetProgramiv
Error 12 error LNK2001: unresolved external symbol __imp____glewGetShaderiv
Error 13 error LNK2001: unresolved external symbol __imp____glewLinkProgram
Error 16 error LNK2001: unresolved external symbol __imp____glewVertexAttribPointer
Error 17 error LNK1120: 16 unresolved externals
my code is :
#include <Windows.h>
#include <iostream>
#include <glew.h>
#include <gl\GL.h>
#include <freeglut.h>
using namespace std;
GLuint program;
GLint attribute_coord2d;
int init_resources(void)
{
GLint compile_ok = GL_FALSE, link_ok = GL_FALSE;
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
const char *vs_source =
#ifdef GL_ES_VERSION_2_0
"#version 100\n" // OpenGL ES 2.0
#else
"#version 120\n" // OpenGL 2.1
#endif
"attribute vec2 coord2d; "
"void main(void) { "
" gl_Position = vec4(coord2d, 0.0, 1.0); "
"}";
glShaderSource(vs, 1, &vs_source, NULL);
glCompileShader(vs);
glGetShaderiv(vs, GL_COMPILE_STATUS, &compile_ok);
if (0 == compile_ok)
{
fprintf(stderr, "Error in vertex shader\n");
return 0;
}
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
const char *fs_source =
"#version 120 \n"
"void main(void) { "
" gl_FragColor[0] = 0.0; "
" gl_FragColor[1] = 0.0; "
" gl_FragColor[2] = 1.0; "
"}";
glShaderSource(fs, 1, &fs_source, NULL);
glCompileShader(fs);
glGetShaderiv(fs, GL_COMPILE_STATUS, &compile_ok);
if (!compile_ok) {
fprintf(stderr, "Error in fragment shader\n");
return 0;
}
program = glCreateProgram();
glAttachShader(program, vs);
glAttachShader(program, fs);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &link_ok);
if (!link_ok) {
fprintf(stderr, "glLinkProgram:");
return 0;
}
const char* attribute_name = "coord2d";
attribute_coord2d = glGetAttribLocation(program, attribute_name);
if (attribute_coord2d == -1) {
fprintf(stderr, "Could not bind attribute %s\n", attribute_name);
return 0;
}
return 1;
}
void onDisplay()
{
/* Clear the background as white */
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(program);
glEnableVertexAttribArray(attribute_coord2d);
GLfloat triangle_vertices[] = {
0.0, 0.8,
-0.8, -0.8,
0.8, -0.8,
};
/* Describe our vertices array to OpenGL (it can't guess its format automatically) */
glVertexAttribPointer(
attribute_coord2d, // attribute
2, // number of elements per vertex, here (x,y)
GL_FLOAT, // the type of each element
GL_FALSE, // take our values as-is
0, // no extra data between each position
triangle_vertices // pointer to the C array
);
/* Push each element in buffer_vertices to the vertex shader */
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(attribute_coord2d);
/* Display the result */
glutSwapBuffers();
}
void free_resources()
{
glDeleteProgram(program);
}
int main(int argc, char* argv[])
{
/* Glut-related initialising functions */
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowSize(640, 480);
glutCreateWindow("My First Triangle");
/* Extension wrangler initialising */
GLenum glew_status = glewInit();
if (glew_status != GLEW_OK)
{
fprintf(stderr, "Error: %s\n", glewGetErrorString(glew_status));
return EXIT_FAILURE;
}
/* When all init functions runs without errors,
the program can initialise the resources */
if (1 == init_resources())
{
/* We can display it if everything goes OK */
glutDisplayFunc(onDisplay);
glutMainLoop();
}
/* If the program exits in the usual way,
free resources and exit with a success */
free_resources();
return EXIT_SUCCESS;
}
i tried every thing from tweaking linker option including .lib files explicitly, specifying include paths reading forums related to these errors and so on, none of them helped, can you guys help me how i fix this problem?
I got the glew binaries from http://glew.sourceforge.net/index.html (https://sourceforge.net/projects/glew/files/glew/1.9.0/glew-1.9.0-win32.zip/download)
and freeglut 2.8.0 MSVC Package from http://www.transmissionzero.co.uk/software/freeglut-devel/ (http://files.transmissionzero.co.uk/software/development/GLUT/freeglut-MSVC.zip)
I set the include path to glew-1.9.0\include\, freeglut\include\ and library path to freeglut\lib\, glew-1.9.0\lib\.
I corrected the header of your file as
#include <Windows.h>
#include <iostream>
#include <gl/glew.h>
#include <gl/GL.h>
#include <gl/freeglut.h>
#pragma comment(lib, "glew32.lib")
Linking successful, and it worked.
UPD
When using third-party libraries, usually:
You must set the include path to <3rdPartyDir>\include, but not to <3rdPartyDir>\include\lib_name. Declare its inclusion in the source code should be:
correct: #include <lib_name/header_name.h>
wrong: #include <header_name.h>, because within the library can be internal dependencies, for example #include <lib_name/other_header_name.h>
Set the library path to <3rdPartyDir>\lib. Then, you must specify the required libraries, one of the following methods:
For MSVC, add
#ifdef _MSC_VER
#pragma comment(lib, "lib1_name.lib")
#pragma comment(lib, "lib2_name.lib")
/// etc
#endif
Or, add the required libraries to the linker options.
Some libraries support auto-linking mechanism (for example, freeglut), that is, the header file contains a line like #pragma comment(lib, "lib1_name.lib")
Copy the required dlls from <3rdPartyDir>\bin to <MyExePath>\
I was having the same problem. Finally found useful instructions in this Visual Studio and OpenGL tutorial. The issue was correctly including the .dll files for the right configuration (Win32 or x64).
This is definitely a problem with linker settings, specifically to do with the glew library. Why your previous attempts to fix it have not worked isnt too clear to me.
Are you able to get any tutorial programs that glew provides to compile?
Edit
From your comment it looks like you are having issues including your lib file.
- Can you verify if it is where you think it is (is it installed correctly)?
- Does Visual studio know where it is supposed to be(is correct path to lib provided)?
Does Project ->Right click + properties -> Configuration Properties -> Linker -> General -> Additional Linker directories in Visual Studio have the path to the folder containing glew32.lib?
It seems as you used not correct glew.lib. when using config win32 to build you must use glew.lib(win32) or opposite. You can try by replace glew.lib in your project.
If the above answers don't work and glew seems to be linked properly, you may have simply neglected to link opengl32.lib.
In VS,
Project > Properties > Linker > Input > Additional Dependencies
and add opengl32.lib to that line if it isn't there already.
I have been working on learning DirectX for a couple days and have run into a problem. I have been following a books example and have solved several annoying problems that have come up, but have been unsuccessful at solving my most recent one. The compiler states that I have an unresolved external symbol whenever I try to compile. Here is the error code below.
1>game.obj : error LNK2019: unresolved external symbol "struct IDirect3DSurface9 * __cdecl
LoadSurface(char *,unsigned long)" (?LoadSurface##YAPAUIDirect3DSurface9##PADK#Z) referenced in
function "int __cdecl Game_Init(struct HWND__ *)" (?Game_Init##YAHPAUHWND__###Z)
1>C:\Users\Christopher\Documents\Visual Studio 2008\Projects\Work\Debug\Work.exe : fatal error
LNK1120: 1 unresolved externals
I am running: [compiler: Visual Studios 2008] [Operating system: Windows 7 64bit professional]
Here a sample of the code and where it seem to be taking place. (I hope I gave enough info)
LPDIRECT3DSURFACE9 kitty_image[7];
SPRITE kitty;
LPDIRECT3DSURFACE9 back;
//timing variable
long start = GetTickCount();
//initializes the game
int Game_Init(HWND hwnd)
{
char s[20];
int n;
//set random number seed
srand(time(NULL));
//load the sprite animation
for (n=0; n<6; n++)
{
sprintf(s, "cat%d.bmp",n+1);
kitty_image[n] = LoadSurface(s, D3DCOLOR_XRGB(255,0,255));
if (kitty_image[n] == NULL)
return 0;
}
back = LoadSurface("background.bmp", NULL );
//initialize the sprite's properties
kitty.x = 100;
kitty.y = 150;
kitty.width = 96;
kitty.height = 96;
kitty.curframe = 0;
kitty.lastframe = 5;
kitty.animdelay = 2;
kitty.animcount = 0;
kitty.movex = 8;
kitty.movey = 0;
//return okay
return 1;
}
I have linked both d3d9.lib and d3dx9.lib to my project and have included all neccesary header files that I know of (d3d9.h, d3dx9.h). Any help is greatly appreciated! Thanks in advance!!!
It looks like the linker is complaining that there is no such function LoadSurface. Where did you define it?