对 _imp_sfBlendAlpha 的未定义引用

undefined reference to _imp_sfBlendAlpha

我最近在笔记本电脑上安装了 MinGW 和 CSFML,我 运行:

gcc shaders.c -csfml-system -csfml-graphics

我得到一个错误:

...\ccV1NsAK.o:shaders.c:(.text+0x247):' undefined reference to _imp__sfBlendAlpha'

我该如何解决这个问题?
亲切的问候, 波士顿布鲁克斯。


更新 1
我试过安装到不同的搜索路径,但我无法让它工作。我重新安装了 MinGW,并将 CSFML 包中的文件粘贴到默认路径。现在我得到:

gcc shaders.c -lcsfml-system -lcsfml-window -lcsfml-graphics
C:\Users\bbroo\AppData\Local\Temp\cc9QM4Nx.o:shaders.c:(.text+0x2d8): undefined reference to '_imp__sfBlendAlpha'
C:\Users\bbroo\AppData\Local\Temp\cc9QM4Nx.o:shaders.c:(.text+0x318): undefined reference to '_imp__sfTransform_Identity'
collect2.exe: error: ld returned 1 exit status

更新 2
我将 CSFML 复制到我的主文件夹。我得到:

$ gcc -B ~/CSFML -Ld: ~/CSFML shaders.c  -lcsfml-system -lcsfml-window -lcsfml-graphics
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find C:/MinGW/msys/1.0/home/bbroo/CSFML: Permission denied
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lcsfml-system
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lcsfml-window
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lcsfml-graphics
collect2.exe: error: ld returned 1 exit status

可以访问头文件,但 dot-a 文件是 'permission denied' 如何使用 MSYS 为所有用户设置对 CSFML 中所有文件的读写执行权限?

如果我使用 C:\SFML 也会出现同样的问题


更新 3
当我将文件解压到默认路径时,在我的.a文件所在的文件夹中生成了一个子文件夹。它包含几个点-a 文件和一个自述文本文件。

此 README 文件已复制到 GCC-only 头文件的目录中 当 fixincludes 被 GCC 的 makefile 运行 时:

Many of the files in this directory were automatically edited from the standard system header files by the fixincludes process. They are system-specific, and will not work on any other kind of system. They are also not part of GCC. The reason we have to do this is because GCC requires ANSI C headers and many vendors supply ANSI-incompatible headers.

Because this is an automated process, sometimes headers get "fixed" that do not, strictly speaking, need a fix. As long as nothing is broken by the process, it is just an unfortunate collateral inconvenience. We would like to rectify it, if it is not "too inconvenient".


更新 4
在没有链接的情况下编译工作正常但单独链接不起作用:

bbroo@DESKTOP-1F1J3SM ~/Shaders
$ ld shaders.o libcsfml-system.a libcsfml-window.a libcsfml-graphics.a
shaders.o:shaders.c:(.text+0x10): undefined reference to `__main'
shaders.o:shaders.c:(.text+0x2d8): undefined reference to `_imp__sfBlendAlpha'
shaders.o:shaders.c:(.text+0x318): undefined reference to `_imp__sfTransform_Identity'
shaders.o:shaders.c:(.text+0x4bc): undefined reference to `sleep'

更新 5
现在我得到:

bbroo@DESKTOP-1F1J3SM ~/Shaders
$ ld shaders.o libcsfml-system.a libcsfml-window.a libcsfml-graphics.a csfml-system-2.dll csfml-window-2.dll csfml-graphics-2.dll
shaders.o:shaders.c:(.text+0x10): undefined reference to `__main'
shaders.o:shaders.c:(.text+0x4bc): undefined reference to `sleep'

这似乎是一个链接错误。您可能在链接 SFML 库时犯了错误。每个 IDE.

的链接库可能不同

按照教程设置与您的IDE相匹配的 SFML 库。

在你的编译命令中: gcc shaders.c -csfml-system -csfml-grphics

你可能写错了(即-csfml-graphics)没有?

这里有教程:https://www.sfml-dev.org/tutorials/2.4/start-cb.php

在链接器部分截图下,教程提到了 3 个需要链接的库,它们将转换为您需要在链接阶段添加的命令行参数:

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

您可能还需要告诉链接器在哪里可以找到库,您需要将这些库调整到它们在您机器上的位置,例如

-Ld:\smfl-2.0\lib

gcc shaders.c libcsfml-system.a libcsfml-window.a libcsfml-graphics.a csfml-system-2.dll csfml-window-2.dll csfml-graphics-2.dll

对我有用。