GPWiki.org
GPWiki.org
It is currently Fri May 24, 2013 1:58 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue May 15, 2012 5:31 pm 
Shake'n'Baker

Joined: Thu Dec 29, 2011 2:33 pm
Posts: 62
Hey there,
once again a beginner's question.
This time, it really sucks, because I did
this very often.

I have a new class(Knopf).
Using the standard constructor.
If I type:
Code:
Knopf new_object;

It works fine.
But If I type:
Code:
Knopf * new_object = new Knopf();

The compiler gives me a very strange error:

Quote:
C:\MinGW\lib\libmingw32.a(tlsthrd.o):tlsthrd.c|| undefined reference to `EnterCriticalSection@4'|


Here now the sources:
Knopf.h
Code:
#ifndef KNOPF_H
#define KNOPF_H

class Knopf
{
    public:
        bool is_null;
        Knopf();
};
#endif


Knopf.cpp
Code:
#include "Knopf.h"
Knopf::Knopf(){
    is_null = false;
}

In the main.cpp I include the "Knopf.h" as usual.

I didn't had problems in the last weeks writing new classes and including them the way I showed you.
Maybe I am a bit unconcentrated and oversaw a very simple error?

Thank you in advance,
Aestond


Top
 Profile  
 
PostPosted: Tue May 15, 2012 8:08 pm 
Bytewise

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 277
Location: Here (where else?)
I tried it too, and it worked fine.

One thing that was not clear to me was where do you allocate the new object, inside a function/method, or ourside?
(I tried both here, and it worked in both cases).

If you do it outside any function, the 'new' is called before main has started, which may or may not be a problem.

Another potential problem is the use of (), there seem to be subtle different semantics attached to adding them or not, at least for the default types, not sure how that works out with a custom class.

BTW: The internets also know this error (I looked for 'libmingw32.a(tlsthrd.o):tlsthrd.c', but the 'EnterCriticalSection@4' may work too), eg http://www.allegro.cc/forums/thread/606340/902409
It says to link with -lkernel32 at the end.

The internet has other references too, I didn't look at all of them.

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
PostPosted: Tue May 15, 2012 10:08 pm 
Shake'n'Baker

Joined: Thu Dec 29, 2011 2:33 pm
Posts: 62
Thanks for trying it Alberth.

First I tried to call new in an excluded(?) function.
I got those errors.
Then I tried to call it inside the main - same error.

After your post I tried it with and without brackets, both the same error.
Also tried to take an argument to the constructor - error.
Tried to compile with -lkernel32, didn't work either :|

Now I tried another, already working program using very similar
code(including another class). It works fine.

To be sure, that it is the "new" operator, or the constructor, which
is bugged here, I commented that line: Compiles fine.

Probably not an easy problem as I thought at first.
My next approach would be, to delete an recreate the project(not a problem,
since I just started it), but it would be greater to know why that happens :|

Edit:
The Build Log shows some other strange things:
http://nopaste.info/9bcb4c03c4.html

1. dwarf? I knew it, there are little robots in there!
2. Some things seem to be located on C:\... some other on D:\... This didn't give an error until now and I don't think, that this is the reason. Anyway it should be changed I guess...


Top
 Profile  
 
PostPosted: Wed May 16, 2012 3:09 pm 
Bytewise

Joined: Sun Oct 16, 2011 3:09 pm
Posts: 277
Location: Here (where else?)
ld.exe is the linker (which connects all object files (*.o or *.obj at your system probably) together into an .exe ).
Dwarf is likely the name of the file format that it uses. What looks worrying to me are the seemingly random numbers that it considers as being the version of the file.

Your c++ experiments sort of demonstrate that it is unlikely that the problem is in the c++ code itself.
Together with the linker errors, my guess would be that your compiler setup is broken.
Do you have several installs? (using one version for compile, and another version for linking or so?)
Do you have enough disk-space?
Do the object files look like having a sane size?

Perhaps there is a more specialized mingw32 community that can help you?


If all else fails, you can always switch to a platform designed for development, namely Linux :p

(just kidding, I hope you can solve your issues soon, but I fear there is little I can do)

_________________
My project: Messing about in FreeRCT, dev blog, and IRC #freerct at oftc.net


Top
 Profile  
 
PostPosted: Wed May 16, 2012 7:00 pm 
Shake'n'Baker

Joined: Thu Dec 29, 2011 2:33 pm
Posts: 62
Quote:
If all else fails, you can always switch to a platform designed for development, namely Linux :p


Yeah, spent the last days also with setting up Linux in a VM and Code::Blocks runs there also :)
Sadly, I am not very comfortable with Linux, almost zero experience...but for now it works, even SDL works.
But the directory and install system on Linux is so different, probably have to learn some more about
that too. I wanted to switch to Linux anyway, since I heard several times, that it is a bit easier on some issues.

My setup probably is somewhere wrong and I think, that I will just
reinstall everything(hey, it's a windows attitude - because it works!*g*).

Thank you for your help,
as soon as I reinstalled the things, I will tell, if it works again.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Baidu [Spider] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group