SFML community forums

Bindings - other languages => C => Topic started by: darekg11 on September 19, 2010, 07:56:52 pm

Title: Can't compile sample code
Post by: darekg11 on September 19, 2010, 07:56:52 pm
Hello, I just downloaded SFML library, I placed lib and includes in right directories and when I try to compile sample source I get this:

c:\documents and settings\darek\moje dokumenty\visual studio 2008\projects\test\test\main.cpp(31) : error C3861: 'sfFont_CreateFromFile': identifier not found
c:\documents and settings\darek\moje dokumenty\visual studio 2008\projects\test\test\main.cpp(74) : error C3861: 'sfFont_Destroy': identifier not found

Anyway help really appreicate.

EDIT: When I include:
#include <SFML/Graphics/Font.h>

I get a wall of external linker errors.

Please help I would really like to solve this and start some coding, I also searched forum but couldn't find anything helpful.
Title: Can't compile sample code
Post by: Laurent on September 19, 2010, 09:59:25 pm
Quote
I get a wall of external linker errors.

Do you link to csfml-graphics?
Title: Can't compile sample code
Post by: darekg11 on September 20, 2010, 07:28:53 am
When I add to Additional Dependies or whatever a name:
csfml-graphics without extensions I get one error:
LINK : fatal error LNK1104: cannot open file 'csfml-graphics.obj'
When I add csfml-graphics.lib I get the same wall of errors.
Title: Can't compile sample code
Post by: Laurent on September 20, 2010, 08:01:13 am
Quote
When I add csfml-graphics.lib I get the same wall of errors.

Did you tell your compiler where the csfml-xxx.lib files are located, so that it can find them?
Title: Can't compile sample code
Post by: darekg11 on September 20, 2010, 08:10:05 am
I putted all lib's to VC/Lib folder I also putted it in options of linker.


Okay, I will tell what I have done from the begging.
First I downloaded full SDK for C 1.6v.
I copied SFML folder from include folder to VC/include.
I copied all libs from library folder to VC/lib

I tried to compile that sample code from documentation but I can't because of this two errors:
c:\documents and settings\darek\moje dokumenty\visual studio 2008\projects\test\test\main.cpp(31) : error C3861: 'sfFont_CreateFromFile': identifier not found
c:\documents and settings\darek\moje dokumenty\visual studio 2008\projects\test\test\main.cpp(74) : error C3861: 'sfFont_Destroy': identifier not found

Thanks for spending Your time to help me.
Title: Can't compile sample code
Post by: Laurent on September 20, 2010, 08:43:19 am
You must include the corresponding headers, like you did in your first post.
Title: Can't compile sample code
Post by: darekg11 on September 20, 2010, 12:29:50 pm
I included Fonts/h like in my first post and now I also putted csfml-graphics.lib in Additional Dependieces and I still got that wall of errors.

Sorry for all this trouble but I would really like to use Your library since it's perfect for my project.
Title: Can't compile sample code
Post by: Laurent on September 20, 2010, 12:32:09 pm
Quote
and I still got that wall of errors

Which ones?
Title: Can't compile sample code
Post by: darekg11 on September 20, 2010, 01:35:37 pm
I will show You screenshots.
Include section:
(http://img828.imageshack.us/img828/7272/kod.png)
Additional:
(http://img718.imageshack.us/img718/8083/additional.jpg)
Preprocessor:
(http://img443.imageshack.us/img443/3593/preprocessor.jpg)
Errors:
(http://img201.imageshack.us/img201/3396/errorzk.jpg)


That's how it looks, anyway if You have any better thing to do than trying to solve it out then just leave this topic and I will try to handle it by my own.
Title: Can't compile sample code
Post by: Laurent on September 20, 2010, 01:42:57 pm
In debug you must link to the debug build of CSFML (csfml-graphics-d.lib).
Title: Can't compile sample code
Post by: darekg11 on September 20, 2010, 01:56:56 pm
After linking csfml-graphics-d.lib nothing changed.
Title: Can't compile sample code
Post by: Nexus on September 20, 2010, 04:29:03 pm
I'm not sure about the C-Binding, but normally, you have to link the system and window package as well, if you use the graphics package.

But, according to the errors, the definitions in the graphics package aren't found... Weird :?
Title: Can't compile sample code
Post by: darekg11 on September 20, 2010, 04:40:36 pm
After adding system and windows package I got this:
E:\Program Files\Microsoft Visual Studio 9.0\VC\lib\csfml-system.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2C0

Well that same error goes when I try to link csfml-system-d.dll instead of normal, god damn it why it just can't compile right fack >.>
Title: Can't compile sample code
Post by: Laurent on September 20, 2010, 04:40:40 pm
This is because you use CSFML with a C++ compiler. Do this to solve your problem:

Code: [Select]
extern "C"
{
    #include <SFML/Graphics.h>
    ... all your SFML includes ...
}


By the way, why don't you use the C++ version of SFML?
Title: Can't compile sample code
Post by: darekg11 on September 20, 2010, 04:51:48 pm
Man, fack jeah that was that thing.
Now it working.

Thanks and I don't like C++ and I am using C++ compilator because I was learning basic of programming at it.
Well it works now but I have like 3 more questions to You:

In Debug mode I need to include libs with -d sufix right?
And which libraries do I need to include when I want build it in Release?
And when I want to share that program with my friend I just need to give him right dll's right?

I also made a simple window and code of it looks like that:
http://wklej.org/id/391461/

And it's lagging my computer like hell, app is tkaing 100% CPU all the time, how Can I prevent that?
Title: Can't compile sample code
Post by: Laurent on September 20, 2010, 05:56:24 pm
Quote
In Debug mode I need to include libs with -d sufix right?

Yes.

Quote
And which libraries do I need to include when I want build it in Release?

The ones without the -d suffix ;)

Quote
And when I want to share that program with my friend I just need to give him right dll's right?

Yes.

Quote
And it's lagging my computer like hell, app is tkaing 100% CPU all the time, how Can I prevent that?

You have two simple ways of limiting the framerate:
- sfRenderWindow_UseVerticalSync(window, true)
- sfRenderWindow_SetFramerateLimit(window, 60)
Title: Can't compile sample code
Post by: darekg11 on September 20, 2010, 06:01:04 pm
I think it's not related to FPS, because Your solution did not help.
It laggs the whole computer not only the app.

Extra question:
How to get rid of that console background?
I found that I need to change in Linker's options In System to: Window I did but I can't find CSFML-main.lib so I can't link it and I get:
 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup



Thanks again man for help You are great big props.
Title: Can't compile sample code
Post by: Laurent on September 20, 2010, 06:04:25 pm
Quote
I can't find CSFML-main.lib

Indeed it's missing from the CSFML 1.6 SDK. You'll have to handle it by yourself.
Title: Can't compile sample code
Post by: darekg11 on September 20, 2010, 07:49:15 pm
Yeah, I solved that problem.
I just can't come up with anything that could fix that 100% CPU use.

Code:
http://wklej.org/id/391461/
Title: Can't compile sample code
Post by: Laurent on September 20, 2010, 10:09:07 pm
Quote
- sfRenderWindow_UseVerticalSync(window, true)
- sfRenderWindow_SetFramerateLimit(window, 60)

These two functions do reduce the CPU usage of your application. How did you try to use them?
Title: Can't compile sample code
Post by: darekg11 on September 20, 2010, 10:18:28 pm
I tried using after:
aaa =  sfRenderWindow_Create(Mode, "Maslo", sfResize | sfClose, Settings);
sfRenderWindow_SetFramerateLimit(aaa, 60);
sfRenderWindow_Display(aaa);
I also tried to use that in loop but no effect.
Title: Can't compile sample code
Post by: Laurent on September 20, 2010, 11:47:59 pm
What if you call sfSleep in your main loop?
Title: Can't compile sample code
Post by: darekg11 on September 21, 2010, 07:31:27 am
It was lagging like hell because I placed:
 sfRenderWindow_Clear(aaa, sfBlack);

In infinite loop so it was refresing it all the time, I placed it outside and it's all good.


Thanks again You can close now.
Title: Can't compile sample code
Post by: Laurent on September 21, 2010, 07:54:05 am
You're supposed to clear your window all the time. You'll probably come back to the same problem when you start drawing something.
Title: Can't compile sample code
Post by: darekg11 on September 21, 2010, 08:00:48 am
God damn it, really?
SfSleep is not helping.
Title: Can't compile sample code
Post by: Laurent on September 21, 2010, 08:07:17 am
What's your graphics card? Are your drivers up-to-date?
Title: Can't compile sample code
Post by: darekg11 on September 21, 2010, 08:10:37 am
Nvidia GeForce 7600GS 256MB DDR2.
Drivers are not the newest but they are also not the oldest.
Version of them: 6.14.11.9621

Hmm I can't come up with anything that could prevent it, damn.
Title: Can't compile sample code
Post by: Laurent on September 21, 2010, 08:37:47 am
Are you able to run games or OpenGL apps on this computer?
Title: Can't compile sample code
Post by: darekg11 on September 21, 2010, 02:35:40 pm
EDIT: Solved, I wasn't updating the window when I putted in a loop:

sfRenderWindow_Clear(aaa, sfRed);
sfRenderWindow_Display(aaa);

It is working great now, thank again mate.