Reputation: 212
I'm trying to make a very simple game using OpenGL & GLFW. I have gotten my current code to compile with no problem on Ubuntu, but when I try it on Windows I get all sorts of unresolved external errors.
I have included in both my main.cpp
and my game.h
files:
#include<GLFW/glfw3.h>
I've tried using:
#define GLFW_DLL
#include<GLFW/glfw3.h>
and then linking glfwdll.lib
instead of glfw3.lib
, and that solved some of the errors, but not all of them. Either way, I'm using the static library on Ubuntu so I want to use it on Windows also.
After researching it, I've tried including User32.lib
and kernel32.lib
,removing the default libraries (using Zl), and a bunch of other things that I can't remember (but they didn't work).
My current compile command looks like this:
@echo off
cl /Zl /MT game.cpp /I C:\dev\include /link "C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\User32.lib" "C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\kernel32.lib" C:\dev\lib\glfw3.lib C:\dev\lib\OpenGL32.lib
cl /Zl main.cpp /I C:\dev\include /link C:\dev\lib\glfw3.lib C:\Users\Daniel\projects\game\game.obj C:\dev\lib\OpenGL32.lib "C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\User32.lib" "C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\kernel32.lib"
With this, the object file compiles with no problem, but with the main file I keep getting unresolved external errors for all of the glfw and openGl funcions (whether I used them or not) in my object file and they are from the object file and the glfw.lib file.
What's really confusing to me about this is that the my game class object file compiles without any issues, but then it has errors when I link it.
Does anyone know how to compile this?
Upvotes: 1
Views: 1796
Reputation: 47
I had the exact same problem that you have described and I tried the exact same solutions which did remove linking errors for opengl functions, but the linking errors for glfw functions remained. Then I downloaded 64 bit glfw binaries and tried 64 bit glfw binaries instead of 32 bit glfw binaries and it worked! I don't know if this is due to the fact that I am on a 64 bit machine, or due to the fact that I have mingw which is for a 64bit machine (I have x86_64-w64-mingw32). My advice would be to try both 64 bit glfw and 32 bit glfw binaries. Here is what I wrote in the command prompt when I compiled and linked the project successfully gcc main.c libglfw3.a -lopengl32 -lgdi32
. If this doesn't work try writing gcc main.c libglfw3.a -lopengl32 -lgdi32 -lkernel32 -luser32 -lws2_32
.
It is important to mention that I put libglfw3.a file in the same directory with the main.c file. I hope that this helps!
Upvotes: 0
Reputation: 212
I've been looking into this for awhile now, and I found someone who said that it works if you use the 32bit binaries. I had been using the 64bit binaries when I had this problem. I downloaded the 32bit binaries and tried it with the same methods, and it compiled no problem.
I have no idea why this is, but for anyone who's having my problem, the 32bit binaries worked.
Upvotes: 1