Jump to content
  • Advertisement
Sign in to follow this  
TheNobleOne

GLFW linking problems

This topic is 5077 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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
_USRDLL
GLFW_EXPORTS
GLFW_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]

Share this post


Link to post
Share on other sites
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 directory
C:\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 directory
C:\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 directory
C:\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 directory
C:\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 directory
C:\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 directory
C:\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 directory
C:\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 directory
C:\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 directory
c:\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
c:\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
c:\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
c:\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
c:\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
c:\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
c:\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
c:\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
c:\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
c:\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
c:\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

Share this post


Link to post
Share on other sites
That means the directories are not set correctly. On step 7, you might have to change things a bit, how about:

include/GL
lib
lib/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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!