Reputation: 604
I have written a basic CSFML program to try to learn CSFML. When I try to compile it, I get a linker error. I can't figure out why this is happening. The program, compile command, and output of compiler are all below. I am on a rather clean copy of 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;
}
Compiled Using:
gcc -o test test.c
Output of 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
Upvotes: 1
Views: 1871
Reputation: 2902
Per @NominalAnimal's comment:
Use gcc -Wall -O2 test.c -lcsfml-graphics -lcsfml-window -o test
to compile the program.
The -lcsfml-graphics
tells the compiler to link the executable with the csfml-graphics library ("libcsfml-graphics.so" or "libcsfml-graphics.a" on Linux), and -lcsfml-window
similarly with the csfml-window library.
(Note: l is "the letter ell", not "digit one", here.)
Upvotes: 5