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

Author Topic: i got errors at compilation  (Read 1481 times)

0 Members and 1 Guest are viewing this topic.

stupiddevil

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
i got errors at compilation
« on: November 03, 2023, 08:27:26 am »
I installed sfml in code bloks and tryed to run the program in the tutorial, it gives me a bounch of errors at compilation :
 ||=== Build: Debug in sfml (compiler: GNU GCC Compiler) ===|
obj\Debug\lucru.o||In function `main':|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|5|undefined reference to `__imp__ZN2sf6StringC1EPKcRKSt6locale'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|5|undefined reference to `__imp__ZN2sf9VideoModeC1Ejjj'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|5|undefined reference to `__imp__ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|6|undefined reference to `__imp__ZN2sf11CircleShapeC1Efy'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|7|undefined reference to `__imp__ZN2sf5Color5GreenE'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|7|undefined reference to `__imp__ZN2sf5Shape12setFillColorERKNS_5ColorE'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|9|undefined reference to `__imp__ZNK2sf10WindowBase6isOpenEv'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|12|undefined reference to `__imp__ZN2sf10WindowBase9pollEventERNS_5EventE'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|15|undefined reference to `__imp__ZN2sf6Window5closeEv'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|18|undefined reference to `__imp__ZN2sf5ColorC1Ehhhh'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|18|undefined reference to `__imp__ZN2sf12RenderTarget5clearERKNS_5ColorE'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|19|undefined reference to `__imp__ZN2sf12RenderStates7DefaultE'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|19|undefined reference to `__imp__ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|20|undefined reference to `__imp__ZN2sf6Window7displayEv'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|5|undefined reference to `__imp__ZN2sf12RenderWindowD1Ev'|
C:\Users\asus\Desktop\C++\sfml\lucru.cpp|5|undefined reference to `__imp__ZN2sf12RenderWindowD1Ev'|
obj\Debug\lucru.o||In function `sf::CircleShape::~CircleShape()':|
C:\Users\asus\Downloads\SFML-2.6.0-windows-vc17-32-bit (1)\SFML-2.6.0\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `__imp__ZTVN2sf11CircleShapeE'|
C:\Users\asus\Downloads\SFML-2.6.0-windows-vc17-32-bit (1)\SFML-2.6.0\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `__imp__ZTVN2sf11CircleShapeE'|
C:\Users\asus\Downloads\SFML-2.6.0-windows-vc17-32-bit (1)\SFML-2.6.0\include\SFML\Graphics\CircleShape.hpp|41|undefined reference to `__imp__ZN2sf5ShapeD2Ev'|
||error: ld returned 1 exit status|
||=== Build failed: 20 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

stupiddevil

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: i got errors at compilation
« Reply #1 on: November 03, 2023, 08:29:18 am »
this is the program :
#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;
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10936
    • View Profile
    • development blog
    • Email
Re: i got errors at compilation
« Reply #2 on: November 05, 2023, 04:45:49 pm »
Looks like you didn't link SFML
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

stupiddevil

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: i got errors at compilation
« Reply #3 on: November 06, 2023, 09:48:32 am »
I followed the steps of the tutorial can't figure out what went wrong

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10936
    • View Profile
    • development blog
    • Email
Re: i got errors at compilation
« Reply #4 on: November 06, 2023, 12:35:04 pm »
Are you trying to link SFML statically, but haven't set SFML_STATIC?

Can you provide your verbose build output: https://www.sfml-dev.org/faq.php#tr-grl-verbose-ide
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

stupiddevil

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: i got errors at compilation
« Reply #5 on: November 07, 2023, 12:48:53 pm »

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

g++.exe -L"C:\Users\asus\Downloads\SFML-2.6.0-windows-vc17-32-bit (1)\SFML-2.6.0\lib" -o bin\Debug\sfml.exe obj\Debug\lucru.o   "C:\Users\asus\Downloads\SFML-2.6.0-windows-vc17-32-bit (1)\SFML-2.6.0\lib\sfml-graphics.lib" "C:\Users\asus\Downloads\SFML-2.6.0-windows-vc17-32-bit (1)\SFML-2.6.0\lib\sfml-window.lib" "C:\Users\asus\Downloads\SFML-2.6.0-windows-vc17-32-bit (1)\SFML-2.6.0\lib\sfml-system.lib"
obj\Debug\lucru.o: In function `main':
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:5: undefined reference to `__imp__ZN2sf6StringC1EPKcRKSt6locale'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:5: undefined reference to `__imp__ZN2sf9VideoModeC1Ejjj'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:5: undefined reference to `__imp__ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:6: undefined reference to `__imp__ZN2sf11CircleShapeC1Efy'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:7: undefined reference to `__imp__ZN2sf5Color5GreenE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:7: undefined reference to `__imp__ZN2sf5Shape12setFillColorERKNS_5ColorE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:9: undefined reference to `__imp__ZNK2sf10WindowBase6isOpenEv'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:12: undefined reference to `__imp__ZN2sf10WindowBase9pollEventERNS_5EventE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:15: undefined reference to `__imp__ZN2sf6Window5closeEv'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:18: undefined reference to `__imp__ZN2sf5ColorC1Ehhhh'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:18: undefined reference to `__imp__ZN2sf12RenderTarget5clearERKNS_5ColorE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:19: undefined reference to `__imp__ZN2sf12RenderStates7DefaultE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:19: undefined reference to `__imp__ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:20: undefined reference to `__imp__ZN2sf6Window7displayEv'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:5: undefined reference to `__imp__ZN2sf12RenderWindowD1Ev'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:5: undefined reference to `__imp__ZN2sf12RenderWindowD1Ev'
obj\Debug\lucru.o: In function `sf::CircleShape::~CircleShape()':
C:/Users/asus/Downloads/SFML-2.6.0-windows-vc17-32-bit (1)/SFML-2.6.0/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `__imp__ZTVN2sf11CircleShapeE'
C:/Users/asus/Downloads/SFML-2.6.0-windows-vc17-32-bit (1)/SFML-2.6.0/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `__imp__ZTVN2sf11CircleShapeE'
C:/Users/asus/Downloads/SFML-2.6.0-windows-vc17-32-bit (1)/SFML-2.6.0/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `__imp__ZN2sf5ShapeD2Ev'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
20 error(s), 0 warning(s) (0 minute(s), 1 second(s))
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10936
    • View Profile
    • development blog
    • Email
Re: i got errors at compilation
« Reply #6 on: November 07, 2023, 01:03:24 pm »
You're trying to link Visual Studio library files (*.lib) while using GCC/MinGW. This won't work.

You have to use the MinGW package, and make sure your compiler aligns with the version linked on the SFML download page. It has to be 100% identical!

Alternatively, you can also use the SFML CMake Template, which automatically builds SFML, but you'd be using CMake.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

stupiddevil

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: i got errors at compilation
« Reply #7 on: November 07, 2023, 08:48:09 pm »
Thank you for your help. It seems Mingw pakage is for 64 bits arhitecture CMake is also for 64 bits. Im on win32. Ill try to solve the prroblem, again thx for help

stupiddevil

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: i got errors at compilation
« Reply #8 on: November 07, 2023, 08:56:59 pm »
oh my bad there is a win32 version for mingw !

stupiddevil

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: i got errors at compilation
« Reply #9 on: November 07, 2023, 09:55:28 pm »
I linked libraries as stated in the tutorial (lib prefix and .a extensions omited) and this is what i got :

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

g++.exe -LC:\Users\asus\Documents\SFML\SFML-2.6.1\lib -o bin\Debug\sfml.exe obj\Debug\lucru.o   C:\Users\asus\Documents\SFML\SFML-2.6.1\lib\sfml-graphics C:\Users\asus\Documents\SFML\SFML-2.6.1\lib\sfml-window C:\Users\asus\Documents\SFML\SFML-2.6.1\lib\sfml-system
g++.exe: error: C:\Users\asus\Documents\SFML\SFML-2.6.1\lib\sfml-graphics: No such file or directory
g++.exe: error: C:\Users\asus\Documents\SFML\SFML-2.6.1\lib\sfml-window: No such file or directory
g++.exe: error: C:\Users\asus\Documents\SFML\SFML-2.6.1\lib\sfml-system: No such file or directory
Process terminated with status 1 (0 minute(s), 0 second(s))
3 error(s), 0 warning(s) (0 minute(s), 0 second(s))

if i put the prefix and the .a extensions i got this :


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

g++.exe -LC:\Users\asus\Documents\SFML\SFML-2.6.1\lib -o bin\Debug\sfml.exe obj\Debug\lucru.o   C:\Users\asus\Documents\SFML\SFML-2.6.1\lib\libsfml-graphics.a C:\Users\asus\Documents\SFML\SFML-2.6.1\lib\libsfml-window.a C:\Users\asus\Documents\SFML\SFML-2.6.1\lib\libsfml-system.a
obj\Debug\lucru.o: In function `main':
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:5: undefined reference to `__imp__ZN2sf6StringC1EPKcRKSt6locale'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:5: undefined reference to `__imp__ZN2sf9VideoModeC1Ejjj'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:5: undefined reference to `__imp__ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:6: undefined reference to `__imp__ZN2sf11CircleShapeC1Efy'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:7: undefined reference to `__imp__ZN2sf5Color5GreenE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:7: undefined reference to `__imp__ZN2sf5Shape12setFillColorERKNS_5ColorE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:9: undefined reference to `__imp__ZNK2sf10WindowBase6isOpenEv'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:12: undefined reference to `__imp__ZN2sf10WindowBase9pollEventERNS_5EventE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:15: undefined reference to `__imp__ZN2sf6Window5closeEv'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:18: undefined reference to `__imp__ZN2sf5ColorC1Ehhhh'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:18: undefined reference to `__imp__ZN2sf12RenderTarget5clearERKNS_5ColorE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:19: undefined reference to `__imp__ZN2sf12RenderStates7DefaultE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:19: undefined reference to `__imp__ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:20: undefined reference to `__imp__ZN2sf6Window7displayEv'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:5: undefined reference to `__imp__ZN2sf12RenderWindowD1Ev'
C:/Users/asus/Desktop/C++/sfml/lucru.cpp:5: undefined reference to `__imp__ZN2sf12RenderWindowD1Ev'
obj\Debug\lucru.o: In function `sf::CircleShape::~CircleShape()':
C:/Users/asus/Downloads/SFML-2.6.0-windows-vc17-32-bit (1)/SFML-2.6.0/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `__imp__ZTVN2sf11CircleShapeE'
C:/Users/asus/Downloads/SFML-2.6.0-windows-vc17-32-bit (1)/SFML-2.6.0/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `__imp__ZTVN2sf11CircleShapeE'
C:/Users/asus/Downloads/SFML-2.6.0-windows-vc17-32-bit (1)/SFML-2.6.0/include/SFML/Graphics/CircleShape.hpp:41: undefined reference to `__imp__ZN2sf5ShapeD2Ev'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
20 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 

 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10936
    • View Profile
    • development blog
    • Email
Re: i got errors at compilation
« Reply #10 on: November 07, 2023, 11:10:43 pm »
You're not actually linking the libraries, you're just listing them. You need to specify the -l (lower case L) followed by the library you want to link. And since you specify the library path with -L already, you can also drop the path, the prefix and suffix.

-lsfml-graphics -lsfml-window -lsfml-system

If you use Code::Blocks, see the tutorial on where to specify the libraries: https://www.sfml-dev.org/tutorials/2.6/start-cb.php
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/