SFML community forums

Help => General => Topic started by: MDK on February 21, 2017, 06:47:00 pm

Title: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: MDK on February 21, 2017, 06:47:00 pm
I can't run example code. When i'm compiling it, i have this message:
||=== Build: Debug in sfml-project01 (compiler: GNU GCC Compiler) ===|
ld.exe||cannot find -lsfml-graphics|
ld.exe||cannot find -lsfml-window|
ld.exe||cannot find -lsfml-system|
||error: ld returned 1 exit status|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I did everything as is said in this tutorial: https://www.sfml-dev.org/tutorials/2.0/start-cb.php
Additionally:

I downloaded and installed this: TDM 4.9.2 (64-bit), codeblocks-16.01-setup.exe, source code of sfml 2.4.2 and made sfml with cmake. Then I created new project, new file.cpp, copied code, and after compilation I had those error messages. After that I followed few YouTube tutorials, tried static and non static version of configuration and nothing changed
I have Windows 10 64bit if this is important.
Here are pics of configuration:
(http://i65.tinypic.com/nog35z.jpg)
(http://i67.tinypic.com/npjhvk.jpg)
(http://i66.tinypic.com/f00nq1.jpg)
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: sjaustirni on February 21, 2017, 07:16:30 pm
Just a quick thought - what is the contents of C:/SFML/lib? Have you moved the compiled libraries to this folder you refer to in C::B?
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: MDK on February 21, 2017, 07:28:35 pm
When i was ask if path to te lib should be relative, i answered no. So i think, this should be full path to the folder where i have all files, that was made by cmake from SFML 2.4.2.. This folder is C:\SFML.
Title: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: eXpl0it3r on February 21, 2017, 07:29:52 pm
And what's the content of the directory?
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: MDK on February 21, 2017, 07:34:22 pm
/bin/openal32.dll
/cmake/Modules/FindSFML.cmake
/include/SFML/Audio,Graphics,Network,System,Window folders, and header files
/lib/*.a
/license.txt
/readme.txt
Title: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: eXpl0it3r on February 21, 2017, 09:25:26 pm
Don't make assumptions about how things work on Windows based on your experience with Linux, or rather don't give out advice based on these assumptions. ;)

MinGW (GCC) still uses .a files for static libs and import/definition libraries.

So what are the names of these *.a files?
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: MDK on February 21, 2017, 10:10:34 pm
(http://i66.tinypic.com/2e6817l.jpg)
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: eXpl0it3r on February 21, 2017, 10:37:18 pm
So how do you expect GCC to find "sfml-graphics" if your directory only contains "sfml-graphics-s"? ;)

If you want to link the static version, you have to add the -s suffix and define SFML_STATIC.
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: MDK on February 21, 2017, 11:04:39 pm
I did everything like on this tutorial:https://www.youtube.com/watch?v=0LGzJP3k7M4
And now have this:
(http://i66.tinypic.com/ajq7hu.jpg)
Can problem be somewhere else, because i checked it twice doing above. And why my directory contain only -s versions of these files?
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: eXpl0it3r on February 21, 2017, 11:15:49 pm
The error message is pretty clear. It can't find the specified libraries. And you know why it can't find it, because they don't exist in the specified location.

If you for example just build the static release (-s) set of SFML libraries you'll just have that one version of them. If you now also want the static debug (-s-d) set of SFML libraries, you'll have to adjust the CMake settings and build that set.
In other words, CMake doesn't build all possible variations, but just the one you specify.
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: MDK on February 22, 2017, 01:19:51 am
That solved the problem with missing debug files. But now I have another one. After compiling project there is something like that:
(http://i67.tinypic.com/2dij4tl.jpg)
I thought that this could be problem with downloaded file, so I redownloaded it and CMake it again. And outcome is the same. Then I downloaded this ready to use file:GCC 4.9.2 TDM (SJLJ) - 64-bit and same thing happened. I am starting to believe in this Murphy law: Anything That Can Possibly Go Wrong, Does.
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: eXpl0it3r on February 22, 2017, 01:47:57 am
Read the official tutorial again. Especially the part about linking statically. Make sure it's for the latest SFML version.
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: MDK on February 22, 2017, 02:08:52 am
Yes: Starting from SFML 2.2, when static linking, you will have to link all of SFML's dependencies to your project as well.
Thanks for help and for your patience.
Title: Re: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: Argus on February 23, 2017, 06:41:28 am
There were a few missing dependencies in the tutorial for me, namely "jpeg" and I think one or two others.

This is a good list to start with:

sfml-graphics-s
freetype
jpeg
sfml-window-s
opengl32
gdi32
sfml-system-s
winmm

Do not include the file extensions or even path if you are using Code::Blocks and following the tutorial. Just type these in as-is. That tripped me up for a while.

To my knowledge, all of those were required to compile that program for me on windows. I may be wrong about freetype, but jpeg is for sure.
Title: Cannot compile example code / cannot find -lsfml-graphics, etc...
Post by: eXpl0it3r on February 23, 2017, 08:08:45 am
They are all listed in the tutorial, you just have to read the latest tutorial. ;)