Skip to main content
GameDev.net gamedev.net
🔒 Locked

GLFW linking problems

Started by TheNobleOne Apr 27, 2005 at 11:02 AM 12 replies 25.8k views
Original Post
TheNobleOne
TheNobleOne
Ok I am using VS.Net 2003 to compile my native c++ code. I already created the binaries and put them where they belong. I took the lesson 1 tutorial and put the code in main.cpp. I linked the libs and set the startup function like it said to in the tutorial 0 I think. So lo and behold it does not compile. I get all this linker errors. What is wrong? for every function that the app uses it can't find the definition to it or anything. it is just a mess lol.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Drew_Benton
Drew_Benton
In your main program, you need to compile with the preprocessor GLFW_DLL defined. If you built GLFW yourself, make sure you have defined GLFW_BUILD_DLL as well. If you have any other problems questions feel free to ask. [smile] Getting GLFW up and running the first time is tricky, but once you have it, well worth the time spent. If you still can't get it, I can send you a sample program as well if needed.

[edit]
On second though, for anyone else interested, here is the newest GLFW Library with a VC6/Dev workspace as well as a working demo. VS7 users can simply double click the .dsw file and upgrade. It's not that it's hard or anything, just better when you can use a project right out of the box [wink].

VC 6/7
Dev CPP

[Edited by - Drew_Benton on March 10, 2006 1:15:58 PM]
TheNobleOne
TheNobleOne
I am still having problems here are my linker and startup settings.

Commandline Arguments in project properties/Linker
glfw.lib opengl32.lib glu32.lib

Linker Advanced Entry Point in properties/Linker mainCRTStartup

errors I am getting are as follows

glfw test error LNK2001: unresolved external symbol _mainCRTStartup
glfw test error LNK2019: unresolved external symbol _glfwGetWindowSize@8 referenced in function "void __cdecl Draw(void)" (?Draw@@YAXXZ)
glfw test error LNK2019: unresolved external symbol _glfwGetTime@0 referenced in function "void __cdecl Draw(void)" (?Draw@@YAXXZ)
glfw test error LNK2001: unresolved external symbol __fltused
glfw test error LNK2019: unresolved external symbol @_RTC_CheckStackVars@8 referenced in function "void __cdecl Draw(void)" (?Draw@@YAXXZ)
glfw test error LNK2019: unresolved external symbol __RTC_CheckEsp referenced in function "void __cdecl Draw(void)" (?Draw@@YAXXZ)
glfw test error LNK2001: unresolved external symbol __RTC_Shutdown
glfw test error LNK2001: unresolved external symbol __RTC_InitBase
glfw test error LNK2019: unresolved external symbol _glfwGetWindowParam@4 referenced in function _main
glfw test error LNK2019: unresolved external symbol _glfwGetKey@4 referenced in function _main
glfw test error LNK2019: unresolved external symbol _glfwSwapBuffers@0 referenced in function _main
glfw test error LNK2019: unresolved external symbol _glfwEnable@4 referenced in function _main
glfw test error LNK2019: unresolved external symbol _glfwSetWindowTitle@4 referenced in function _main
glfw test error LNK2019: unresolved external symbol _glfwTerminate@0 referenced in function _main
glfw test error LNK2019: unresolved external symbol _glfwOpenWindow@36 referenced in function _main
glfw test error LNK2019: unresolved external symbol _glfwInit@0 referenced in function _main
glfw test fatal error LNK1120: 16 unresolved externals

code:
#define GLFW_DLL#define GLFW_BUILD_DLL#include <stdlib.h>    // For malloc() etc.#include <stdio.h>     // For printf(), fopen() etc.#include <math.h>      // For sin(), cos() etc.#include <gl/glfw.h>   // For GLFW, OpenGL and GLU//----------------------------------------------------------------------// Draw() - Main OpenGL drawing function that is called each frame//----------------------------------------------------------------------void Draw( void ){    int    width, height;  // Window dimensions    double t;              // Time (in seconds)    // Get current time    t = glfwGetTime();    // Get window size    glfwGetWindowSize( &width, &height );    // Make sure that height is non-zero to avoid division by zero    height = height < 1 ? 1 : height;    // Set viewport    glViewport( 0, 0, width, height );    // Clear color and depht buffers    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );    // Set up projection matrix    glMatrixMode( GL_PROJECTION );    // Select projection matrix    glLoadIdentity();                 // Start with an identity matrix    gluPerspective(                   // Set perspective view        65.0,                         // Field of view = 65 degrees        (double)width/(double)height, // Window aspect (assumes square pixels)        1.0,                          // Near Z clipping plane        100.0                         // Far Z clippling plane    );    // Set up modelview matrix    glMatrixMode( GL_MODELVIEW );     // Select modelview matrix    glLoadIdentity();                 // Start with an identity matrix    gluLookAt(                        // Set camera position and orientation        0.0, 0.0, 10.0,               // Camera position (x,y,z)        0.0, 0.0, 0.0,                // View point (x,y,z)        0.0, 1.0, 0.0                 // Up-vector (x,y,z)    );    // Here is where actual OpenGL rendering calls would begin...}//----------------------------------------------------------------------// main() - Program entry point//----------------------------------------------------------------------int main( int argc, char **argv ){    int    ok;             // Flag telling if the window was opened    int    running;        // Flag telling if the program is running    // Initialize GLFW    glfwInit();    // Open window    ok = glfwOpenWindow(        640, 480,          // Width and height of window        8, 8, 8,           // Number of red, green, and blue bits for color buffer        8,                 // Number of bits for alpha buffer        24,                // Number of bits for depth buffer (Z-buffer)        0,                 // Number of bits for stencil buffer        GLFW_WINDOW        // We want a desktop window (could be GLFW_FULLSCREEN)    );    // If we could not open a window, exit now    if( !ok )    {        glfwTerminate();        return 0;    }    // Set window title    glfwSetWindowTitle( "My OpenGL program" );    // Enable sticky keys    glfwEnable( GLFW_STICKY_KEYS );    // Main rendering loop    do    {        // Call our rendering function        Draw();        // Swap front and back buffers (we use a double buffered display)        glfwSwapBuffers();        // Check if the escape key was pressed, or if the window was closed        running = !glfwGetKey( GLFW_KEY_ESC ) &&                  glfwGetWindowParam( GLFW_OPENED );    }    while( running );    // Terminate GLFW    glfwTerminate();    // Exit program    return 0;}
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Drew_Benton
Drew_Benton
You will only need to #define GLFW_DLL in the that program. The other define is for when you create the .lib/.dll, so you may need to recompile your GLFW library and use the new one. Make sure that you have made the project a MultiThreaded DLL runtime as well. I just dropped your code into my demo project and it compiled fine, so I think you need to fix your GLFW library. (You have to use the Preprocessor settings for GLFW_BUILD_DLL)

[Edited by - Drew_Benton on March 10, 2006 1:18:05 PM]
TheNobleOne
TheNobleOne
I am totally confused right now. They should make this thing simpler to install. I already compiled my libs/dll 3 times over and it still does not work. I followed the instructions and moved the files it said to move to where it said. and I still get the linker errors. They should make this windowing more like sdl style. easy to setup and use. however, I have some problems with sdl when I need to switch projections. So i want to try this. I tried everything I could think of and none of it worked. maybe you can write out some instructions.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Drew_Benton
Drew_Benton
Sure, no problem! I know what you mean, it took me quite a few hours the first time I tried to get this up and running. Here are some quick little steps to get this working. ( Steps from very start )

1. Go to the GLFW site and download the GLFW v2.5 zip file.

2. Next, after extracting the files, go to the main directory. Copy the path location because we will be making a project for GLFW here. Open up Visual Studio.Net and choose to make a new project

3. We will create a "Win32 Project". Enter in the name of GLFW and paste in the path that the main GLFW directory was. Remove the check that will create a directory for the solution.

4. Click OK, then Application settings. Choose DLL and Empty project and hit finish. Now we will start adding in the files.

5. Right click on the Source Files folder and choose Add->Add Existing Files. You will probabally have to navigate up one folder, then select the lib folder, then select the 11 .C files and hit Open. They are added to the workspace.

6. Now repeat the same procedure, but you will this time go to the win32 folder inside the LIB folder, add in the 9 .C files. Note that adding in the header files is not a must to the workspace, it just is a convience when developing.

7. Now right click on the GLFW project name, under the Solution 'GLFW' and choose properties. We will now need to set the include directories. Click on the C/C++ Tab and in the Additional Include Directives (first box), we will want to add in the line: ../include/GL;../lib;../lib/win32. Explanation:
../include/GL -> Navigate up one level, cd to include, then cd to GL
../lib -> Navigate up one level, cd to lib
../lib/win32 -> Navigate up one level, cd to lib, cd to Win32


We do this so GLFW can find the necessary header files needed to build.

8. Now right click on the GLFW project name, under the Solution 'GLFW' and choose properties again. In the C/C++ Tab, choose "Preprocessor". In the first box, preprocessor defines, add in the line GLFW_BUILD_DLL. It should now look like this for debug mode:
WIN32_DEBUG_WINDOWS_USRDLLGLFW_EXPORTSGLFW_BUILD_DLL


9. Now in the same options screen, choose "Code Generation" and switch it to a "Multithreaded Debug DLL" ( For release it is Multithreaded DLL).

10. Finally, still in that same box, click on the Linker tab, then the Input tab. In the first box, Additional Dependecies, add in the line: opengl32.lib glu32.lib.

Now you should be able to build the library in debug mode with no problems. You will pretty much do the same steps for release mode.

Now onto the demo project you have made. You will keep everythign the same, except you will only use the #define GLFW_DLL and not the GLFW_BUILD_DLL. Make sure you copy over the library files and .dll that you just made and it should all work fine. Let me know how that goes. If you have any further questions comments about this feel free to share [smile]

[Edited by - Drew_Benton on March 10, 2006 1:32:26 PM]
TheNobleOne
TheNobleOne
Humm it is not building ?

C:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\win32\win32_time.c(36): fatal error C1083: Cannot open include file: 'internal.h': No such file or directoryC:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\win32\win32_thread.c(36): fatal error C1083: Cannot open include file: 'internal.h': No such file or directoryC:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\win32\win32_joystick.c(36): fatal error C1083: Cannot open include file: 'internal.h': No such file or directoryC:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\win32\win32_init.c(36): fatal error C1083: Cannot open include file: 'internal.h': No such file or directoryC:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\win32\win32_glext.c(36): fatal error C1083: Cannot open include file: 'internal.h': No such file or directoryC:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\win32\win32_fullscreen.c(36): fatal error C1083: Cannot open include file: 'internal.h': No such file or directoryC:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\win32\win32_enable.c(36): fatal error C1083: Cannot open include file: 'internal.h': No such file or directoryC:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\win32\win32_dllmain.c(36): fatal error C1083: Cannot open include file: 'internal.h': No such file or directoryC:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\win32\win32_window.c(36): fatal error C1083: Cannot open include file: 'internal.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directoryc:\Documents and Settings\Bill Lewis Jr\Desktop\glfw-2.5\lib\internal.h(65): fatal error C1083: Cannot open include file: 'platform.h': No such file or directory
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Drew_Benton
Drew_Benton
That means the directories are not set correctly. On step 7, you might have to change things a bit, how about:
include/GLliblib/win32


The idea is that wherever the GLFW.sln is, you must navigate using the directory paths to where those two files are. If all else fails, when you add the paths on step 7, just use absolute hard coded paths [wink] THat should work.
TheNobleOne
TheNobleOne
nevermind about that got it to compile lol just could not edit in time. I switched to a release and forgot to reset the directories :S. So where do I copy the files that were compiled. I can put the dll in system32. but where should the lib and header go does it matter as long as the compiler knows where it is. And will I have to include gl.h and glu.h in my apps.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Drew_Benton
Drew_Benton
If you want do always use the .lib files, you can just copy the release version to your Microsoft Visual Studio .NET 2003\Vc7\lib folder or you just copy it with each project. I usually go with keeping it with my projects in case I want to send it to someone else to compile. I;d do the same for the header file as well as .DLL. Just a matter of preference [smile]
TheNobleOne
TheNobleOne
bah I am still getting the same linker errors. ;(
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup
Drew_Benton
Drew_Benton
Give my projects a try and see if those work. I mean I just made those steps as I went along and it all worked fine [sad]. In your program, make sure that you do not have a random copy of GLFW.lib floating around in your VC7 lib folder already. Also, make sure that the project created is a MultiThreaded DLL as well as defines GLFW_DLL before you include GLFW. Finally make sure you are linking in GLFW.lib.

Looking back at your errors I see some that I do not recognize at all. All of the "__RTC_Shutdown" stuff is kind of weird - are you making C++ and not managed code? That and see if you can remake your demo project from scratch again in case something was changed by accident. Here was my project:
// This is made for debug mode only - the libraries included in // this folder are debug, not release since it's just a demo#include <windows.h>#include <stdio.h>     // For printf(), fopen() etc.#define GLFW_DLL#include "glfw.h"		// For GLFW, OpenGL and GLU#pragma comment ( lib, "opengl32.lib" )#pragma comment ( lib, "glu32.lib" )#pragma comment ( lib, "GLFW.lib" )void CalculateFrameRate();void Init(){	int    width, height;  // Window dimensions	// Get window size	glfwGetWindowSize( &width, &height );	// Make sure that height is non-zero to avoid division by zero	height = height < 1 ? 1 : height;	// Set viewport	glViewport( 0, 0, width, height );	// Clear color and depht buffers	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );	// Set up projection matrix	glMatrixMode( GL_PROJECTION );    // Select projection matrix	glLoadIdentity();                 // Start with an identity matrix	gluPerspective(                   // Set perspective view		65.0,                         // Field of view = 65 degrees		(double)width/(double)height, // Window aspect (assumes square pixels)		1.0,                          // Near Z clipping plane		100.0                         // Far Z clippling plane	);	// Set up modelview matrix	glMatrixMode( GL_MODELVIEW );     // Select modelview matrix	glLoadIdentity();                 // Start with an identity matrix	gluLookAt(                        // Set camera position and orientation		0.0, 0.0, 10.0,               // Camera position (x,y,z)		0.0, 0.0, 0.0,                // View point (x,y,z)		0.0, 1.0, 0.0                 // Up-vector (x,y,z)	);}void Draw( void ){	if( glfwGetKey( GLFW_KEY_F1 ) )	{	}	if( glfwGetKey( GLFW_KEY_F2 ) )	{	}	if( glfwGetKey( GLFW_KEY_F3 ) )	{	}	if( glfwGetKey( GLFW_KEY_F4 ) )	{	}	if( glfwGetKey( GLFW_KEY_F5 ) )	{	}	double t = glfwGetTime();              // Time (in seconds)	// Clear color and depht buffers	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );	glLoadIdentity();                 // Start with an identity matrix	gluLookAt	(								  // Set camera position and orientation		0.0, 0.0, 10.0,               // Camera position (x,y,z)		0.0, 0.0, 0.0,                // View point (x,y,z)		0.0, 1.0, 0.0                 // Up-vector (x,y,z)	);	glTranslatef( 0, 0, -5 );	// Rotate the triangle about the y-axis	glRotatef( 60.0f * (float)t, 0.0f, 1.0f, 0.0f );	// Let us draw a triangle, with color!	glBegin( GL_TRIANGLES );          // Tell OpenGL that we want to draw a triangle		glColor3f( 1.0f, 0.0f, 0.0f );    // Color for first corner (red)		glVertex3f( -5.0f, -4.0f, 0.0f ); // First corner of the triangle		glColor3f( 0.0f, 1.0f, 0.0f );    // Color for second corner (green)		glVertex3f(  5.0f, -4.0f, 0.0f ); // Second corner of the triangle		glColor3f( 0.0f, 0.0f, 1.0f );    // Color for third corner (blue)		glVertex3f(  0.0f,  4.5f, 0.0f ); // Third corner of the triangle	glEnd();                          // No more triangles...	glFlush();}int main( int argc, char **argv ){	int    ok;             // Flag telling if the window was opened	int    running;        // Flag telling if the program is running	// Initialize GLFW	glfwInit();	// Open window	ok = glfwOpenWindow(		640, 480,          // Width and height of window		8, 8, 8,           // Number of red, green, and blue bits for color buffer		8,                 // Number of bits for alpha buffer		24,                // Number of bits for depth buffer (Z-buffer)		0,                 // Number of bits for stencil buffer		GLFW_WINDOW        // We want a desktop window (could be GLFW_FULLSCREEN)	);	// If we could not open a window, exit now	if( !ok )	{		glfwTerminate();		return 0;	}	// Set window title	glfwSetWindowTitle( "GLFW Demo" );	// Enable sticky keys	glfwEnable( GLFW_STICKY_KEYS );	Init();	// Main rendering loop	do	{		// Call our rendering function		Draw();		// Swap front and back buffers (we use a double buffered display)		glfwSwapBuffers();		// Check if the escape key was pressed, or if the window was closed		running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED );	}	while( running );	// Terminate GLFW	glfwTerminate();	// Exit program	return 0;}


Also if you made a Release version of the library, make sure you compile in release mode for your demo app. Actually your demo does not even need to be Multithreaded DLL, mine is ST and it still works fine.

If none of that can work, I really have no idea what the problem is. I mean either something is wrong with your compiler or I just don't know. If you want to go over things again, that's fine with me, If you need any more details or anything feel free to ask.
TheNobleOne
TheNobleOne
Ok I got it working I made a release copy and did not have the compiler set to release in my project lol.
My JournalComputer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter. (Eric Raymond)"C makes it easy to shoot yourself in the foot. C++ makes itharder, but when you do, it blows away your whole leg."-- Bjarne Stroustrup

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.