Hello! This is my first time posting here and I'm a new to sfml, so I have a feeling that this might be something easy to fix... hopefully. FYI, my machine is a 2020 MacBook Air M1 running Monterey 12.0.1.
I've been having a ton of trouble getting this simple C++ sfml program to compile using vim and command line only:
//file: main.cpp
1 #include <SFML/Graphics.hpp>
2
3 int main()
4 {
5 sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
6 sf::CircleShape shape(100.f);
7 shape.setFillColor(sf::Color::Green);
8
9 while (window.isOpen())
10 {
11 sf::Event event;
12 while (window.pollEvent(event))
13 {
14 if (event.type == sf::Event::Closed)
15 window.close();
16 }
17
18 window.clear();
19 window.draw(shape);
20 window.display();
21 }
22
23 return 0;
24 }
I downloaded sfml via homebrew and have verified that all the dynamic libraries are arm64:
libsfml-audio.2.5.1.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-audio.2.5.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-audio.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-graphics.2.5.1.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-graphics.2.5.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-graphics.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-network.2.5.1.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-network.2.5.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-network.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-system.2.5.1.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-system.2.5.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-system.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-window.2.5.1.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-window.2.5.dylib: Mach-O 64-bit dynamically linked shared library arm64
libsfml-window.dylib: Mach-O 64-bit dynamically linked shared library arm64
This is the command I use to compile with:
g++ main.cpp -I//opt/homebrew/Cellar/sfml/2.5.1_1/include -o sfml_test -L/opt/homebrew/Cellar/sfml/2.5.1_1/lib -lsfml-graphics -lsfml-window -lsfml-system
And these are the linker errors I receive upon compilation:
ld: warning: dylib (/opt/homebrew/Cellar/sfml/2.5.1_1/lib/libsfml-graphics.dylib) was built for newer macOS version (12.0) than being linked (11.0)
ld: warning: dylib (/opt/homebrew/Cellar/sfml/2.5.1_1/lib/libsfml-window.dylib) was built for newer macOS version (12.0) than being linked (11.0)
ld: warning: dylib (/opt/homebrew/Cellar/sfml/2.5.1_1/lib/libsfml-system.dylib) was built for newer macOS version (12.0) than being linked (11.0)
ld: warning: dylib (/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/libstdc++.dylib) was built for newer macOS version (11.4) than being linked (11.0)
Undefined symbols for architecture arm64:
"__ZN2sf6StringC1EPKcRKSt6locale", referenced from:
_main in cctjIkFF.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
Where am I going wrong here?
I'm confused why the errors are referencing "was built for newer macOS version (12.0) than being linked (11.0)". I don't really understand what that means. What are these dynamic libraries being linked to and why is it an older version? My OS is up-to-date.
Also, I confirmed that all of the dynamic library binaries are for arm 64, so I'm wondering why this error pops up: "ld: symbol(s) not found for architecture arm64".
Any insights or help would be much appreciated!
UPDATE: I just learned about the -v option for g++ and have included the output incase it might contain any useful information that I'm overlooking.
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/11.2.0/libexec/gcc/aarch64-apple-darwin20/11.1.0/lto-wrapper
Target: aarch64-apple-darwin20
Configured with: ../configure --prefix=/opt/homebrew/Cellar/gcc/11.2.0 --libdir=/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-11 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 11.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --build=aarch64-apple-darwin20 --with-system-zlib --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (Homebrew GCC 11.2.0)
COLLECT_GCC_OPTIONS='-I' '//opt/homebrew/Cellar/sfml/2.5.1_1/include' '-o' 'sfml_test' '-L/opt/homebrew/Cellar/sfml/2.5.1_1/lib' '-v' '-mmacosx-version-min=11.0.0' '-asm_macosx_version_min=11.0' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'sfml_test-'
/opt/homebrew/Cellar/gcc/11.2.0/libexec/gcc/aarch64-apple-darwin20/11.1.0/cc1plus -quiet -v -I //opt/homebrew/Cellar/sfml/2.5.1_1/include -D__DYNAMIC__ main.cpp -fPIC -quiet -dumpdir sfml_test- -dumpbase main.cpp -dumpbase-ext .cpp -mmacosx-version-min=11.0.0 -mlittle-endian -mabi=lp64 -version -o /var/folders/0d/24cnz0cn4dx14nc3qswtvz0h0000gn/T//cc6caKt7.s
GNU C++17 (Homebrew GCC 11.2.0) version 11.1.0 (aarch64-apple-darwin20)
compiled by GNU C version 11.1.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/../../../../../../aarch64-apple-darwin20/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
//opt/homebrew/Cellar/sfml/2.5.1_1/include
/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/../../../../../../include/c++/11.1.0
/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/../../../../../../include/c++/11.1.0/aarch64-apple-darwin20
/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/../../../../../../include/c++/11.1.0/backward
/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/include
/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/include-fixed
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks
End of search list.
GNU C++17 (Homebrew GCC 11.2.0) version 11.1.0 (aarch64-apple-darwin20)
compiled by GNU C version 11.1.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 8c4dfc26dbd0a1c1a63f0177bfaeaead
COLLECT_GCC_OPTIONS='-I' '//opt/homebrew/Cellar/sfml/2.5.1_1/include' '-o' 'sfml_test' '-L/opt/homebrew/Cellar/sfml/2.5.1_1/lib' '-v' '-mmacosx-version-min=11.0.0' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'sfml_test-'
as -arch arm64 -v -I //opt/homebrew/Cellar/sfml/2.5.1_1/include -mmacosx-version-min=11.0 -o /var/folders/0d/24cnz0cn4dx14nc3qswtvz0h0000gn/T//ccHtpgwP.o /var/folders/0d/24cnz0cn4dx14nc3qswtvz0h0000gn/T//cc6caKt7.s
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: arm64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1as -triple arm64-apple-macosx11.0.0 -filetype obj -main-file-name cc6caKt7.s -target-cpu apple-m1 -target-feature +v8.5a -target-feature +fp-armv8 -target-feature +neon -target-feature +crc -target-feature +crypto -target-feature +dotprod -target-feature +fp16fml -target-feature +ras -target-feature +lse -target-feature +rdm -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sm4 -target-feature +sha3 -target-feature +sha2 -target-feature +aes -I //opt/homebrew/Cellar/sfml/2.5.1_1/include -fdebug-compilation-dir /Users/stu/scratch -dwarf-debug-producer "Apple clang version 13.0.0 (clang-1300.0.29.3)" -I //opt/homebrew/Cellar/sfml/2.5.1_1/include -dwarf-version=4 -mrelocation-model pic --mrelax-relocations -mllvm -disable-aligned-alloc-awareness=1 -mllvm -enable-dse-memoryssa=0 -o /var/folders/0d/24cnz0cn4dx14nc3qswtvz0h0000gn/T//ccHtpgwP.o /var/folders/0d/24cnz0cn4dx14nc3qswtvz0h0000gn/T//cc6caKt7.s
COMPILER_PATH=/opt/homebrew/Cellar/gcc/11.2.0/libexec/gcc/aarch64-apple-darwin20/11.1.0/:/opt/homebrew/Cellar/gcc/11.2.0/libexec/gcc/aarch64-apple-darwin20/11.1.0/:/opt/homebrew/Cellar/gcc/11.2.0/libexec/gcc/aarch64-apple-darwin20/:/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/:/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/
LIBRARY_PATH=/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/:/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/../../../
COLLECT_GCC_OPTIONS='-I' '//opt/homebrew/Cellar/sfml/2.5.1_1/include' '-o' 'sfml_test' '-L/opt/homebrew/Cellar/sfml/2.5.1_1/lib' '-v' '-mmacosx-version-min=11.0.0' '-mlittle-endian' '-mabi=lp64' '-dumpdir' 'sfml_test.'
/opt/homebrew/Cellar/gcc/11.2.0/libexec/gcc/aarch64-apple-darwin20/11.1.0/collect2 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ -dynamic -arch arm64 -macosx_version_min 11.0.0 -weak_reference_mismatches non-weak -o sfml_test -L/opt/homebrew/Cellar/sfml/2.5.1_1/lib -L/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0 -L/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/../../.. /var/folders/0d/24cnz0cn4dx14nc3qswtvz0h0000gn/T//ccHtpgwP.o -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ -lgcc_s.1.1 -lgcc -lSystem -lgcc -no_compact_unwind -rpath @loader_path -rpath /opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0 -rpath /opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/../../.. -v
collect2 version 11.1.0
/usr/bin/ld -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ -dynamic -arch arm64 -macosx_version_min 11.0.0 -weak_reference_mismatches non-weak -o sfml_test -L/opt/homebrew/Cellar/sfml/2.5.1_1/lib -L/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0 -L/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/../../.. /var/folders/0d/24cnz0cn4dx14nc3qswtvz0h0000gn/T//ccHtpgwP.o -lsfml-graphics -lsfml-window -lsfml-system -lstdc++ -lgcc_s.1.1 -lgcc -lSystem -lgcc -no_compact_unwind -rpath @loader_path -rpath /opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0 -rpath /opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0/../../.. -v
@(#)PROGRAM:ld PROJECT:ld64-711
BUILD 18:11:19 Aug 3 2021
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
/opt/homebrew/Cellar/sfml/2.5.1_1/lib
/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/gcc/aarch64-apple-darwin20/11.1.0
/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
Framework search paths:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/
ld: warning: dylib (/opt/homebrew/Cellar/sfml/2.5.1_1/lib/libsfml-graphics.dylib) was built for newer macOS version (12.0) than being linked (11.0)
ld: warning: dylib (/opt/homebrew/Cellar/sfml/2.5.1_1/lib/libsfml-window.dylib) was built for newer macOS version (12.0) than being linked (11.0)
ld: warning: dylib (/opt/homebrew/Cellar/sfml/2.5.1_1/lib/libsfml-system.dylib) was built for newer macOS version (12.0) than being linked (11.0)
ld: warning: dylib (/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11/libstdc++.dylib) was built for newer macOS version (11.4) than being linked (11.0)
Undefined symbols for architecture arm64:
"__ZN2sf6StringC1EPKcRKSt6locale", referenced from:
_main in ccHtpgwP.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status