我已经编写了一个基本的CSFML程序来尝试学习CSFML。当我尝试编译它时,我收到链接器错误。我无法弄清楚为什么会这样。程序,编译命令和编译器的输出都在下面。我是一个相当干净的ubuntu副本。
test.c的:
#include <SFML/Window.h>
#include <SFML/Graphics.h>
int main(){
sfVideoMode mode = {800,600,32};
sfRenderWindow *window = sfRenderWindow_create(mode,"Hello, CSFML", sfResize | sfClose, NULL);
sfRectangleShape *shape = sfRectangleShape_create();
sfRectangleShape_setFillColor(shape,sfWhite);
while(sfRenderWindow_isOpen(window)){
sfEvent event;
while(sfRenderWindow_pollEvent(window,&event)){
if(event.type == sfEvtClosed){
sfRenderWindow_close(window);
}
}
sfRenderWindow_clear(window,sfBlack);
sfRenderWindow_drawRectangleShape(window,shape,NULL);
sfRenderWindow_display(window);
}
return 0;
}
编译使用:
gcc -o test test.c
输出gcc:
/tmp/ccFCNmd7.o: In function `main':
csfmlTest.c:(.text+0x4b): undefined reference to `sfRenderWindow_create'
csfmlTest.c:(.text+0x54): undefined reference to `sfRectangleShape_create'
csfmlTest.c:(.text+0x5e): undefined reference to `sfWhite'
csfmlTest.c:(.text+0x6c): undefined reference to
`sfRectangleShape_setFillColor'
csfmlTest.c:(.text+0x81): undefined reference to `sfRenderWindow_close'
csfmlTest.c:(.text+0x94): undefined reference to `sfRenderWindow_pollEvent'
csfmlTest.c:(.text+0x9e): undefined reference to `sfBlack'
csfmlTest.c:(.text+0xac): undefined reference to `sfRenderWindow_clear'
csfmlTest.c:(.text+0xc4): undefined reference to
`sfRenderWindow_drawRectangleShape'
csfmlTest.c:(.text+0xd0): undefined reference to `sfRenderWindow_display'
csfmlTest.c:(.text+0xdc): undefined reference to `sfRenderWindow_isOpen'
collect2: error: ld returned 1 exit status
答案 0 :(得分:0)
Per @ NominalAnimal的评论:
使用gcc -Wall -O2 test.c -lcsfml-graphics -lcsfml-window -o test
编译程序。
-lcsfml-graphics
告诉编译器将可执行文件与csfml-graphics库(Linux上的“libcsfml-graphics.so”或“libcsfml-graphics.a”)链接,-lcsfml-window
与GROUP BY Date
类似。 csfml-window库。
(注意:l是“字母”,而不是“数字一”,这里。)