Skip to main content
GameDev.net gamedev.net
🔒 Locked

SFML sf::window linker errors (They just keep coming...)

Started by The Communist Duck Jan 18, 2010 at 3:20 PM 14 replies 7.7k views
Original Post
The Communist Duck
The Communist Duck
Hey. Had another crack at some OpenGL, with SFML for window managing and stuff. I tried running the program, but I got linker errors. Which was strange in itself, because it ran fine 4 days ago and I haven't changed anything since. But linker errors follow me everywhere. :/ I reinstalled C::B, because I thought it could help. I rebuilt sfml-main, sfml-system-s, and sfml-window-s from the SVN version. I have included the lib path to them. I have put:

-lsfml-window-s
-lsfml-system-s
//I know I haven't linked -lopengl32, but I get the undefined reference errors
//Even if I make a new project with just sf::Window in it.
I don't #define SFML_DYNAMIC...and can't think of anything else to check. Thanks guys/girls. -TCD
fcoelho
fcoelho
Since it all appears to be right, just a guess, do you add these dependencies for the same build target you're building? i.e., make sure that if you're building in debug mode, these dependencies are listed when you select the debug build target.
The Communist Duck
The Communist Duck
Quote:
Original post by fcoelho
Since it all appears to be right, just a guess, do you add these dependencies for the same build target you're building? i.e., make sure that if you're building in debug mode, these dependencies are listed when you select the debug build target.


Do you mean link the debug (-d) versions of the libraries, or the Debug/Release library include settings? I have the release static libraries on the linker in general, so I assumed it would link whatever build target. Debug+debug libraries make no difference to the issue.
fcoelho
fcoelho
Not really, I meant it like this:



You can set the linker options based on the render target (I use just two, the default debug and release). If you add the options for the debug release, as in the left screen, and try to build in release mode (in the right picture, highlighted as debug here), these won't be added to the command line. Check the command in the build log tab when you try to compile it to see if these options are actually being passed to the compiler, i.e., something like
g++ ... -lsfml-window -lsfml-system ...
The Communist Duck
The Communist Duck
I tried that, and had no effect at all I'm afraid. It's also something I haven't set before (since I set the link libraries for all projects, rather than single ones.).

I can't find a way to look at the command line from within C::B either.

Thanks for the help anyway.
-TCD
fcoelho
fcoelho
Go to [Settings > Compiler and Debugger > Other Settings] and choose "Full command Line" as "compiler logging". When you build your project, the command line used will be output in the "build log" tab.
The Communist Duck
The Communist Duck
mingw32-g++.exe -L"G:\Libraries And Code\SFML Libs and Headers\lib"  -o "bin\Release\SFML Test.exe" obj\Release\main.o   -s -lsfml-window-s -lsfml-system-s  "G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s-d.a""G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-main.a" "G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-main-d.a" "G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-system-s.a" "G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-system-s-d.a" "G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a" 


It seems to be linking everything fine.
fcoelho
fcoelho
Why is it linking to the same library multiple times? Since you have
-L"G:\Libraries And Code\SFML Libs and Headers\lib"
in the library search path, only adding sfml-window and sfml-system should work. Doing this:
#include <SFML/Window.hpp>int main(int argc, char *argv[]){	bool running = true;	sf::Window app(sf::VideoMode(800,600,32), "my window");	while (running)	{		sf::Event event;		while (app.GetEvent(event))		{			if (event.Type == sf::Event::KeyPressed)				if (event.Key.Code == sf::Key::Escape)					running = false;		}				app.Display();	}}

gives me a nice blank window. And my command line is
g++ myfile.cpp -o myoutput -lsfml-window -lsfml-system
and nothing more.[edit]Oh yeah, and I'm bulding on the console, in C::B it should be a little different..[/edit]

Did you built the libraries yourself or get them prebuilt? There are a lot of versions of MinGW out there, and a few are incompatible regarding object files. Unless you're actually using one built for the same version as the one you use, it's better to just recompile it from source, it's not a painful process and will save a lot of trouble.
The Communist Duck
The Communist Duck
mingw32-g++.exe -L"G:\Libraries And Code\SFML Libs and Headers\lib"  -o "bin\Release\SFML Test.exe" obj\Release\main.o   -s -lsfml-window-s -lsfml-system-s  

I had added more paths to see if any difference was made.
And I did recompile the libraries from SVN (so OGL 3.0 was supported).
C&P'd your code...still no change in the errors. :/

EDIT: Tried just copy pasting the .a files to MinGW's lib dir...no dice.
fcoelho
fcoelho
Heh, I don't know what could be wrong now. I don't have the static libraries to test the program with them - I just use the dlls all the time..
As a last resort you can check the libraries with nm to see if the symbols the linker doesn't find are actually in there, things are getting weird..
The Communist Duck
The Communist Duck
I've just given up trying now. :L
I tried to build the SFML2 DLLs, but the graphics one is throwing exactly the same errors as when I try to use the window one.:/

I dont think there's an incremental linker option in C::B?
fcoelho
fcoelho
About incremental linking, I don't know.

About SFML, just to make sure, I've built the sfml2 branch right now and got it working. I don't know why you're getting these errors, it just works fine for me. There must be something else I'm not able to spot from here. Just for the record, can you show the linker errors?
The Communist Duck
The Communist Duck
Here's some quick code:
#include <SFML/Window.hpp>int main(int argc, char* argv[]){    sf::Window window;    return 0;}


Which gives me: (The original project I'm working on gives me 30 of similar errors.)
||=== foo, Release ===|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(Joystick.o):Joystick.cpp:(.text+0x45)||undefined reference to `_joyGetPosEx@8'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(Joystick.o):Joystick.cpp:(.text+0x78)||undefined reference to `_joyGetPosEx@8'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(Joystick.o):Joystick.cpp:(.text+0xab)||undefined reference to `_joyGetDevCapsA@12'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(Joystick.o):Joystick.cpp:(.text+0x150)||undefined reference to `_joyGetDevCapsA@12'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(Joystick.o):Joystick.cpp:(.text+0x188)||undefined reference to `_joyGetPosEx@8'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(WindowImplWin32.o):WindowImplWin32.cpp:(.text+0xb4)||undefined reference to `_SwapBuffers@4'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(WindowImplWin32.o):WindowImplWin32.cpp:(.text+0x2264)||undefined reference to `_ChoosePixelFormat@8'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(WindowImplWin32.o):WindowImplWin32.cpp:(.text+0x22b8)||undefined reference to `_DescribePixelFormat@16'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(WindowImplWin32.o):WindowImplWin32.cpp:(.text+0x22f6)||undefined reference to `_SetPixelFormat@12'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(WindowImplWin32.o):WindowImplWin32.cpp:(.text+0x2494)||undefined reference to `_DescribePixelFormat@16'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(WindowImplWin32.o):WindowImplWin32.cpp:(.text+0x27f8)||undefined reference to `_GetDeviceCaps@8'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(WindowImplWin32.o):WindowImplWin32.cpp:(.text+0x281f)||undefined reference to `_GetDeviceCaps@8'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(WindowImplWin32.o):WindowImplWin32.cpp:(.text+0x2d18)||undefined reference to `_GetDeviceCaps@8'|G:\Libraries And Code\SFML Libs and Headers\lib\libsfml-window-s.a(WindowImplWin32.o):WindowImplWin32.cpp:(.text+0x2d3f)||undefined reference to `_GetDeviceCaps@8'|||=== Build finished: 14 errors, 0 warnings ===|


After trying for a while, I tried building the dynamic libraries. sfml-window and sfml-system built fine, but sfml-graphics decided to only build as static. I just hope you can mix static/DLL libraries. :P
Thanks for all your help.
-TCD
LaurentGom
LaurentGom
Hi

Have you read the tutorials?

Quote:
Getting started with Code::Blocks / MinGW

Compiling SFML

[...]
Compiling SFML static libraries with MinGW requires an extra-step if you want to include the external libraries as well. If you don't do it, you will have to explicitly link with the external libraries used by SFML in each of your programs.
Unfortunately Code::Blocks can't perform this step automatically, but a batch script named build.bat exists in SFML-x.y\build\codeblocks\batch-build. This script automatically compiles the SFML libraries for all configurations (debug/release static/dynamic) and performs the extra step required for static libraries. All you have to do before running it is to make your Code::Blocks executable (codeblocks.exe) available, i.e. add its path to the PATH environment variable.


From your error messages, it seems that you're compiling SFML 1.6 (trunk), not SFML 2 (branches/sfml2). OpenGL 3 support is only available in SFML 2.
The Communist Duck
The Communist Duck
Hey Laurent,

Yes, I have read the tutorials (numerous times, they're good. :D),but I havent' batch built them. Mainly because, originally, I forgot to batch build however the libraries *appeared* to work fine, at least for a time. So I just ignored it, which probably wasn't a good idea. :/

However I do believe I am using SFML1.6.
I used the GL version checking functions which gave me version 3.0, apparently.

I shall try the batch build though, thanks. :D
fcoelho
fcoelho
Those messages are not due to SFML. These functions are in libwinmm. At the end of your linker list, include winmm and gdi32.

When you say you can't build sfml-graphics, check that it isn't because the name used for the library in the build options is the same. For me, the .a file for sfml-system is named sfml-system.dll.a, whilst the one used in the linker for sfml-graphics was just sfml-system.a. If that's the case, change that and it should build fine.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.