Compile error under vc++ - unresolved external symbol

Hello,

I installed SDL 1.2 into my VC++ 2005 (Windows) and it worked fine, and
later I tried to install SDL Mixer. First I used the precompiled lib files
available for download on the SDL website, and I tried to compile the
following code:=========================================
#include “stdafx.h”
#include “SDL.h”
#include “SDL_thread.h”
#include “SDL_mixer.h”

int _tmain(int argc, _TCHAR* argv[])
{
Mix_Chunk *chunk = Mix_LoadWAV(“E:\open sonic\ogg\st3.ogg”);
if(chunk!=NULL) fprintf(stderr,“Loaded myfile.wav\n”);
else fprintf(stderr,“Could not load myfile.wav\n”);

return 0;

}

======================================

The compiler gave me two errors:
Error 1 error LNK2019: unresolved external symbol _Mix_LoadWAV_RW
referenced in function _wmain sdltest2.obj
Error 2 error LNK2019: unresolved external symbol _SDL_RWFromFile
referenced in function _wmain sdltest2.obj

After that, I downloaded the SDL Mixer source and built all the libraries,
then copied all of them to the SDL lib folder, and the includes to the SDL
includes folder. Now, in addition to the 2 errors the compiler gave me, it
also gives me this error:
Error 3 fatal error LNK1120: 2 unresolved externals C:\Documents
and Settings\Albert\My Documents\Visual Studio
2005\Projects\sdltest2\Debug\sdltest2.exe 1

Does someone have any clue on this? I hope I won’t have to switch off to
DirectX :stuck_out_tongue:

Thanks,

Albert

Albert Ridolfi wrote:

Hello,

I installed SDL 1.2 into my VC++ 2005 (Windows) and it worked fine, and
later I tried to install SDL Mixer. First I used the precompiled lib files
available for download on the SDL website, and I tried to compile the
following code:

VS2005 might have changed the symbol format. You are best building
SDL/SDL_mixer yourself.

int _tmain(int argc, _TCHAR* argv[])

Don’t do this. Your code will not be handled correctly by the SDL entry
point code.

The compiler gave me two errors:
Error 1 error LNK2019: unresolved external symbol _Mix_LoadWAV_RW
referenced in function _wmain sdltest2.obj
Error 2 error LNK2019: unresolved external symbol _SDL_RWFromFile
referenced in function _wmain sdltest2.obj

Are you adding the libs to your linker settings?
Some headers use #pragma (lib, “blah.lib”) to make this unneccesary. SDL
doesn’t because that isn’t portable.

Pete.

Hello Peter,

I was using the pre-compiled libraries, but now I have built them all by
myself, and this didn’t fix the problem.

I modified just the main function and the signature, and removed #include
"stdafx.h", now it is just int main()

Yes, the libraries were added to the linker settings.

The compiler output:
main.obj : error LNK2019: unresolved external symbol _Mix_LoadWAV_RW
referenced in function “int __cdecl SDL_main(void)” (?SDL_main@@YAHXZ)
main.obj : error LNK2019: unresolved external symbol _SDL_RWFromFile
referenced in function “int __cdecl SDL_main(void)” (?SDL_main@@YAHXZ)
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main
referenced in function ___tmainCRTStartup

Thanks for the help
Albert> ----- Original Message -----

From: sdl-bounces+arfx4=yahoo.co.uk@libsdl.org
[mailto:sdl-bounces+arfx4=yahoo.co.uk at libsdl.org] On Behalf Of Peter
Mulholland
Sent: 16 July 2006 03:02
To: A list for developers using the SDL library. (includes SDL-announce)
Subject: Re: [SDL] compile error under vc++ - unresolved external symbol

Albert Ridolfi wrote:

Hello,

I installed SDL 1.2 into my VC++ 2005 (Windows) and it worked fine, and
later I tried to install SDL Mixer. First I used the precompiled lib files
available for download on the SDL website, and I tried to compile the
following code:

VS2005 might have changed the symbol format. You are best building
SDL/SDL_mixer yourself.

int _tmain(int argc, _TCHAR* argv[])

Don’t do this. Your code will not be handled correctly by the SDL entry
point code.

The compiler gave me two errors:
Error 1 error LNK2019: unresolved external symbol _Mix_LoadWAV_RW
referenced in function _wmain sdltest2.obj
Error 2 error LNK2019: unresolved external symbol _SDL_RWFromFile
referenced in function _wmain sdltest2.obj

Are you adding the libs to your linker settings?
Some headers use #pragma (lib, “blah.lib”) to make this unneccesary. SDL
doesn’t because that isn’t portable.

Pete.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Albert Ridolfi wrote:

Hello Peter,

I was using the pre-compiled libraries, but now I have built them all by
myself, and this didn’t fix the problem.

I modified just the main function and the signature, and removed #include
"stdafx.h", now it is just int main()

How have you created the project ? The correct setting to use is “Win32
Project”, “Windows Application”, and IMHO you are best ticking “Empty
Project”

One thing I have noticed is that VS2005 now defaults to using Unicode
character set. I doubt this is a problem but you can always try setting
it back to Multibyte (the default in previous versions), in the project
property pages under General.

The compiler output:
main.obj : error LNK2019: unresolved external symbol _Mix_LoadWAV_RW
referenced in function “int __cdecl SDL_main(void)” (?SDL_main@@YAHXZ)
main.obj : error LNK2019: unresolved external symbol _SDL_RWFromFile
referenced in function “int __cdecl SDL_main(void)” (?SDL_main@@YAHXZ)

I don’t get this. These should be available if you are linking with
SDL.lib and SDL_mixer.lib. For some reason VS2005 is not doing so. Are
you sure that the place where these lib files are is in VS2005’s library
search path?

MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main
referenced in function ___tmainCRTStartup

That means that the wrong project setting (Console Application most
likely, in Unicode mode) was chosen.

Windows Apps typically have a WinMain() entry point. SDL hides this
through SDLmain.lib so that it can set itself up, and it makes it appear
that a standard main() is supported. This shows up (through some
preprocessor tricks) as SDL_main().

Pete.

Hello Albert,
the better way to work in vs2005 with the SDL is:

1 - Make a empty project
2 - copy all the precompilated libraries under
\Programmi\Microsoft Visual Studio 8\VC\lib
3 - copy all the headers files under
\Programmi\Microsoft Visual Studio 8\VC\include\SDL
4 - copy all the dll under:
C:\Windows\System32
5 - Set the project with the libraries that you will use:
Right-click on the project -> Options -> Linker -> Input:
SDLmain.lib SDL.lib etc.lib

Where you must insert SDLmain.lib SDL.lib, and the etc.lib are,
for example, SDL_image.lib, SDL_mixer.lib.

Albert Ridolfi ha scritto:> Hello Peter,

I was using the pre-compiled libraries, but now I have built them all by
myself, and this didn’t fix the problem.

I modified just the main function and the signature, and removed #include
"stdafx.h", now it is just int main()

Yes, the libraries were added to the linker settings.

The compiler output:
main.obj : error LNK2019: unresolved external symbol _Mix_LoadWAV_RW
referenced in function “int __cdecl SDL_main(void)” (?SDL_main@@YAHXZ)
main.obj : error LNK2019: unresolved external symbol _SDL_RWFromFile
referenced in function “int __cdecl SDL_main(void)” (?SDL_main@@YAHXZ)
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main
referenced in function ___tmainCRTStartup

Thanks for the help
Albert

I found a tutorial that told me to add to the code:
#ifdef WIN32
#pragma comment(lib, “SDL.lib”)
#pragma comment(lib, “SDLmain.lib”)
#endif

Now it’s working. Thanks for the help> ----- Original Message -----

From: sdl-bounces+arfx4=yahoo.co.uk@libsdl.org
[mailto:sdl-bounces+arfx4=yahoo.co.uk at libsdl.org] On Behalf Of Salvatore Di
Fazio
Sent: 16 July 2006 07:37
To: SDL
Subject: Re: [SDL] compile error under vc++ - unresolved external symbol

Hello Albert,
the better way to work in vs2005 with the SDL is:

1 - Make a empty project
2 - copy all the precompilated libraries under
\Programmi\Microsoft Visual Studio 8\VC\lib
3 - copy all the headers files under
\Programmi\Microsoft Visual Studio 8\VC\include\SDL
4 - copy all the dll under:
C:\Windows\System32
5 - Set the project with the libraries that you will use:
Right-click on the project -> Options -> Linker -> Input:
SDLmain.lib SDL.lib etc.lib

Where you must insert SDLmain.lib SDL.lib, and the etc.lib are, for example,
SDL_image.lib, SDL_mixer.lib.

Albert Ridolfi ha scritto:

Hello Peter,

I was using the pre-compiled libraries, but now I have built them all
by myself, and this didn’t fix the problem.

I modified just the main function and the signature, and removed
#include “stdafx.h”, now it is just int main()

Yes, the libraries were added to the linker settings.

The compiler output:
main.obj : error LNK2019: unresolved external symbol _Mix_LoadWAV_RW
referenced in function “int __cdecl SDL_main(void)” (?SDL_main@@YAHXZ)
main.obj : error LNK2019: unresolved external symbol _SDL_RWFromFile
referenced in function “int __cdecl SDL_main(void)” (?SDL_main@@YAHXZ)
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol
_main referenced in function ___tmainCRTStartup

Thanks for the help
Albert


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Albert Ridolfi ha scritto:

I found a tutorial that told me to add to the code:
#ifdef WIN32
#pragma comment(lib, “SDL.lib”)
#pragma comment(lib, “SDLmain.lib”)
#endif

I have never done it.
I think because I have never used the precompileted header.

Anyway I think you will have some problem when you will want delivery
you application.

bye

Albert Ridolfi wrote:

I found a tutorial that told me to add to the code:
#ifdef WIN32
#pragma comment(lib, “SDL.lib”)
#pragma comment(lib, “SDLmain.lib”)
#endif

Now it’s working. Thanks for the help

If that works, then you were not correctly adding the libs to the linker
settings.

Project->Properties->Configuration Properties, Linker, Input and add the
libs in the “Additional Dependancies” box. Make sure you do it for all
build configurations.

Pete.