Page 1 of 1

librarys hurt me in ways you cannot imagine

Posted: Sat Jan 30, 2010 2:08 pm
by spirit bomb!
Hello everyone,

So I am trying to make a simple level editor int dark gdk. All it does is translate what is on the screen and make it into a txt file.
When i started playing around with txt files it started to break on me. Here is the visual studio build output:

>libcpmtd.lib(xdebug.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Obstacle::Obstacle(void)" (??0Obstacle@@QAE@XZ) referenced in function "void __cdecl DarkGDK(void)" (?DarkGDK@@YAXXZ)
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Obstacle::~Obstacle(void)" (??1Obstacle@@QAE@XZ) referenced in function "void __cdecl DarkGDK(void)" (?DarkGDK@@YAXXZ)
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
1>Debug\Edit.exe : fatal error LNK1120: 4 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\steve\My Documents\Visual Studio 2008\Projects\Edit\Edit\Debug\BuildLog.htm"
1>Edit - 5 error(s), 12 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I was playing around with my "project > properties > linker" and while there i used NODEFAULTLIB and played around alot, but cannot figure out the problem.

The first two errors may be due to my lack of constructor/destructors to my Obstacle class
The others are just killing me.

Anyone who can point me in the correct direction will be considered a God by me.
Any and all help is extremely appreciated!

Thank you much, and i'll post a vid of the level editor if anyone would like to see it (Assuming i can get it to run).

Re: librarys hurt me in ways you cannot imagine

Posted: Sat Jan 30, 2010 5:18 pm
by LeonBlade
That's what I love about Xcode!
All I got to do is just add the Framework, dylib or whatever library I need and I'm good to go :D
No need for linkers etc.

But... I guess this doesn't help you at all... :roll:

Re: librarys hurt me in ways you cannot imagine

Posted: Sat Jan 30, 2010 6:12 pm
by Live-Dimension
lmao.i *HATE* linker errors.
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall Obstacle::Obstacle(void)" (??0Obstacle@@QAE@XZ) referenced in function "void __cdecl DarkGDK(void)" (?DarkGDK@@YAXXZ)
"Main.obj" pretty much means Main.cpp

An unresolved external symbol pretty much means you've defined an say an type/function/etc inside an include file, and used it in the cpp file, but haven't defined it in the cpp file. The compiler is smart enough to know what said type/function is thanks to the include, but the linker doesn't catch on. So basically you have to prototype? the function in the include, and define it in the source cpp file.

Errors 1 and 2 are the same. Fixing them possibly will remove the other two linker errors, as c++ errors have a fantastic ability to cascade and generate more errors.

If it doesn't work, please post the c++/include files =]

Re: librarys hurt me in ways you cannot imagine

Posted: Sat Jan 30, 2010 7:47 pm
by spirit bomb!
Aight so those first two errors were easy enough to fix. All I did was comment out the constructor + destructor in my Obstacle.h file ( //~Obstacle(void); )

So now im down to.....

1>libcpmtd.lib(xdebug.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
1>Debug\Edit.exe : fatal error LNK1120: 2 unresolved externals

i;m not sure what you mean by include file, but...

#include "DarkGDK.h"
#include "Obstacle.h"
#include <string>
#include "stdio.h"
#include <sstream>

#include <stdlib.h>

using namespace std;

is this what you mean?
I have also played around with the run time library, but that turned out to be a crapshoot.

Re: librarys hurt me in ways you cannot imagine

Posted: Sat Jan 30, 2010 8:16 pm
by avansc

Re: librarys hurt me in ways you cannot imagine

Posted: Sat Jan 30, 2010 8:21 pm
by spirit bomb!
http://forum.thegamecreators.com/?m=for ... 22531&b=22

Oh my, someone with the same problem, and no solution :( :(

Re: librarys hurt me in ways you cannot imagine

Posted: Sat Jan 30, 2010 9:10 pm
by spirit bomb!
AVANSC, thank you much!

I now got no errors and it runs. but it does give me a wierd runtime error...

The screen goes black + unresponsive.

i debugged it and it would seem that my global dynamically created array of instance objects seems to malfunction.
It would seem that the "new" operator is messed up some how and it takes me into disassembly.
It NEVER did this before, and i know that this works because i used 4 different object arrays in my other project.

Here is a little snippet...

Obstacle *obstacle;

void DarkGDK ( void )
{
dbOpenToRead( 1 , "LevelData.txt");
dbOpenToWrite( 2 ,"LevelData.txt");

obstacle = new Obstacle[ObstacleMax]; //debugging dies here

Re: librarys hurt me in ways you cannot imagine

Posted: Sun Jan 31, 2010 7:27 am
by Live-Dimension
It's generally regarded as a bad idea to differentiate different names/types/etc by capitals only, as it can be confusing later on to you and definitely other programmers. you also don't need to use void as a function parameter, ie,

//exactly the same. I assume the compiler inserts void as it compiles.
void DarkGDK()
void DarkGDK(void)

As for your freeze......
Aight so those first two errors were easy enough to fix. All I did was comment out the constructor + destructor in my Obstacle.h file ( //~Obstacle(void); )
obstacle = new Obstacle[ObstacleMax]; //debugging dies here
Were those constructors perhaps needed for something? It's "OK" to not supply any constructors as the compiler generates empty constructors/destructors anyway.

The only way I know how to make arrays is like this.

Code: Select all

int myArray[5];
myArray[0] = 1;
myArray[2] = 1337;
//etc etc
Judging by the above example, I'd assume that you need to do this (or similar).

Code: Select all

Obstacle *obstacle[ObstacleMax];
I'm not a c++ lord, hell I'm still muddling my way through my first basic game engine (though I'm doing well on it) so someone else may/should be able to help better.

Good luck!

Re: librarys hurt me in ways you cannot imagine

Posted: Sun Jan 31, 2010 5:43 pm
by dandymcgee
spirit bomb! wrote:
Obstacle *obstacle;

void DarkGDK ( void )
{
dbOpenToRead( 1 , "LevelData.txt");
dbOpenToWrite( 2 ,"LevelData.txt");

obstacle = new Obstacle[ObstacleMax]; //debugging dies here
For some reason that doesn't look right..

Code: Select all

Obstacle *obstacle[ObstacleMax];

void DarkGDK ( void )
{
	dbOpenToRead( 1 , "LevelData.txt");
	dbOpenToWrite( 2 ,"LevelData.txt");	

	obstacle = new Obstacle[ObstacleMax];
That might work?

Re: librarys hurt me in ways you cannot imagine

Posted: Sun Jan 31, 2010 7:54 pm
by Bakkon
I'm assuming obstacle is a class and not just a datatype. Might want to try like this.

Code: Select all

Obstacle** obstacles;

void DarkGDK ( void )
{
   dbOpenToRead( 1 , "LevelData.txt");
   dbOpenToWrite( 2 ,"LevelData.txt");   

   obstacles = new Obstacle*[ObstacleMax];

   for(int i = 0; i < ObstableMax; i++)
      obstacles[i] = new Obstacle();
}