E
E
Evgeny Labuzov2016-03-19 21:20:01
C++ / C#
Evgeny Labuzov, 2016-03-19 21:20:01

How to connect SFML-2.3.2 to c++ project in VS2015 IDE or CodeBlocks?

I can't connect SFML to the project.
Connected in different ways according to different tutorials.
...I even already learned how to do it :)
windows10 x64
Test code:

#include <SFML/Graphics.hpp>

int main(){
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    return 0;
}

in CodeBlocks 16.01 gives the following errors:
Build log:
-------------- Build: Debug in sfml_test (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -LC:\c\SFML-2.3.2\lib -LC:\c\SFML-2.3.2\lib -LC:\c\SFML-2.3.2\lib -o bin\Debug\sfml_test.exe obj\Debug\src\main.o  -v -static-libgcc -static-libstdc++ -std=c++11 -v -static-libgcc -static-libstdc++ -std=c++11  C:\c\SFML-2.3.2\lib\libsfml-graphics-s.a C:\c\SFML-2.3.2\lib\libsfml-system-s.a C:\c\SFML-2.3.2\lib\libsfml-window-s.a C:\c\SFML-2.3.2\lib\libsfml-graphics-s-d.a C:\c\SFML-2.3.2\lib\libsfml-system-s-d.a C:\c\SFML-2.3.2\lib\libsfml-window-s-d.a -lsfml-graphics-s-d -lsfml-window-s-d -lsfml-system-s-d -mwindows
Using built-in specs.
COLLECT_GCC=mingw32-g++.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-4.9.3/configure --build=x86_64-pc-linux-gnu --host=mingw32 --prefix=/mingw --disable-win32-registry --target=mingw32 --with-arch=i586 --enable-languages=c,c++,objc,obj-c++,fortran,ada --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --enable-libstdcxx-debug --with-tune=generic --enable-nls
Thread model: win32
gcc version 4.9.3 (GCC) 
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.9.3/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../
COLLECT_GCC_OPTIONS='-LC:\c\SFML-2.3.2\lib' '-LC:\c\SFML-2.3.2\lib' '-LC:\c\SFML-2.3.2\lib' '-o' 'bin\Debug\sfml_test.exe' '-v' '-static-libgcc' '-std=c++11' '-v' '-static-libgcc' '-std=c++11' '-mwindows' '-mtune=generic' '-march=i586'
 c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/collect2.exe -plugin c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/liblto_plugin-0.dll -plugin-opt=c:/mingw/bin/../libexec/gcc/mingw32/4.9.3/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\USER\AppData\Local\Temp\ccPmQFsm.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lgdi32 -plugin-opt=-pass-through=-lcomdlg32 -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt --subsystem windows -Bdynamic -o bin\Debug\sfml_test.exe c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../crt2.o c:/mingw/bin/../lib/gcc/mingw32/4.9.3/crtbegin.o -LC:\c\SFML-2.3.2\lib -LC:\c\SFML-2.3.2\lib -LC:\c\SFML-2.3.2\lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.9.3 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../.. obj\Debug\src\main.o C:\c\SFML-2.3.2\lib\libsfml-graphics-s.a C:\c\SFML-2.3.2\lib\libsfml-system-s.a C:\c\SFML-2.3.2\lib\libsfml-window-s.a C:\c\SFML-2.3.2\lib\libsfml-graphics-s-d.a C:\c\SFML-2.3.2\lib\libsfml-system-s-d.a C:\c\SFML-2.3.2\lib\libsfml-window-s-d.a -lsfml-graphics-s-d -lsfml-window-s-d -lsfml-system-s-d -Bstatic -lstdc++ -Bdynamic -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lgdi32 -lcomdlg32 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.9.3/crtend.o

Build Messages:
||=== Build: Debug in sfml_test (compiler: GNU GCC Compiler) ===|
obj\Debug\src\main.o||In function `main':|
C:\c\sfml_test\src\main.cpp|4|undefined reference to `sf::String::String(char const*, std::locale const&)'|
C:\c\sfml_test\src\main.cpp|4|undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'|
C:\c\sfml_test\src\main.cpp|4|undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'|
C:\c\sfml_test\src\main.cpp|5|undefined reference to `sf::RenderWindow::~RenderWindow()'|
||error: ld returned 1 exit status|
||=== Build failed: 5 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

In the project options I specify:
Other linker options (for debug, release, general):
-v
-static-libgcc
-static-libstdc++
-std=c++11
in Link librares I specify (general):
C:\c\SFML- 2.3.2\lib\libsfml-graphics-sa
C:\c\SFML-2.3.2\lib\libsfml-system-sa
C:\c\SFML-2.3.2\lib\libsfml-window-sa
in debug all the same thing only with the -sd postfix
in release the same but with the -s postfix
It is worth mentioning that in most tutorials it is said
about specifying the names of libraries without writing the path, such as "sfml-system"
Actually, I tried this, but the result is the same.
Search directories says (general, debug, release):
Compiler: C:\c\SFML-2.3.2\include
Linker: C:\c\SFML-2.3.2\lib
All paths have been checked and the presence of files in them too...
In Compiler settings -> defines(general , debug, release):
SFML_STATIC
In the general settings I have Settings->Compiler->Toolchain executables:
Compiler's installation directory: C:\MinGW
The rest of the default settings have not changed. File paths and directories have been checked.
SFML was obtained from the link: www.sfml-dev.org/files/SFML-2.3.2-windows-gcc-4.9....
...well, bang your head against the wall, it won't work!
...Next, I tried to run something in Visual Studio Community 2015. I
created a project, included a file with a minimal test code...
The project switched to x64
In the project settings I wrote:
С/С++ -> General -> "Additional include directories": C:\c\SFML-2.3.2-studio\include;%(AdditionalIncludeDirectories)
С/С+ + -> Preprocessor -> "Preprocessor Definitions": SFML_STATIC;%(PreprocessorDefinitions)
Linker -> General -> "Additional Library Directories": C:\c\SFML-2.3.2-studio\lib;%(AdditionalLibraryDirectories)
Linker -> Input-> "Additional dependencies": flac.lib;freetype.lib;jpeg.lib;ogg.lib;openal32.lib;sfml-audio-s.lib;sfml-graphics-s.lib;sfml-main .lib;sfml-network-s.lib;sfml-system-s.lib;sfml-window-s.lib;vorbis.lib;vorbisenc.lib;vorbisfile.lib;kernel32.lib;user32.lib;gdi32.lib ;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
(This time I included everything that was in the sfml library, but with a single -s prefix)
, the settings are specified for all configurations, in particular for x64 for which the assembly is being performed.
....what does Visual Studio tell us:
Серьезность	Код	Описание	Проект	Файл	Строка
Ошибка	LNK2001	неразрешенный внешний символ "__imp_glGetIntegerv"	sfml_test2	C:\c\sfml_test2\sfml_test2\sfml_test2\sfml-graphics-s.lib(GLLoader.cpp.obj)	1
Ошибка	LNK2001	неразрешенный внешний символ "__imp_glGetError"	sfml_test2	C:\c\sfml_test2\sfml_test2\sfml_test2\sfml-graphics-s.lib(GLLoader.cpp.obj)	1
Ошибка	LNK2001	неразрешенный внешний символ "__imp_glGetString"	sfml_test2	C:\c\sfml_test2\sfml_test2\sfml_test2\sfml-graphics-s.lib(GLLoader.cpp.obj)	1
... ... ...
C:\c\sfml_test2\sfml_test2\sfml_test2\sfml-window-s.lib(WglContext.cpp.obj)	1
Ошибка	LNK1120	неразрешенных внешних элементов: 44	sfml_test2	C:\c\sfml_test2\sfml_test2\x64\Release\sfml_test2.exe	1

For Visual Studio, I found several instructions for connecting, including using the dynamic linking of dll libraries, but no matter how I tried to connect sfml or run some minimal code, I got a bunch of errors ...
Please tell me how to connect it correctly, and force at least something to work?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeniy Labuzov, 2016-03-20
@silksofthesoul

Hooray! I started the project in visual studio!
Just in case, here are the tutorials that helped me:
gamecodeschool.com/sfml/setting-up-visual-studio-a...
gamecodeschool.com/sfml/building-your-first-sfml-g...
I don't know about what was the problem, but I did the following:
All attempts before this I created a new empty project.
And it was necessary to apparently create a "New win32 console application".
Such are the things...

A
AtomKrieg, 2016-03-19
@AtomKrieg

Under codeblock, you need to build your own versions of libraries, since those posted offsite do not fit the compiler in 16.01 (version 4.9.2, 32 bit, SJLJ)
For the studio, they forgot to specify winmm.lib and opengl32.lib: www.sfml-dev.org/ tutorials/2.3/start-vc.php they are listed here in the dependency plate.

A
Artyom Sveshnikov, 2016-03-20
@zenitfan2109

Try creating an SFML project in the Code::Blocks environment. All the necessary settings are listed there. And yes, under Code::Blocks (and under MSVS) it is better to build SFML yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question