Can't use vector push_back with SDL

I’m struggling to get rid of my LINK errors and I’ve isolated it to the
use of vector’s push_back(). I would really like to use it so any help
would be appreciated.

I’m using Visual Studio 2005 and I’ve scaled my program all the way down
to this:

#include <windows.h>
#include

//SDL related libraries
#include <stdio.h>
#include <SDL/SDL.h>

using namespace std;

int main( int argc, char* args[] )
{
vector vList;
vList.push_back(2);
return 0;
}

Not much to look at but it throws these errors
Error 1 error LNK2019: unresolved external symbol
__imp___CrtDbgReportW referenced in function "public: __thiscall
std::_Vector_const_iterator<int,class std::allocator

::_Vector_const_iterator<int,class std::allocator >(int *,class
std::_Container_base const *)"
(??0?$_Vector_const_iterator at HV?$allocator at H@std@@@std@@QAE at PAHPBV_Container_base@1@@Z)
main.obj

Error 2 error LNK2019: unresolved external symbol _SDL_main
referenced in function _main SDLmain.lib

If I comment out vList.push_back(2); then the program compiles

I have done:
Linker->Input->Additional Dependencies = SDL.lib SDLmain.lib
Runtime library = Multi-threaded DLL (/MD)

I figured half a day trying was long enough so here I am, posting to a
mailing list.

Thanks,

Glenn

Glenn McCord wrote:

I’m struggling to get rid of my LINK errors and I’ve isolated it to
the use of vector’s push_back(). I would really like to use it so any
help would be appreciated.

I’m using Visual Studio 2005 and I’ve scaled my program all the way
down to this:

#include <windows.h>
#include

//SDL related libraries
#include <stdio.h>
#include <SDL/SDL.h>

using namespace std;

int main( int argc, char* args[] )
{
vector vList;
vList.push_back(2);
return 0;
}

Not much to look at but it throws these errors
Error 1 error LNK2019: unresolved external symbol
__imp___CrtDbgReportW referenced in function "public: __thiscall
std::_Vector_const_iterator<int,class std::allocator

:_Vector_const_iterator<int,class std::allocator >(int *,class
std::_Container_base const *)"
(??0?$_Vector_const_iterator at HV?$allocator at H@std@@@std@@QAE at PAHPBV_Container_base@1@@Z)
main.obj

Error 2 error LNK2019: unresolved external symbol _SDL_main
referenced in function _main SDLmain.lib

I got the same error if I failed to link with SDLmain.lib. When I link with
both libs it builds fine, but issues a warning:
Compiling…

sdltest.cpp

Linking…

MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib’
conflicts with use of other libs; use /NODEFAULTLIB:library

My test program was identical with yours but I removed the two unnecessary
includes <windows.h> and <stdio.h>

If I comment out vList.push_back(2); then the program compiles

I have done:
Linker->Input->Additional Dependencies = SDL.lib SDLmain.lib
Runtime library = Multi-threaded DLL (/MD)

I figured half a day trying was long enough so here I am, posting to a
mailing list.

Thanks,

Glenn

/ E

Hi, Glenn!
Try this:

  1. Remove the unnecessary #includes (<windows.h> and <stdio.h>);
  2. Make sure SDLmain.lib is being linked to your application;
  3. Add /NODEFAULTLIB:msvcrt.lib at Linker -> Command Line

Goodbye!

— Glenn McCord <clari_player at paradise.net.nz> escreveu:

I’m struggling to get rid of my LINK errors and I’ve isolated it to
the
use of vector’s push_back(). I would really like to use it so any
help
would be appreciated.

I’m using Visual Studio 2005 and I’ve scaled my program all the way
down
to this:

#include <windows.h>
#include

//SDL related libraries
#include <stdio.h>
#include <SDL/SDL.h>

using namespace std;

int main( int argc, char* args[] )
{
vector vList;
vList.push_back(2);
return 0;
}

Not much to look at but it throws these errors
Error 1 error LNK2019: unresolved external symbol
__imp___CrtDbgReportW referenced in function "public: __thiscall
std::_Vector_const_iterator<int,class std::allocator

::_Vector_const_iterator<int,class std::allocator >(int
*,class
std::_Container_base const *)"

(??0?$_Vector_const_iterator at HV?$allocator at H@std@@@std@@QAE at PAHPBV_Container_base@1@@Z)>

main.obj

Error 2 error LNK2019: unresolved external symbol _SDL_main
referenced in function _main SDLmain.lib

If I comment out vList.push_back(2); then the program compiles

I have done:
Linker->Input->Additional Dependencies = SDL.lib SDLmain.lib
Runtime library = Multi-threaded DLL (/MD)

I figured half a day trying was long enough so here I am, posting to
a
mailing list.

Thanks,

Glenn


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


Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho agora!
http://br.mobile.yahoo.com/mailalertas/

I don’t know why it wasn’t linking to SDLmain before but it is working now.
So now I’ve explicitly linked to the two SDL libraries and removed the
two unnecessary headers. However if I go

/NODEFAULTLIB:msvcrt.lib at Linker -> Command Line -> Additional Dependencies

I go from 2 errors to 22. The first few are

Error 1 error LNK2019: unresolved external symbol __RTC_CheckEsp
referenced in function _SDL_main main.obj
Error 2 error LNK2019: unresolved external symbol
@_RTC_CheckStackVars at 8 referenced in function _SDL_main main.obj
Error 3 error LNK2001: unresolved external symbol __RTC_Shutdown
main.obj
Error 4 error LNK2001: unresolved external symbol __RTC_InitBase
main.obj
Error 5 error LNK2019: unresolved external symbol
___security_cookie referenced in function “public: __thiscall
std::vector<int,class std::allocator >::vector<int,class
std::allocator >(void)”
(??0?$vector at HV?$allocator at H@std@@@std@@QAE at XZ) main.obj

The program now looks like the following:

#include

#pragma comment(lib,“SDL.lib”)
#pragma comment(lib,“SDLmain.lib”)
#pragma comment(lib,“opengl32.lib”)

#include <SDL/SDL.h>

using namespace std;

int main( int argc, char* args[] )
{
vector vList;
vList.push_back(2);
return 0;
}

which still throws these two errors

Error 1 error LNK2019: unresolved external symbol
__imp___CrtDbgReportW referenced in function "public: __thiscall
std::_Vector_const_iterator<int,class std::allocator

::_Vector_const_iterator<int,class std::allocator >(int *,class
std::_Container_base const *)"
(??0?$_Vector_const_iterator at HV?$allocator at H@std@@@std@@QAE at PAHPBV_Container_base@1@@Z)
main.obj

Error 2 fatal error LNK1120: 1 unresolved externals
C:\Documents and Settings\Glenn McCord\Desktop\Copy of
715_SDL\Debug\GraphicsPractise.exe 1

Thanks

Glenn

Alex (aka Majin) wrote:> Hi, Glenn!

Try this:

  1. Remove the unnecessary #includes (<windows.h> and <stdio.h>);
  2. Make sure SDLmain.lib is being linked to your application;
  3. Add /NODEFAULTLIB:msvcrt.lib at Linker -> Command Line

Goodbye!

— Glenn McCord <clari_player at paradise.net.nz> escreveu:

I’m struggling to get rid of my LINK errors and I’ve isolated it to
the
use of vector’s push_back(). I would really like to use it so any
help
would be appreciated.

I’m using Visual Studio 2005 and I’ve scaled my program all the way
down
to this:

#include <windows.h>
#include

//SDL related libraries
#include <stdio.h>
#include <SDL/SDL.h>

using namespace std;

int main( int argc, char* args[] )
{
vector vList;
vList.push_back(2);
return 0;
}

Not much to look at but it throws these errors
Error 1 error LNK2019: unresolved external symbol
__imp___CrtDbgReportW referenced in function "public: __thiscall
std::_Vector_const_iterator<int,class std::allocator

::_Vector_const_iterator<int,class std::allocator >(int
*,class
std::_Container_base const *)"

(??0?$_Vector_const_iterator at HV?$allocator at H@std@@@std@@QAE at PAHPBV_Container_base@1@@Z)

main.obj

Error 2 error LNK2019: unresolved external symbol _SDL_main
referenced in function _main SDLmain.lib

If I comment out vList.push_back(2); then the program compiles

I have done:
Linker->Input->Additional Dependencies = SDL.lib SDLmain.lib
Runtime library = Multi-threaded DLL (/MD)

I figured half a day trying was long enough so here I am, posting to
a
mailing list.

Thanks,

Glenn


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


Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu celular. Registre seu aparelho agora!
http://br.mobile.yahoo.com/mailalertas/


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

Glenn McCord wrote:

I don’t know why it wasn’t linking to SDLmain before but it is working now.
So now I’ve explicitly linked to the two SDL libraries and removed the
two unnecessary headers. However if I go

/NODEFAULTLIB:msvcrt.lib at Linker -> Command Line -> Additional Dependencies

I go from 2 errors to 22. The first few are

First thing to do - compile your own SDLmain, VS2005 has changed things
quite a bit versus the older compilers that the precompiled binaries
use. Better still, build your own SDL too. This will minimise CRT
runtime clashes.

I would just build SDL in release mode, but build SDLmain in both
release and debug modes. Then, use the appropriate version. The reason
is that the CRT runtime libs used are different in debug and release
builds, and the linker will moan if they don’t match.

That should make all of the problems go away. It’s strange though, why
you were getting errors using vector::push_back(). That would sound like
Visual C++ has not automatically linked to the C++ runtime lib. Again,
compiling your own SDL and SDLmain should stop this.

Pete.

I was dreading someone suggesting that then only way forward was to
compile SDL myself. Assuming my attempt was correct, VS 2005 gives the
following error.

Error 1 fatal error LNK1104: cannot open file ‘dxguid.lib’ SDL

Yet under Linker -> Command Line -> Additional Dependencies

dxguid.lib appears in the list. I think it doesn’t exist on my machine.

After googling some more I’ve gotten the impression that I have to
download the entire DirectX SDK. My poor dialup connection is going to
have to endure another 170MB unless I can be convinced otherwise.

Glenn

Peter Mulholland wrote:>Glenn McCord wrote:

I don’t know why it wasn’t linking to SDLmain before but it is working now.
So now I’ve explicitly linked to the two SDL libraries and removed the
two unnecessary headers. However if I go

/NODEFAULTLIB:msvcrt.lib at Linker -> Command Line -> Additional Dependencies

I go from 2 errors to 22. The first few are

First thing to do - compile your own SDLmain, VS2005 has changed things
quite a bit versus the older compilers that the precompiled binaries
use. Better still, build your own SDL too. This will minimise CRT
runtime clashes.

I would just build SDL in release mode, but build SDLmain in both
release and debug modes. Then, use the appropriate version. The reason
is that the CRT runtime libs used are different in debug and release
builds, and the linker will moan if they don’t match.

That should make all of the problems go away. It’s strange though, why
you were getting errors using vector::push_back(). That would sound like
Visual C++ has not automatically linked to the C++ runtime lib. Again,
compiling your own SDL and SDLmain should stop this.

Pete.


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

Thanks. I’ve compiled my own SDL and SDLmain and almost got everything
working. My SDL programs that use .push_back can now compile under
release mode but not under debug. That is despite using an SDLmain that
has been compiled as either debug or release. Have I interpreteded what
you’ve said correctly?

The error is

Error 1 error LNK2019: unresolved external symbol
__imp___CrtDbgReportW referenced in function "public: __thiscall
std::_Vector_const_iterator<int,class std::allocator

::_Vector_const_iterator<int,class std::allocator >(int *,class
std::_Container_base const *)"
(??0?$_Vector_const_iterator at HV?$allocator at H@std@@@std@@QAE at PAHPBV_Container_base@1@@Z)
main.obj

Is there a way around or am I just going to have to live with it?

Thanks for helping me get this far.

Glenn

Peter Mulholland wrote:>Glenn McCord wrote:

I don’t know why it wasn’t linking to SDLmain before but it is working now.
So now I’ve explicitly linked to the two SDL libraries and removed the
two unnecessary headers. However if I go

/NODEFAULTLIB:msvcrt.lib at Linker -> Command Line -> Additional Dependencies

I go from 2 errors to 22. The first few are

First thing to do - compile your own SDLmain, VS2005 has changed things
quite a bit versus the older compilers that the precompiled binaries
use. Better still, build your own SDL too. This will minimise CRT
runtime clashes.

I would just build SDL in release mode, but build SDLmain in both
release and debug modes. Then, use the appropriate version. The reason
is that the CRT runtime libs used are different in debug and release
builds, and the linker will moan if they don’t match.

That should make all of the problems go away. It’s strange though, why
you were getting errors using vector::push_back(). That would sound like
Visual C++ has not automatically linked to the C++ runtime lib. Again,
compiling your own SDL and SDLmain should stop this.

Pete.


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

Glenn McCord wrote:

Thanks. I’ve compiled my own SDL and SDLmain and almost got everything
working. My SDL programs that use .push_back can now compile under
release mode but not under debug. That is despite using an SDLmain that
has been compiled as either debug or release. Have I interpreteded what
you’ve said correctly?

The error is

Error 1 error LNK2019: unresolved external symbol
__imp___CrtDbgReportW referenced in function "public: __thiscall
std::_Vector_const_iterator<int,class std::allocator

::_Vector_const_iterator<int,class std::allocator >(int *,class
std::_Container_base const *)"
(??0?$_Vector_const_iterator at HV?$allocator at H@std@@@std@@QAE at PAHPBV_Container_base@1@@Z)
main.obj

This is strange. I guess you use a lot more of the STL than just this?

I wouldn’t say this problem is related to SDL. If you create a simple
command line project, can you use vector::push_back() there?

Sounds like it could be a bug in VS2005.

Pete.