通过终端使用 g++ 编译器编译 SFML
compiling SFML with g++ compiler through the terminal
这是我在终端中输入的内容:
g++ -g -I/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/include -L/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/lib -l libsfml-graphics.2.4.2.dylib -lsfml-window-d -lsfml-system-d virtual_field.cpp -o virtual_field
我遇到了这个问题,因为它告诉我它找不到包含的库。
ld: library not found for -llibsfml-graphics.2.4.2.dylib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
如果您需要更多上下文,请看这里:
Carloss-MacBook-Pro:src cjm10000$ g++ -g -I/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/include -L/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/lib -l libsfml-graphics.2.4.2.dylib -lsfml-window-d -lsfml-system-d virtual_field.cpp -o virtual_field
ld: library not found for -llibsfml-graphics.2.4.2.dylib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
不太确定而且我没有 Mac,所以我无法真正测试它,但我认为您可以删除 dylib 文件结尾和前面的 lib,然后就可以了在 -l 之后使用它,就像您使用其他的一样。
大致如下:
g++ -g -I/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/include -L/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/lib -lsfml-graphics -lsfml-window-d -lsfml-system-d virtual_field.cpp -o virtual_field
编辑
我在手册页上查找了 ld
的部分,它进行了实际的链接,上面写着:
-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If
namespec is of the form :filename, ld will search the library path for
a file called filename, otherwise it will search the library path for
a file called libnamespec.a.
On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS
systems, ld will search a directory for a library called
libnamespec.so before searching for one called libnamespec.a. (By
convention, a ".so" extension indicates a shared library.) Note that
this behavior does not apply to :filename, which always specifies a
file called filename.
所以您似乎可以使用 -l:libsfml-graphics.2.4.2.dylib
格式。请注意,这是来自 GNU/linux 系统上 ld 运行 的手册页,因此他们没有提及 dylib,因为它似乎是 Mac 特定的文件格式。
这是我在终端中输入的内容:
g++ -g -I/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/include -L/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/lib -l libsfml-graphics.2.4.2.dylib -lsfml-window-d -lsfml-system-d virtual_field.cpp -o virtual_field
我遇到了这个问题,因为它告诉我它找不到包含的库。
ld: library not found for -llibsfml-graphics.2.4.2.dylib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
如果您需要更多上下文,请看这里:
Carloss-MacBook-Pro:src cjm10000$ g++ -g -I/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/include -L/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/lib -l libsfml-graphics.2.4.2.dylib -lsfml-window-d -lsfml-system-d virtual_field.cpp -o virtual_field
ld: library not found for -llibsfml-graphics.2.4.2.dylib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
不太确定而且我没有 Mac,所以我无法真正测试它,但我认为您可以删除 dylib 文件结尾和前面的 lib,然后就可以了在 -l 之后使用它,就像您使用其他的一样。
大致如下:
g++ -g -I/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/include -L/Users/cjm10000/Desktop/7701X/code/include/SFML-2.4.2-osx-clang/lib -lsfml-graphics -lsfml-window-d -lsfml-system-d virtual_field.cpp -o virtual_field
编辑
我在手册页上查找了 ld
的部分,它进行了实际的链接,上面写着:
-l namespec
--library=namespecAdd the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.
On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS systems, ld will search a directory for a library called libnamespec.so before searching for one called libnamespec.a. (By convention, a ".so" extension indicates a shared library.) Note that this behavior does not apply to :filename, which always specifies a file called filename.
所以您似乎可以使用 -l:libsfml-graphics.2.4.2.dylib
格式。请注意,这是来自 GNU/linux 系统上 ld 运行 的手册页,因此他们没有提及 dylib,因为它似乎是 Mac 特定的文件格式。