Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


How to import GLFW in eclipse C++ IDE


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Alfox   Members   -  Reputation: 148

Like
0Likes
Like

Posted 11 August 2014 - 09:54 AM

Hi guys

I have a problem to correctly linking GLFW under eclipse Luna C/C++ IDE

I already read this post:

http://www.gamedev.net/topic/647428-glfw3-linker-errors/

I tried his solution

If you are trying to link the static version of the library, libglfw3.a, you have to link gdi32 in this order.

  1. libglfw3.a
  2. gdi32
  3. opengl32

If you are linking in the dynamic link version of the library, glfw3dll.a, you shouldn't need to link gdi32.

 

 

but I received this error:

cannot find -llibglfw3.a              C/C++ Problem

So I changed libglfw3.a with the entire path. But I still receive the same error:

cannot find -lC:\Users\Alfonso-PC\workspace\ProvaGLFW\libglfw3.a    C/C++ Problem

Of corse I also include the .h folder under "Includes"

/ProvaGLFW/glfw/include

And the lib-mingw folder under "Library paths"

/ProvaGLFW/glfw/lib-mingw

How Can I solve this issue?

 


 



Sponsor:

#2 Kaptein   Prime Members   -  Reputation: 2207

Like
1Likes
Like

Posted 11 August 2014 - 10:26 AM

Create a lib folder, add libglfw3.a to it. Add -Llib to linker commandline. Now you can add -lglfw3 -lgdi32 -lopengl32 (also to linker commandline)

Do the same with glew: -lglew32s

You really want glew, because the whole context creation & extension lookup thing in OpenGL is a disaster.

 

Here is an example:

LFLAGS  = -Llib/win32 -static -lglfw3 -lgdi32 -lglew32s -lopengl32


Edited by Kaptein, 11 August 2014 - 10:27 AM.


#3 Alfox   Members   -  Reputation: 148

Like
0Likes
Like

Posted 11 August 2014 - 10:56 AM

Thanks for reply!

So I created the lib folder inside the project with libglfw.a and glew32.dll inside,

under windows cmd, I wrote this:

g++ -LC:\Users\Alfonso-PC\workspace\ProvaGLFW\lib -static -lglfw3 -lgdi32 -lglew32s -lopengl32
-IC:\Users\Alfonso-PC\workspace\ProvaGLFW\glew\include -IC:\Users\Alfonso-PC\workspace\ProvaGLFW\glfw\include ProvaGLFW.cpp

this give me the same error:


c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lglew32s
collect2.exe: error: ld returned 1 exit status

Edited by Alfox, 11 August 2014 - 10:57 AM.


#4 Kaptein   Prime Members   -  Reputation: 2207

Like
1Likes
Like

Posted 11 August 2014 - 11:52 AM

That's because you put a .dll there, it's not static, in fact its dynamic: DLL = Dynamically linked library

(.dll is on linux shared objects: .so)

 

When you add libraries, you basically add an archive (AR archive) of objects that can be added to your binary. It's basically the same as not having a .dll along with your .exe file, and instead putting it all inside your .exe, which means you can feel more pro.

Doing it this way means you don't need to depend on external stuff, and if you do it right you can just send your friends your exe and it will just work.

Static linking isn't the solution to everything, but it's very nice when you get it to work and on windows its pretty much the way to go.

 

So, open the GLEW binary archive from glew website. Go to the windows folder and find libglew32s.lib

Rename it to libglew32s.a, then copy it to your lib folder. Bam.

 

 

EDIT: I couldn't find any precompiled binaries for libglew, so I'm just giving you mine

http://dm.fwsnet.net/libglew32s.a

 

It's for win32 (not 64bit)


Edited by Kaptein, 11 August 2014 - 11:59 AM.


#5 Alfox   Members   -  Reputation: 148

Like
0Likes
Like

Posted 11 August 2014 - 03:55 PM

Hello!

Really thanks for you availability, I downloaded your .a and I put it in the /lib folder.

Now the error is changed.

C:\Users\ALFONS~1\AppData\Local\Temp\ccXaI1XL.o:ProvaGLFW.cpp:(.text+0x17): unde
fined reference to `glfwInit'
C:\Users\ALFONS~1\AppData\Local\Temp\ccXaI1XL.o:ProvaGLFW.cpp:(.text+0x51): unde
fined reference to `_imp__glewInit@0'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\A
LFONS~1\AppData\Local\Temp\ccXaI1XL.o: bad reloc address 0x0 in section `.ctors'

c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
 failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

this is my little main:

#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
using namespace std;

int main() {
	if( !glfwInit() )
	{
		cout << "fail init glfw" << endl; // prints Hello World!!!
		return -1;
	}

	if (glewInit() != GLEW_OK) {
		cout << "fail init glew" << endl; // prints Hello World!!!
			return -1;
		}
	cout << "Hello World!!!" << endl; // prints Hello World!!!

	return 0;
}

===========EDIT==============

My bad, I forgot the:

#define GLEW_STATIC

And I changed the compile command as follow

g++ -IC:\Users\Alfonso-PC\workspace\ProvaGLFW\glfw\include -IC:\Users\Alfonso-PC\workspace\ProvaGLFW\glew\include ProvaGLFW.cpp -LC:\Users\Alfonso-PC\workspace\ProvaGLFW\lib -static -lglfw3 -lgdi32 -lglew32s -lopengl32

Now it compiles: but give me a

Warning: corrupt .drectve at end of def file

and when I launch the a.exe the program (above) enter in the glewInit() "if" and always print

fail init glew

Edited by Alfox, 11 August 2014 - 04:38 PM.


#6 Kaptein   Prime Members   -  Reputation: 2207

Like
1Likes
Like

Posted 11 August 2014 - 05:09 PM

As for GLEW_STATIC just add -DGLEW_STATIC to commandline

Remember to make yourself a basic makefile, as it makes things really simple: make --> done.

In your case it would be mingw32-make instead of just make

 

I don't know the value of GLEW_OK, but this is what I do:

if (glewInit() != GLEW_OK)
{
    // nothing to do, just exit
    std::cout << "(glewInit() != GLEW_OK) this should never happen" << std::endl;
    return EXIT_FAILURE;
}

First I glfwInit(), then I open glfw window, then I glewInit()
Either way its not good because I believe glew creates a context, gets the pointers, then destroys it. This is bad practice, but it just happens to work. I don't really care as long as it works.
 
With that out of the way, at least your program runs now, even if you don't initialize glew.
I have a shitty window opener here if you need something to look at: https://github.com/fwsGonzo/library/blob/master/library/opengl/window.cpp
 
Btw. you need to get rid of those absolute paths in your call to g++ as there is no reason for them to be there. All that's required is for NetBeans (in your case) to set the current directory to your ProvaGLFW folder. It should do that automatically, and if it doesn't, uninstall it and install something else, like CodeLite.
In a normal scenario you would add -Iinc and -Llib.

Edited by Kaptein, 11 August 2014 - 05:15 PM.


#7 Alfox   Members   -  Reputation: 148

Like
0Likes
Like

Posted 11 August 2014 - 06:34 PM

Hello!

I modified my program, as you suggest

First I glfwInit(), then I open glfw window, then I glewInit()

as follow.

#define GLEW_STATIC

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "TryClass.h"
using namespace std;

int main() {
	if( !glfwInit() )
	{
		cout << "fail init glfw" << endl; 
		return -1;
	}

	GLFWwindow* window = glfwCreateWindow( 1024, 768, "Window", NULL, NULL);

	if( window == NULL ){
		cout << "failed to open window" << endl;
		glfwTerminate();
		return -1;
	}
	glfwMakeContextCurrent(window);

	if (glewInit() != GLEW_OK) {
		cout << "fail init glew" << endl; 
		return -1;
	}
	glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
	do{

		// Swap buffers
		glfwSwapBuffers(window);
		glfwPollEvents();

	}
	while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
		glfwWindowShouldClose(window) == 0 );
	
	glfwDestroyWindow(window);
	glfwTerminate();
	return 0;
}

And add -DGLEW_STATIC in commandline

g++ -IC:\Users\Alfonso-PC\workspace\ProvaGLFW\glfw\include -IC:\Users\Alfonso-PC\workspace\ProvaGLFW\glew\include TryClass.cpp ProvaGLFW.cpp -LC:\Users\Alfonso-PC\workspace\ProvaGLFW\lib -static -lglfw3 -lgdi32 -lglew32s -lopengl32 -DGLEW_STATIC

Now I have a "nice" well-functioning black window happy.png

 

Thanks a lot!

now I'll search how to make a "make file"

Again Thanks






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS