Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: C-SFML - Getting some Linker Error: undefined reference to `_imp__sfBlendAdd'  (Read 9095 times)

0 Members and 1 Guest are viewing this topic.

MOP

  • Newbie
  • *
  • Posts: 19
  • Expect the progress
    • View Profile
Hello folks,

this is my first topic in this forum. First of all my english is not very good.  ;D

Iam actually playing with the C-SFML Libary. Iam coding in C. Iam dont rly know C++, so thats why.

Former i used the SDL Libary, which was easy. C-SFML seems also to be very easy.

Actually i try to put some Example Shader(Edge Detection from the Examples), to a picture. Just for testing in my own gui. But i just failing first for the blend mode...

I use the latest codeblocks and csfml version, with mingw32.

Code: [Select]
bool MenuPlaceIMG(int x, int y, bool type, int id)
{
    // Initialisieren
    if(!CSFMLIsInit || !mstate.isInit)
        return false;

    sfSprite *sprite = sfSprite_create();
    sfShader *shader = sfShader_createFromFile(NULL, NULL, "edge.frag");
    sfRenderStates state;

    if(shader == NULL || sprite == NULL)
    {
        printf("Shader oder Sprite kann nicht geladen werden!");
        return false;
    }

    sfVector2f position = {x, y};
    sfSprite_setPosition(sprite, position);

    sfShader_setFloatUniform(shader, "edge_threshold", 1.0f);

    // Bild zeichnen
    if(type == false)
    {
        sfSprite_setTexture(sprite, media.header, sfTrue);
        sfTexture_setSmooth(media.header, sfTrue);
        sfShader_setTextureUniform(shader, "texture", media.header);

        state.blendMode = sfBlendAdd;
        state.shader = shader;
        state.texture = media.header;
        state.transform = sfTransform_Identity;
    }
    else
    {
        sfSprite_setTexture(sprite, media.bg[id].background, sfTrue);
        sfTexture_setSmooth(media.bg[id].background, sfTrue);
        sfShader_setTextureUniform(shader, "texture", media.bg[id].background);

        state.blendMode = sfBlendAdd;
        state.shader = shader;
        state.texture = media.bg[id].background;
        state.transform = sfTransform_Identity;
    }

    sfRenderWindow_drawSprite(screen, sprite, &state);

    // Speicher freigeben
    sfShader_destroy(shader);
    shader = NULL;
    sfSprite_destroy(sprite);
    sprite = NULL;

    return true;
}

If i tryn compile this, i got some linker errors, and iam actually sure, that i linked all libarys...

My errors:
Code: [Select]
|249|undefined reference to `_imp__sfBlendAdd'|
|252|undefined reference to `_imp__sfTransform_Identity'|
|260|undefined reference to `_imp__sfBlendAdd'|
|263|undefined reference to `_imp__sfTransform_Identity'|
||error: ld returned 1 exit status|

By The way, when i want to use the default Colors like sfBlack or something, i get the same errors.

My Link-Libarys sequence are the following
Audio
Network
Graphics
Window
System

Anyone an idea to fix this?

Thank you all in advance for help or tips.

Greetings MOP
« Last Edit: October 11, 2017, 02:58:57 pm by MOP »
My Github Repo:
Snake
Deep Deep Deep in Development

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
You shouldn't add SFML to the global Code::Blocks compiler settings, but configure your project settings.
Additionally you should define the path where the libraries are located and then only specify the names of the libraries. See the official SFML tutorials to get the idea.

Where did you get CSFML from?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MOP

  • Newbie
  • *
  • Posts: 19
  • Expect the progress
    • View Profile
I got CSFML from here: https://www.sfml-dev.org/download/csfml/

I updated my settings, but i still get the errors. Same Settings for Build, the xxx-d suffix for debug as said in the tutorial wont work.

Edit:
I got it work now. But i need to self define variables.
I just put this to my code
Code: [Select]
const sfBlendMode sfBlendAdd = { sfBlendFactorSrcAlpha, sfBlendFactorOne, sfBlendEquationAdd, sfBlendFactorOne, sfBlendFactorOne, sfBlendEquationAdd };
    const sfTransform sfTransform_Identity = { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
This is from officially documentation.
« Last Edit: October 11, 2017, 04:22:25 pm by MOP »
My Github Repo:
Snake
Deep Deep Deep in Development

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Have you maybe not updated the header files properly? Does your include/SFML/Graphics/BlendMode.h contain the mentioned symbols?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MOP

  • Newbie
  • *
  • Posts: 19
  • Expect the progress
    • View Profile
My Header File Contain the following:
Its the same like on this: https://github.com/SFML/CSFML/blob/master/include/SFML/Graphics/BlendMode.h
Code: [Select]
...
CSFML_GRAPHICS_API const sfBlendMode sfBlendAlpha;    ///< Blend source and dest according to dest alpha
CSFML_GRAPHICS_API const sfBlendMode sfBlendAdd;      ///< Add source to dest
CSFML_GRAPHICS_API const sfBlendMode sfBlendMultiply; ///< Multiply source and dest
CSFML_GRAPHICS_API const sfBlendMode sfBlendNone;     ///< Overwrite dest with source
...

The self define things i got from this file:
https://github.com/SFML/CSFML/blob/master/src/SFML/Graphics/BlendMode.cpp

My Github Repo:
Snake
Deep Deep Deep in Development

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
The MinGW import files (*.a) were created based off the MSVC import files (*.lib) and it seems like the conversion tool for whatever reason dropped those symbols.
I'm no expert on this topic, but when looking at both files in a text editor, the mentioned symbols can be found in the *.lib file, but can't be found in the *.a file. They can also be found in the *.dll itself.

If you know how to generate an import file based off a *.lib and *.dll file, you might be able to generate non-broken *.a files.

Will certainly keep that in mind for future releases.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MOP

  • Newbie
  • *
  • Posts: 19
  • Expect the progress
    • View Profile
That sounds logic
Please donot forget the same with
The Default Colors
SfBlack
SfWhite

and so on..

I will try to built up directly the .a's liabray with the source.
And if successfully, I will test it and post updates here.
My Github Repo:
Snake
Deep Deep Deep in Development

MOP

  • Newbie
  • *
  • Posts: 19
  • Expect the progress
    • View Profile
Hey,

some update from me about linking.

If you built up a 32 Bit project, MinGW supports for 32 Bit also *.lib libarys, i tested it. But i just got the same error, with the default Colors / Blend Modes.

Another try, i used the converter tool LIB2A. This tool generate a .def File without these symbols...

It seems the Tool just generates symbols, which has some functions

Like:
...
sfTestSymbol ---struct
sfTestSymbol_FunctionTest ---function to the struct
sfTestSymbol_FunctionTest2 ---another function to the struct
...

All of these symbols are exported.

If you got:
...
sfTestSymbol1 ---struct
sfTestSymbol2 ---struct
sfTestSymbol3 ---struct
...
sfTestSymbol4 ---struct
sfTestSymbol4_Explode ---function to the struct
...

It just export the last 2 Symbols and ignores the first 3.

And the converter uses the .def file to generate an .a file.
If i open the .a lib with 7zip (a tip from me, if you want to see Symbols in a,lib,dl file).
I only see the symbols in my .a file which was defined in the .def File.

It is maybe a bug in LIB2A tool, or desired?


I try to put manually missing symbols to the .def file and post for update.


My Github Repo:
Snake
Deep Deep Deep in Development

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Will it's no surprise that you find the same result that way, since I've also used the LIB2A tool, but it might well be that it doesn't handle all symbols.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MOP

  • Newbie
  • *
  • Posts: 19
  • Expect the progress
    • View Profile
i was successfully, now the tool generated a good .a file.

I put all missing symbols from the graphics libary manually to the .def file. My compiling and linking now works good.

In my attachment you find the .def file and the .a file.

Edit:
Some things got my attention, in your Source Code
https://github.com/SFML/CSFML/tree/master/src/SFML/Graphics

All exported "Structs" got his own ExampleStruct.h File.
On the other Side, such like BlendModes or Colors, got no own .h File.
The defines are in the .cpp file. Maybe there's a problem?

Iam not the expert on C++ and your code of course, but it is maybe an idea ?!
« Last Edit: October 13, 2017, 01:56:07 pm by MOP »
My Github Repo:
Snake
Deep Deep Deep in Development

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
If anyone ever stumbles up on this topic and gets curious how to easily solve it.

It took a while, but I finally figured out that MinGW-w64 ships with a tool called gendef.exe which does a proper export of DLL to DEF file. From there you can take the dlltool.exe that also ships with MinGW-w64.

In summary, here's a bat file that converts all the CSFML libs - I know it's quite hardcoded, but hey it works. :D

set dll_file= csfml-system-2.dll
set def_file= csfml-system-2.def
set   a_file= libcsfml-system.a

gendef.exe %dll_file%
dlltool.exe -d %def_file% -D %dll_file% -l %a_file%

set dll_file= csfml-window-2.dll
set def_file= csfml-window-2.def
set   a_file= libcsfml-window.a

gendef.exe %dll_file%
dlltool.exe --export-all-symbols -d %def_file% -D %dll_file% -l %a_file%

set dll_file= csfml-graphics-2.dll
set def_file= csfml-graphics-2.def
set   a_file= libcsfml-graphics.a

gendef.exe %dll_file%
dlltool.exe --export-all-symbols -d %def_file% -D %dll_file% -l %a_file%

set dll_file= csfml-network-2.dll
set def_file= csfml-network-2.def
set   a_file= libcsfml-network.a

gendef.exe %dll_file%
dlltool.exe --export-all-symbols -d %def_file% -D %dll_file% -l %a_file%

set dll_file= csfml-audio-2.dll
set def_file= csfml-audio-2.def
set   a_file= libcsfml-audio.a

gendef.exe %dll_file%
dlltool.exe --export-all-symbols -d %def_file% -D %dll_file% -l %a_file%

Also finally updated the CSFML download packages, so this issue shouldn't occur anymore!
For those interested, I wrote a short blog post about it.
« Last Edit: June 02, 2018, 12:00:33 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/