Konfiguracja SFML pod Debian pod Codeblocks.

0

Skonfigurowałem Codeblocks według:
https://www.sfml-dev.org/tutorials/2.4/start-cb.php

Przy konpilacji przykł. progz.

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

mam błąd

> 
-------------- Build: Debug in testik (compiler: GNU GCC Compiler)---------------
> 
g++ -L/home/znyk/SFML-2.4.2/lib -o bin/Debug/testik obj/Debug/tescik.o   /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a /home/znyk/SFML-2.4.2/lib/libsfml-audio-s-d.a /home/znyk/SFML-2.4.2/lib/libsfml-network-s-d.a /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a /home/znyk/SFML-2.4.2/lib/libsfml-system-s-d.a
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(Color.cpp.o): relocation R_X86_64_32 against hidden symbol `_ZN2sf5Color5BlackE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(RenderStates.cpp.o): relocation R_X86_64_32 against hidden symbol `_ZN2sf12RenderStates7DefaultE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(RenderTarget.cpp.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(RenderWindow.cpp.o): relocation R_X86_64_32S against hidden symbol `_ZTVN2sf12RenderWindowE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(Shader.cpp.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(Texture.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(TextureSaver.cpp.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(Transform.cpp.o): relocation R_X86_64_32 against hidden symbol `_ZN2sf9Transform8IdentityE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(GLLoader.cpp.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(Shape.cpp.o): relocation R_X86_64_32S against hidden symbol `_ZTVN2sf5ShapeE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(CircleShape.cpp.o): relocation R_X86_64_32S against hidden symbol `_ZTVN2sf11CircleShapeE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(VertexArray.cpp.o): relocation R_X86_64_32S against hidden symbol `_ZTVN2sf11VertexArrayE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(BlendMode.cpp.o): relocation R_X86_64_32 against hidden symbol `_ZN2sf10BlendAlphaE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(GLCheck.cpp.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(GLExtensions.cpp.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(Image.cpp.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(ImageLoader.cpp.o): relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-graphics-s-d.a(Transformable.cpp.o): relocation R_X86_64_32S against hidden symbol `_ZTVN2sf13TransformableE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(Context.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(GlContext.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(GlResource.cpp.o): relocation R_X86_64_32 against symbol `[email protected]@CXXABI_1.3' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(VideoMode.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(Window.cpp.o): relocation R_X86_64_32S against hidden symbol `_ZTVN2sf6WindowE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(WindowImpl.cpp.o): relocation R_X86_64_32S against hidden symbol `_ZTVN2sf4priv10WindowImplE' can not be used when making a shared object
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(VideoModeImpl.cpp.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(WindowImplX11.cpp.o): relocation R_X86_64_32 against undefined symbol `__pthread_key_create' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(GlxContext.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(GlxExtensions.cpp.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(JoystickManager.cpp.o): relocation R_X86_64_32 against undefined symbol `__pthread_key_create' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(SensorManager.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(Display.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(JoystickImpl.cpp.o): relocation R_X86_64_32 against undefined symbol `__pthread_key_create' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-window-s-d.a(Joystick.cpp.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-system-s-d.a(Err.cpp.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-system-s-d.a(Lock.cpp.o): relocation R_X86_64_32 against symbol `[email protected]@CXXABI_1.3' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-system-s-d.a(Mutex.cpp.o): relocation R_X86_64_32 against symbol `[email protected]@CXXABI_1.3' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-system-s-d.a(String.cpp.o): relocation R_X86_64_32 against undefined symbol `__pthread_key_create' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-system-s-d.a(ThreadLocal.cpp.o): relocation R_X86_64_32 against symbol `[email protected]@CXXABI_1.3' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /home/znyk/SFML-2.4.2/lib/libsfml-system-s-d.a(Time.cpp.o): relocation R_X86_64_32 against hidden symbol `_ZN2sf4Time4ZeroE' can not be used when making a shared object
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
0

Jesteś w stanie modyfikować flagi kompilacji?
Dostajesz wyraźny komunikat: recompile with -fPIC /usr/bin/ld:, więc spróbuj tą flagę ustawić.

0

Są flagi kompilacji w Global compiler settings -> Compilers settings - >Complier flags, ale nie widzę nigdzie:

recompile with -fPIC /usr/bin/ld: ???

0


-------------- Build: Release in sfml (compiler: GNU GCC Compiler)---------------

g++ -Wall -fexceptions -O2 -DSFML_STATIC -I../../SFML-2.4.2/include -c /home/znyk/Pulpit/sfml/main.cpp -o obj/Release/main.o
g++ -L../../SFML-2.4.2/lib -o bin/Release/sfml obj/Release/main.o  -s  -lsfml-network -lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system
/usr/bin/ld: warning: libjpeg.so.8, needed by ../../SFML-2.4.2/lib/libsfml-graphics.so, not found (try using -rpath or -rpath-link)
../../SFML-2.4.2/lib/libsfml-graphics.so: undefined reference to `[email protected]_8.0'
../../SFML-2.4.2/lib/libsfml-graphics.so: undefined reference to `[email protected]_8.0'
../../SFML-2.4.2/lib/libsfml-graphics.so: undefined reference to `[email protected]_8.0'
../../SFML-2.4.2/lib/libsfml-graphics.so: undefined reference to `[email protected]_8.0'
../../SFML-2.4.2/lib/libsfml-graphics.so: undefined reference to `[email protected]_8.0'
../../SFML-2.4.2/lib/libsfml-graphics.so: undefined reference to `[email protected]_8.0'
../../SFML-2.4.2/lib/libsfml-graphics.so: undefined reference to `[email protected]_8.0'
../../SFML-2.4.2/lib/libsfml-graphics.so: undefined reference to `[email protected]_8.0'
../../SFML-2.4.2/lib/libsfml-graphics.so: undefined reference to `[email protected]_8.0'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 2 second(s))
10 error(s), 1 warning(s) (0 minute(s), 2 second(s))```

Co jest źle ?
0

Podstawowe pytanie: czy wersja twojego kompilatora jest zgodna z wersją kompilatora, którym została skompilowana biblioteka? Jeśli nie, to masz prawdopodobny powód tych problemów.

Ściągnij źródła SFML-a i skompiluj.

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0