Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2.1 and GLEW  (Read 6031 times)

0 Members and 1 Guest are viewing this topic.

Cyragia

  • Newbie
  • *
  • Posts: 17
    • View Profile
SFML 2.1 and GLEW
« on: October 29, 2013, 05:50:48 pm »
Hello,
I'm making an openGL application using sfml en glew. (I'm using sfml 2.1)
I'm including my own glew headers and linking to both glew  and sfml statically.

When I try to compile my code a get tons of linker errors like this one:
sfml-graphics-s.lib(glew.obj) : error LNK2005: ___glewCopyTexSubImage3D already defined in glew32s.lib(glew.obj)

When I don't link to glew32s.lib I can't use glew myself.
main.obj : error LNK2001: unresolved external symbol _glewInit@0

I have searched the forum and found some glew related topics but none had a solution to my problem.

Any help is appreciated...

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11045
    • View Profile
    • development blog
    • Email
AW: SFML 2.1 and GLEW
« Reply #1 on: October 29, 2013, 06:09:35 pm »
You want to get the latest version from GitHub, because Laurent removed the script that includes glew into SFML a few days ago.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Cyragia

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML 2.1 and GLEW
« Reply #2 on: October 29, 2013, 07:09:55 pm »
so, I downloaded and compiled the most recent version of sfml on git, but I still can't get my program to compile.

If I link with glew.lib (the one in included in sfml)
I still can't use glew myself and I get these errors:
1>------ Build started: Project: VoxelGame, Configuration: Release Win32 ------
1>Linking...
1>main.obj : error LNK2001: unresolved external symbol __imp__glDepthFunc@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glClear@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glClearColor@16
1>main.obj : error LNK2001: unresolved external symbol __imp__glDrawElements@16
1>main.obj : error LNK2001: unresolved external symbol _glewInit@0
1>main.obj : error LNK2001: unresolved external symbol _glewGetString@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glDepthMask@4
1>main.obj : error LNK2001: unresolved external symbol _glewGetErrorString@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glCullFace@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glViewport@16
1>main.obj : error LNK2001: unresolved external symbol __imp__glEnable@4
1>sfml-window-s.lib(GlContext.obj) : error LNK2001: unresolved external symbol __imp__glEnable@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glFrontFace@4
1>glew.lib(glew.obj) : error LNK2001: unresolved external symbol __imp__wglGetProcAddress@4
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglGetProcAddress@4
1>glew.lib(glew.obj) : error LNK2001: unresolved external symbol __imp__glGetString@4
1>sfml-window-s.lib(GlContext.obj) : error LNK2001: unresolved external symbol __imp__glGetString@4
1>glew.lib(glew.obj) : error LNK2001: unresolved external symbol __imp__wglGetCurrentDC@0
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglGetCurrentContext@0
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglShareLists@8
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglCreateContext@4
1>sfml-window-s.lib(JoystickImpl.obj) : error LNK2001: unresolved external symbol __imp__joyGetPosEx@8
1>sfml-window-s.lib(JoystickImpl.obj) : error LNK2001: unresolved external symbol __imp__joyGetDevCapsW@12
1>sfml-system-s.lib(SleepImpl.obj) : error LNK2001: unresolved external symbol __imp__timeEndPeriod@4
1>sfml-system-s.lib(SleepImpl.obj) : error LNK2001: unresolved external symbol __imp__timeBeginPeriod@4
1>sfml-system-s.lib(SleepImpl.obj) : error LNK2001: unresolved external symbol __imp__timeGetDevCaps@8
1>C:\Users\Manu\Desktop\Coding\OpenGL\VoxelGame\Release\VoxelGame.exe : fatal error LNK1120: 25 unresolved externals
1>Build log was saved at "file://c:\Users\Manu\Desktop\Coding\OpenGL\VoxelGame\VoxelGame\Release\BuildLog.htm"
1>VoxelGame - 29 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

If I include glew32s.lib (the one from my own copy of glew)
I get these errors:
1>------ Build started: Project: VoxelGame, Configuration: Release Win32 ------
1>Linking...
1>main.obj : error LNK2001: unresolved external symbol __imp__glDepthFunc@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glClear@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glClearColor@16
1>main.obj : error LNK2001: unresolved external symbol __imp__glDrawElements@16
1>main.obj : error LNK2001: unresolved external symbol __imp__glDepthMask@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glCullFace@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glViewport@16
1>main.obj : error LNK2001: unresolved external symbol __imp__glEnable@4
1>sfml-window-s.lib(GlContext.obj) : error LNK2001: unresolved external symbol __imp__glEnable@4
1>main.obj : error LNK2001: unresolved external symbol __imp__glFrontFace@4
1>glew32s.lib(glew.obj) : error LNK2001: unresolved external symbol __imp__wglGetProcAddress@4
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglGetProcAddress@4
1>glew32s.lib(glew.obj) : error LNK2001: unresolved external symbol __imp__glGetString@4
1>sfml-window-s.lib(GlContext.obj) : error LNK2001: unresolved external symbol __imp__glGetString@4
1>glew32s.lib(glew.obj) : error LNK2001: unresolved external symbol __imp__wglGetCurrentDC@0
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglGetCurrentContext@0
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglShareLists@8
1>sfml-window-s.lib(WglContext.obj) : error LNK2001: unresolved external symbol __imp__wglCreateContext@4
1>sfml-window-s.lib(JoystickImpl.obj) : error LNK2001: unresolved external symbol __imp__joyGetPosEx@8
1>sfml-window-s.lib(JoystickImpl.obj) : error LNK2001: unresolved external symbol __imp__joyGetDevCapsW@12
1>sfml-system-s.lib(SleepImpl.obj) : error LNK2001: unresolved external symbol __imp__timeEndPeriod@4
1>sfml-system-s.lib(SleepImpl.obj) : error LNK2001: unresolved external symbol __imp__timeBeginPeriod@4
1>sfml-system-s.lib(SleepImpl.obj) : error LNK2001: unresolved external symbol __imp__timeGetDevCaps@8
1>C:\Users\Manu\Desktop\Coding\OpenGL\VoxelGame\Release\VoxelGame.exe : fatal error LNK1120: 22 unresolved externals
1>Build log was saved at "file://c:\Users\Manu\Desktop\Coding\OpenGL\VoxelGame\VoxelGame\Release\BuildLog.htm"
1>VoxelGame - 26 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Am I soing something wrong ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.1 and GLEW
« Reply #3 on: October 29, 2013, 08:01:22 pm »
glew is not the only dependency that you now have to link yourself. There are gdi32, opengl32, winmm, freetype, etc.
Laurent Gomila - SFML developer

Cyragia

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML 2.1 and GLEW
« Reply #4 on: October 29, 2013, 08:10:00 pm »
ah, didn't know that...
is there a comprehensive list somewhere of what to link ?

Or another solution to my initial problem ?

I still can't get it to compile, if I link with glew.lib i can't use glew, if I link with glew32s.lib sfml can't use glew.
(If i don't use SMFL/Graphics it compiles fine)
« Last Edit: October 29, 2013, 08:33:01 pm by Cyragia »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.1 and GLEW
« Reply #5 on: October 29, 2013, 08:53:52 pm »
When you link glew32s.lib, you define the GLEW_STATIC macro, right?

You should be able to link without errors by not linking glew yourself and defining the GLEW_STATIC macro.

Quote
is there a comprehensive list somewhere of what to link ?
Not yet, since it's only available in the current sources.
Laurent Gomila - SFML developer

Cyragia

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML 2.1 and GLEW
« Reply #6 on: October 29, 2013, 09:05:55 pm »
Yes, I defined the GLEW_STATIC macro.
And I magaged to fix it by using the glew files (inlcude and lib) from the sfml folder.
This only worked with the version I compiled myself, not with the standard 2.1 version.
So i think the problem is fixed for me atm, but there should be a way to do it with the default 2.1 files, right ?
I'd like to be able to use the default files and not a homecompiled one.
« Last Edit: October 29, 2013, 09:08:10 pm by Cyragia »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: SFML 2.1 and GLEW
« Reply #7 on: October 29, 2013, 10:07:46 pm »
I'm fairly sure it can't be done with 2.1, which is the whole reason the linking process was changed recently; now that you're responsible for including and linking the dependencies you have the power to change how it's done.

It should be possible with 2.2's "default files" when that comes out.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.1 and GLEW
« Reply #8 on: October 29, 2013, 10:19:23 pm »
I'm pretty sure it can be done with SFML 2.1 (the recent modification solves a less obvious problem), but I don't have the time to try myself. Linking GLEW directly or through the SFML static libs should have the same result.

Ok... let's summon binary1248 :P
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: SFML 2.1 and GLEW
« Reply #9 on: October 29, 2013, 11:46:12 pm »
GLEW doesn't do much besides define the needed OpenGL constants and set up function entry points for everything that is supported on the graphics hardware. The thing to remember is that the addresses that are defined in glew.h are defined as extern, meaning that the linker will look for the location of those symbols in one of the libraries you feed it.

Obviously there should only be a single definition of the GLEW symbols because when calling glewInit() it only populates the set it finds first. The symbols must also match the headers that you use everywhere in the project, this includes the libraries. So you can't compile a library using version X of GLEW and use version Y of GLEW.

The only way to make sure this doesn't happen is by forcing CMake to use a certain header and certain GLEW library that you compiled yourself. This obviously implies that you should build the library yourself as well (no precompiled SFML prior to... 2.2?). It worked for me, since CMake tends to find things in places I never even knew existed :P.

I might have understood something wrong, since many different scenarios were discussed in this thread already :P.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Cyragia

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML 2.1 and GLEW
« Reply #10 on: October 30, 2013, 09:53:40 am »
It got it to work with default sfml 2.1 !
I used the glew headers from the extlibs folder (from git), defined GLEW_STATIC and linked to the static sfml libs (not to glew.lib, neither glew32s.lib), and it worked !
So it was probably a slightly different version...

Maybe you should include the extlibs folder in the official 2.1 version so we can use the same glew version as sfml. (and add this to the opengl tutorial maybe ?)


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.1 and GLEW
« Reply #11 on: October 30, 2013, 09:58:38 am »
Everything that needs to be done will be done in the next release.
Laurent Gomila - SFML developer

Cyragia

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML 2.1 and GLEW
« Reply #12 on: October 30, 2013, 09:59:39 am »
Great !
And thanks for the help everyone !