Trying to compile my silly hello-world SFML project for test. But getting strange error messages from linker. (When I compile with shared lib's - everything is OK.)
g++ -DSFML_STATIC -O2 -no-pie -fno-pie -o main main.cpp -L/home/uzzer/LIB/SFML-2.5.1/lib -lstdc++ -lc -lm -ldl -lX11 -lGL -lGLU -lsfml-system-s -lsfml-graphics-s -lsfml-window-s
Error messages:
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(RenderTarget.cpp.o): in function `(anonymous namespace)::equationToGlConstant(sf::BlendMode::Equation) [clone .part.0]':
RenderTarget.cpp:(.text+0x8): undefined reference to `sf::err()'
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(RenderTarget.cpp.o): in function `(anonymous namespace)::factorToGlConstant(sf::BlendMode::Factor) [clone .part.0]':
RenderTarget.cpp:(.text+0xa8): undefined reference to `sf::err()'
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(RenderTarget.cpp.o): in function `sf::RenderTarget::clear(sf::Color const&)':
RenderTarget.cpp:(.text+0x2c9): undefined reference to `glClearColor'
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(RenderTarget.cpp.o): in function `sf::RenderTarget::popGLStates()':
RenderTarget.cpp:(.text+0x854): undefined reference to `glMatrixMode'
/usr/bin/ld: RenderTarget.cpp:(.text+0x859): undefined reference to `glPopMatrix'
/usr/bin/ld: RenderTarget.cpp:(.text+0x863): undefined reference to `glMatrixMode'
/usr/bin/ld: RenderTarget.cpp:(.text+0x868): undefined reference to `glPopMatrix'
/usr/bin/ld: RenderTarget.cpp:(.text+0x872): undefined reference to `glMatrixMode'
/usr/bin/ld: RenderTarget.cpp:(.text+0x877): undefined reference to `glPopMatrix'
/usr/bin/ld: RenderTarget.cpp:(.text+0x87c): undefined reference to `glPopClientAttrib'
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(RenderTarget.cpp.o): in function `sf::RenderTarget::initialize()':
RenderTarget.cpp:(.text+0x9c3): undefined reference to `sf::Lock::Lock(sf::Mutex&)'
/usr/bin/ld: RenderTarget.cpp:(.text+0x9de): undefined reference to `sf::Lock::~Lock()'
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(RenderTarget.cpp.o): in function `sf::RenderTarget::applyCurrentView()':
RenderTarget.cpp:(.text+0xa60): undefined reference to `glViewport'
/usr/bin/ld: RenderTarget.cpp:(.text+0xa6a): undefined reference to `glMatrixMode'
/usr/bin/ld: RenderTarget.cpp:(.text+0xa82): undefined reference to `glLoadMatrixf'
/usr/bin/ld: RenderTarget.cpp:(.text+0xa8c): undefined reference to `glMatrixMode'
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(RenderTarget.cpp.o): in function `sf::RenderTarget::applyBlendMode(sf::BlendMode const&)':
RenderTarget.cpp:(.text+0xbb0): undefined reference to `glBlendFunc'
/usr/bin/ld: RenderTarget.cpp:(.text+0xc19): undefined reference to `sf::err()'
/usr/bin/ld: RenderTarget.cpp:(.text+0xc6e): undefined reference to `sf::err()'
/usr/bin/ld: RenderTarget.cpp:(.text+0xcc3): undefined reference to `sf::err()'
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(RenderTarget.cpp.o): in function `sf::RenderTarget::resetGLStates()':
RenderTarget.cpp:(.text+0xf80): undefined reference to `glDisable'
/usr/bin/ld: RenderTarget.cpp:(.text+0xf8a): undefined reference to `glDisable'
/usr/bin/ld: RenderTarget.cpp:(.text+0xf94): undefined reference to `glDisable'
/usr/bin/ld: RenderTarget.cpp:(.text+0xf9e): undefined reference to `glDisable'
/usr/bin/ld: RenderTarget.cpp:(.text+0xfa8): undefined reference to `glEnable'
/usr/bin/ld: RenderTarget.cpp:(.text+0xfb2): undefined reference to `glEnable'
/usr/bin/ld: RenderTarget.cpp:(.text+0xfbc): undefined reference to `glMatrixMode'
/usr/bin/ld: RenderTarget.cpp:(.text+0xfc1): undefined reference to `glLoadIdentity'
/usr/bin/ld: RenderTarget.cpp:(.text+0xfcb): undefined reference to `glEnableClientState'
/usr/bin/ld: RenderTarget.cpp:(.text+0xfd5): undefined reference to `glEnableClientState'
/usr/bin/ld: RenderTarget.cpp:(.text+0xfdf): undefined reference to `glEnableClientState'
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(RenderTarget.cpp.o): in function `sf::RenderTarget::pushGLStates()':
RenderTarget.cpp:(.text+0x1104): undefined reference to `glPushClientAttrib'
/usr/bin/ld: RenderTarget.cpp:(.text+0x110e): undefined reference to `glPushAttrib'
/usr/bin/ld: RenderTarget.cpp:(.text+0x1118): undefined reference to `glMatrixMode'
/usr/bin/ld: RenderTarget.cpp:(.text+0x111d): undefined reference to `glPushMatrix'
/usr/bin/ld: RenderTarget.cpp:(.text+0x1127): undefined reference to `glMatrixMode'
/usr/bin/ld: RenderTarget.cpp:(.text+0x112c): undefined reference to `glPushMatrix'
/usr/bin/ld: RenderTarget.cpp:(.text+0x1136): undefined reference to `glMatrixMode'
/usr/bin/ld: RenderTarget.cpp:(.text+0x113b): undefined reference to `glPushMatrix'
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(RenderTarget.cpp.o): in function `sf::RenderTarget::setupDraw(bool, sf::RenderStates const&)':
.............etc
/usr/bin/ld: GLExtensions.cpp:(.text+0xa1): undefined reference to `sf::err()'
/usr/bin/ld: GLExtensions.cpp:(.text+0xf8): undefined reference to `sf::err()'
/usr/bin/ld: GLExtensions.cpp:(.text+0x15e): undefined reference to `glGetString'
/usr/bin/ld: /home/uzzer/LIB/SFML-2.5.1/lib/libsfml-graphics-s.a(Image.cpp.o): in function `sf::Image::getPixelsPtr() const':
Image.cpp:(.text+0x778): undefined reference to `sf::err()'
collect2: error: ld returned 1 exit status
gcc version 10.2.0 (Ubuntu 10.2.0-13ubuntu1).
$g++ -v -print-search-dirs
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
install: /usr/lib/gcc/x86_64-linux-gnu/10/
programs: =/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/bin/
libraries: =/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib/:/lib/x86_64-linux-gnu/10/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/10/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../:/lib/:/usr/lib/
What am I doing wrong / stupid?
The order of libraries on the command line is important - this means that a library containing the definition of a function should appear after any source files or object files which use it. Please see here for more information. Also the comment of @SeanFrancisNBallais is exactly about that.
In your case you need to place the sfml-system-s library after all other SFML libraries, something like below:
g++ <...other options...> -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lGLU -lGL -lX11 -ludev -lpthread
Also, from this line you can see that the GL library uses the X11 library (not vise versa) and so on. Some basic GCC libraries, such as stdc++ or m, aren't to be present on the command line - they are here by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With