0

I am using Visual Studio 2013, and used nuget to install "glew" and "freeglut". I am following a course, and these instructions for installation:

http://in2gpu.com/2014/10/15/setting-up-opengl-with-visual-studio/

I did get confused along the way, but I read the instructions thoroughly. In the end of the build of my simple project, I got an error :

1>LINK : fatal error LNK1104: cannot open file 'Dependencies\freeglut.obj'

#include <iostream>
#include "Dependencies\glew\glew.h"
#include "Dependencies\freeglut\freeglut.h"

int main(int argc, char **argv)
{
    return 0;
}

I have read other websites about installing libraries, but I just get confused. Any help and in-depth discussion would be very helpful. Thanks.

Max Khan
  • 21
  • 10

2 Answers2

0

LINK : fatal error LNK1104: cannot open file 'Dependencies\freeglut.obj'

It should not be freeglut.obj, but freeglut.lib.

Also, be sure, that you followed properly all the steps in Now let’s prepare FreeGLUT section of tutorial: they explained very clearly how to add search library directories and linker input, but Visual Studio reports missing Dependencies\freeglut.obj - check carefully, what do you have in Project Properties -> Linker -> Input -> Additional Dependencies.

Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49
-1

Unfortunately, I'll have to ask the obvious question: is freeglut.lib located where it's supposed to be and are you pointed to the right directory?

Your error says Dependencies\freeglut.obj, but if you were following the tutorial freeglut should be in Dependencies\freeglut. Another common mistake on Windows is using a full file path that has spaces (C:....My Documents...), but not putting the whole file path in quotes. The linker gets tripped up by that.

EDIT: I'm guessing I was voted down since I didn't notice the more obvious problem that your linker is looking for a freeglut.obj, which you don't have. Make sure you're calling it freeglut.lib.

Conceptually, here's what happening, and this may help you troubleshoot: When you write a cpp file and compile it, it's turned into an obj file. The compiler doesn't need to know everything. You can declare a function that returns an int and takes a bool as an argument, and use it in your code and the compiler says "ok, if you say so."

Your program will probably have several cpp files, and hence several obj files. After compilation, the obj files are linked together and form your executable. If anything goes wrong here (it has!) it's a linker error. The linker says "ok, you say you're using this function...where is it?"

You've obtained lib files. In this case, they are static libraries, essentially a container for a bundle of obj files, no different than if you had written all of the freeglut functions and classes yourself and compiled them. The linker wants to link them. For code that you write and compile, Visual Studio makes sure everything ends up in the right folder and that it looks in the right place. For compiled object files coming from somewhere else? It has no way of knowing, so you have to tell VS two things: What folder the libraries are in, and what the names of the library files are. Then the linker knows where to look, and what it's looking for.

Somewhere along the line you put the files in the wrong place, or told VS the wrong location, or the wrong files, or some combination. OR you've done something like have spaces in a file path without quotes. Another common error is mixing different platforms. x86 (i.e., 32 bit) and x64 object files are different, and if your linker is looking for one type, it won't understand the other. Your download provided the libraries for different platforms, and VS lets you choose a target platform. Make sure everything is the same.

mock_blatt
  • 955
  • 5
  • 11
  • Ok, I reviewed everything I did, and I do have the linker correct and the files correct. BUT, I am missing this "freeglut.sln" file that is supposed to give me projects to compile, that will give me a new "freeglut.lib" that will work. And, ontop of that, I found the file online from here: – Max Khan Jul 29 '15 at 19:01
  • But when I load the .sln project, it says that it is incompatible because I do not have VS'12, as I am using VS'13. Should I abandon this and search a different way to learn openGL? – Max Khan Jul 29 '15 at 19:03
  • That tutorial you're following is for 2013, that's odd. You can download the latest source files here: http://sourceforge.net/projects/freeglut/files/freeglut/3.0.0/ - Once you do that, you'll need to get 7-zip to unzip the tar.gz file, then read the CMAKE.readme file and follow the instructions for Windows. You'll also need cmake. It's not trivial, but it might be a good chance to learn how to do this. Getting the raw source files, and building the project and libraries yourself is a useful skill. – mock_blatt Jul 29 '15 at 21:55
  • Ok, I will try this and get back to you to see if this works. – Max Khan Jul 30 '15 at 02:11