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

Author Topic: VS2005 linking error: unresolved external symbol  (Read 10714 times)

0 Members and 1 Guest are viewing this topic.

Crank1d

  • Newbie
  • *
  • Posts: 14
    • View Profile
VS2005 linking error: unresolved external symbol
« on: July 25, 2010, 04:38:29 pm »
I´ve just started with CSFML and i am getting linking errors everytime i try to compile my app (i am using Visual Sudio 2005, as i´ve said in title).
I´ve included all needed libraries for app (csfml-audio.lib, csfml-graphics.lib, csfml-network.lib, csfml-system.lib, csfml-window.lib). Here is the code:

SoundSystem.h
Code: [Select]
#include <SFML/Audio.h>
#include "DataTypes.h"

// sound
extern void PlayMusic(C8 *FileName);


SoundSystem.cpp
Code: [Select]
#include "DataTypes.h"
#include "SoundSystem.h"

sfMusic *Music;

void PlayMusic(C8 *FileName)
{
sfMusic_CreateFromFile(FileName);
sfMusic_Play(Music);
// Loop while the music is playing
while(sfMusic_GetStatus(Music) == sfPlaying)
{
sfSleep(0.1f);
}
}


main.cpp
Code: [Select]
#include "SoundSystem.h"

int main()
{
PlayMusic("data/sound.ogg");
return EXIT_SUCCESS;
}


...and here are the linking errors.
Code: [Select]
1>Compiling...
1>main.cpp
1>SoundSystem.cpp
1>Linking...
1>SoundSystem.obj : error LNK2001: unresolved external symbol "void __cdecl sfMusic_Play(struct sfMusic *)" (?sfMusic_Play@@YAXPAUsfMusic@@@Z)
1>SoundSystem.obj : error LNK2001: unresolved external symbol "void __cdecl sfSleep(float)" (?sfSleep@@YAXM@Z)
1>SoundSystem.obj : error LNK2001: unresolved external symbol "struct sfMusic * __cdecl sfMusic_CreateFromFile(char const *)" (?sfMusic_CreateFromFile@@YAPAUsfMusic@@PBD@Z)
1>SoundSystem.obj : error LNK2001: unresolved external symbol "enum sfSoundStatus __cdecl sfMusic_GetStatus(struct sfMusic *)" (?sfMusic_GetStatus@@YA?AW4sfSoundStatus@@PAUsfMusic@@@Z)
1>..\bin32\game_c.exe : fatal error LNK1120: 4 unresolved externals


I don´t know if i´ve forgot to set some options to compiler or forgot to include some file... so i´m looking for a help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
VS2005 linking error: unresolved external symbol
« Reply #1 on: July 25, 2010, 07:23:22 pm »
Is it happening for every SFML function that you use? Even from other modules? If so, make sure that you use the VC2005 libs (not the VC2008 ones, for example).

Or maybe you've made a mistake in the linker options.
Laurent Gomila - SFML developer

Crank1d

  • Newbie
  • *
  • Posts: 14
    • View Profile
VS2005 linking error: unresolved external symbol
« Reply #2 on: July 25, 2010, 08:14:03 pm »
It happens for every CSFML function that i use (tried to create simple SFML window, it also didnt compiled sucessfully). Using VS2005 version of CSFML SDK and precompiled libraries that came with SDK. Tried to compile SDK from source (compiling succesfull) but it fails to compile without linking errors for my app.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
VS2005 linking error: unresolved external symbol
« Reply #3 on: July 25, 2010, 08:31:50 pm »
Can you send me your project?
Laurent Gomila - SFML developer

Crank1d

  • Newbie
  • *
  • Posts: 14
    • View Profile
VS2005 linking error: unresolved external symbol
« Reply #4 on: July 26, 2010, 01:10:01 am »
I´ve sended it on your e-mail adress.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
VS2005 linking error: unresolved external symbol
« Reply #5 on: July 26, 2010, 09:27:41 am »
This is because you compile in C++. When doing so, the compiler uses the C++ naming rules for imported symbols (for example "?sfMusic_Play@@YAXPAUsfMusic@@@Z") instead of the C ones ("_sfMusic_Play"), that's why it can't find them in the CSFML DLLs.

You have to use this code to tell the compiler to use the C rules:
Code: [Select]

extern "C"
{
    #include <SFML/Audio.h>
}
Laurent Gomila - SFML developer

Crank1d

  • Newbie
  • *
  • Posts: 14
    • View Profile
VS2005 linking error: unresolved external symbol
« Reply #6 on: July 26, 2010, 06:49:11 pm »
It works! Thanks! I knew that i´ve forgot to add something (didn´t used this "extern C" code for a long time, so i´ve forgot it because of only C++ programming in past years).  :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
VS2005 linking error: unresolved external symbol
« Reply #7 on: July 26, 2010, 07:07:39 pm »
By the way, may I ask why you're using CSFML in C++ code?
Laurent Gomila - SFML developer

Crank1d

  • Newbie
  • *
  • Posts: 14
    • View Profile
VS2005 linking error: unresolved external symbol
« Reply #8 on: July 26, 2010, 07:55:27 pm »
Can you explain it more closely, why do you think i use CSFML in C++ code (because of C++ source files (.cpp) with C code in it or something else) ?  :?:  :?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
VS2005 linking error: unresolved external symbol
« Reply #9 on: July 26, 2010, 08:06:15 pm »
Quote
because of C++ source files (.cpp) with C code in it

Yes.
Laurent Gomila - SFML developer

Crank1d

  • Newbie
  • *
  • Posts: 14
    • View Profile
VS2005 linking error: unresolved external symbol
« Reply #10 on: July 26, 2010, 08:14:56 pm »
I´m trying to create a simple 3D OpenGL engine with CSFML similar to Cube Engine http://cubeengine.com/. Cube source files are also .cpp with C code in it and the game uses SDL. I found design of a Cube Engine quite interesting. It won´t be tottally same but i wil try to keep similar design of a Cube source files for code of my project.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
VS2005 linking error: unresolved external symbol
« Reply #11 on: July 26, 2010, 08:56:24 pm »
But why do you use C in C++ sources? And why don't you use the C++ API of SFML (which is far more convenient to use) if you use a C++ compiler?
Laurent Gomila - SFML developer

Crank1d

  • Newbie
  • *
  • Posts: 14
    • View Profile
VS2005 linking error: unresolved external symbol
« Reply #12 on: July 27, 2010, 12:49:22 am »
Quote from: "Laurent"
1.) But why do you use C in C++ sources? 2.) And why don't you use the C++ API of SFML (which is far more convenient to use) if you use a C++ compiler?

1.) Experimenting. :wink: But i would probably switch to C++ version of SFML.
2.) I´ve didn´t configured all of the project options yet.

 

anything