# The process of creating a simple GLFW test program (Question)

**URL:** <https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179>\
**Category:** support\
**Created:** [November 6, 2015, 9:50pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179 "2015-11-06T21:50:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [November 6, 2015, 9:50pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/1 "2015-11-06T21:50:28Z")

</div>

**[arkathorn](https://sourceforge.net/u/arkathorn/)** wrote on [Friday, November 06, 2015](https://sourceforge.net/p/glfw/discussion/247562/thread/75f5e0cc/#b286):

I have recently begun with C++, and am attempting to begin OpenGL programming, starting with GLFW. I have created a small test program, to be built upon as I go:

```auto
#include <iostream>
#include <GLFW/glfw3.h>

using namespace std;

int main() {
	if(!glfwInit()) {
		return 1;
	}
	glfwTerminate();
	return 0;
}

```

I am compiling using MinGW’s g++. Unfortunately, though I have tried extensively to do so, I cannot discern how to properly link GLFW to the compilation, in such a way as it can actually be compiled. Can anyone detail the process? In detail?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [December 7, 2015, 4:08pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/2 "2015-12-07T16:08:36Z")

</div>

**[arkathorn](https://sourceforge.net/u/arkathorn/)** wrote on [Monday, December 07, 2015](https://sourceforge.net/p/glfw/discussion/247562/thread/75f5e0cc/#b85b):

Nobody?

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [December 7, 2015, 4:18pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/3 "2015-12-07T16:18:19Z")

</div>

There’s [documentation on compiling with GLFW](http://www.glfw.org/docs/latest/build.html#build_link_win32) which also links to a [Beginner’s Guide to Linkers](http://www.lurklurk.org/linkers/linkers.html). Also [this answer on Stackoverflow](http://stackoverflow.com/questions/12886609/setting-up-glfw-with-mingw) may help.

With g++ your command line should look something like:

g++ -o myexe mysourcefile.cpp -lglfw32 -lopengl32

If you are having problems getting this to work, then paste your command line used along with the output from the compiler and notes as to what files you have.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [December 7, 2015, 6:49pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/4 "2015-12-07T18:49:48Z")

</div>

**[mmozeiko](https://sourceforge.net/u/mmozeiko/)** wrote on [Monday, December 07, 2015](https://sourceforge.net/p/glfw/discussion/247562/thread/75f5e0cc/#4347):

It should be lowercase -l for specifying libraries: -lglfw32 -lopengl32. Uppercase L is for specifying folders where to search libraries.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [December 7, 2015, 7:08pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/5 "2015-12-07T19:08:29Z")

</div>

Thanks, apologies for mistake - corrected that.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [December 9, 2015, 5:06pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/6 "2015-12-09T17:06:15Z")

</div>

**[arkathorn](https://sourceforge.net/u/arkathorn/)** wrote on [Wednesday, December 09, 2015](https://sourceforge.net/p/glfw/discussion/247562/thread/75f5e0cc/#4846/fcc3):

I read that, but what files do I download? What do I do, with which files? The process in it’s entirety is not detailed.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [December 9, 2015, 6:00pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/7 "2015-12-09T18:00:08Z")

</div>

I disagree - the process in its entirety is very well detailed, but aimed at more experienced programmers than yourself. You didn’t mention that you did not know where to download the required files in your question - if you want to get a detailed response then please be specific.

See the [glfw download page](http://www.glfw.org/download.html) for download links. This is linked to from the main glfw page under the heading ‘download’. You need either the 32bit or 64bit Windows binaries depending on which version of MinGW you have. You’ll find the libraries in the folder lib-mingw(version).

I recommend moving the libraries into the same folder as your C++ source code for now, and move the GLFW folder which is in the Include directory into the directory you have your C++ code in. This means you don’t have to set up paths for your include and libraries.

Good luck.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [December 9, 2015, 9:01pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/8 "2015-12-09T21:01:44Z")

</div>

**[arkathorn](https://sourceforge.net/u/arkathorn/)** wrote on [Wednesday, December 09, 2015](https://sourceforge.net/p/glfw/discussion/247562/thread/75f5e0cc/#4846/fcc3/3678/58f5):

Welp. Still the same old undefined reference errors. Project dump follows:

File structure:

```auto
+- GLFW
| +- glfw3.h
| +- glfw3native.h
+- build.bat
+- glfw.dll
+- glfwdll.a
+- libglfw3.a
+- Main.cpp

```

build.bat:

```auto
g++ -o glfw-test -lglfw3 -lopengl32 main.cpp
pause

```

Main.cpp:  
(See Above)

I apologize if this is really obvious, but I have no experience with manual compilation/linking.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [December 9, 2015, 9:30pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/9 "2015-12-09T21:30:07Z")

</div>

Could you add the errors from the compile please.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [December 9, 2015, 11:16pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/10 "2015-12-09T23:16:57Z")

</div>

**[arkathorn](https://sourceforge.net/u/arkathorn/)** wrote on [Wednesday, December 09, 2015](https://sourceforge.net/p/glfw/discussion/247562/thread/75f5e0cc/#4846/fcc3/3678/58f5/f7fb/ede5):

Whoops, forgot about those.

```auto
C:\Users\AccountName\AppData\Local\Temp\cc14CDRC.o:Main.cpp:(.text+0xc): undefined reference to `glfwInit'
C:\Users\AccountName\AppData\Local\Temp\cc14CDRC.o:Main.cpp:(.text+0x21): undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status

```

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [December 11, 2015, 12:42pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/11 "2015-12-11T12:42:52Z")

</div>

OK - I also encountered these problems, but found a fix.

1. I’m using the 32bit version of MinGW. I can tell this as I see mingw32 in the output and not mingw64 (add -v to command line for verbose output from g++ if you don’t see which version your using). Thus I used the libs from glfw-3.1.2.bin.WIN32\lib-mingw
2. I removed the iostream include and using namespace as you don’t need them for this.
3. I compiled Main.cpp to Main.o using g++ -c -I. Main.cpp
4. I linked using: g++ -o Main.exe Main.o -L. -lglfw3 -lopengl32 -lgdi32

Basically there seems to be a problem with compiling and linking on one command line, not sure why (it’s been 15 years since I regularily used unix and I’ve never used MinGW).

Note that I used -I. and -L. to set the compile and link directories as g++ didn’t default to the current dir as I expected.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [December 11, 2015, 1:23pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/12 "2015-12-11T13:23:56Z")

</div>

**[arkathorn](https://sourceforge.net/u/arkathorn/)** wrote on [Friday, December 11, 2015](https://sourceforge.net/p/glfw/discussion/247562/thread/75f5e0cc/#4846/fcc3/3678/58f5/f7fb/ede5/e9b9/4c3a):

It worked! I cannot thank you enough for your help.

---

<div class="post-metadata">

**Author:** ![elmindreda](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/elmindreda/32/26_2.png) [@elmindreda](https://discourse.glfw.org/u/elmindreda)\
**Post date:** [December 12, 2015, 10:04pm UTC](https://discourse.glfw.org/t/the-process-of-creating-a-simple-glfw-test-program-question/179/13 "2015-12-12T22:04:31Z")

</div>

Sorry, I’ll try again. `-L. -lglfw3` is equivalent to `libglfw3.a`, i.e. just specifying the library file name.
