Code not running

Pages: 12
from the thread title as you may have guessed, I am very new to this.

I am using Dev-C++ 4.9.9.2

Here is my code.
#include <iostream>
int main()
{
using namespace std ;
cout << "I am your computer talking";
system("pause") ;
return 0 ;
}

now, as far as I know, this should open the command prompt and show the words "I am your computer talking. But this does not happen.

this is what I get after I try to compile and run the program.

[Linker error] undefined reference to `__dyn_tls_init_callback'
[Linker error] undefined reference to `__cpu_features_init'
ld returned 1 exit status

I have no idea what this means. I wouldn't mind a veteran or anyone shedding some light on how to get this to work, thanks.
Crazy hunch time. Have you MinGW installed? Or any other compiler n' linker programmes?
Last edited on
It compiles for me. As Moschops said, you probably don't have something installed. I use Dev-C++ 4.9.9.2 as well, and my version came with everything I needed, so I'm not quite sure what would be wrong.
Where did you get Dev-C++ from?

Edit: I'm pretty sure system commands are platform dependant. Replace system("pause") with cin.get(). What OS do you use?
Last edited on
1
2
3
4
5
6
7
8
#include <iostream>
int main()
{
using namespace std ;
cout << "I am your computer talking";
system("pause") ;
return 0 ;
}


Normally you would put the 'using namespace' statement in the global namespace and the system() function is included in <cstdlib>. It should be:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cstdlib>

using namespace std;

int main(const int argc, const char* argv[])
{
     cout << "I am your computer talking" << endl;

     system("pause");

     return 0;
}


I tried that in VC++ 2005 and it ran as you wanted.
Last edited on
NOOOO!!!! Not the system commands!
Seriously though, it's better to use something else like cin.get(). You could even do something like this:
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

using namespace std ;

int main()
{
    cout << "I am your computer talking\n";
    cout << "Press enter to continue...";
    cin.get();
    return 0 ;
}
If you still get errors after correcting your code, then maybe it's time to upgrade from Dev-C++ (it really should not be recommended by any sites anymore due to its age). Might I recommend Code::Blocks?

-Albatross
If you still get errors after correcting your code, then maybe it's time to upgrade from Dev-C++ (it really should not be recommended by any sites anymore due to its age). Might I recommend Code::Blocks?

I somewhat disagree. Sure it's old, but it's also very beginner friendly and it works.
Last edited on
Well, Dev-C++ still works for some systems, but here obviously something's phony. When I try to compile it with a newer version of GCC, it builds and links just fine. Now, maybe something got corrupted during the download, but either way right there we have two symbols that should be defined and that aren't, and Dev-C++'s compiler really could use an upgrade.

I suggest retrying the compilation of this program with Code::Blocks. It has a newer version of MinGW than Dev-C++, so if the error persists we'll know it's something else than an old compiler (which to fix, there may be a way to update the version of MinGW that Dev-C++ uses).

EDIT: If you like Dev-C++'s GUI, then instead of Code::Blocks you can try wxDev-C++.

-Albatross
Last edited on
I'd guess the software's been corrupted, or maybe he downloaded the IDE without the compiler. His code works as is with Dev on my computer. I have Windows 7 on a fairly new computer.

Note: Albatross now has 2^11-1 posts!
Albatross now has 2^11-1 posts-

EY! I'm the one who's supposed to say that! :P

On a side note, you, Browni, should probably upgrade to wxDev-C++ as well, unless you've already upgraded the included MinGW. Dev-C++ was last updated in... what, 2003? 7-8 years is a long time for computers.
http://wxdsgn.sourceforge.net/

-Albatross

2^11 posts (again), and counting (wouldn't it be fun if the people who hosted this website decided to change our post counts into binary?)
Last edited on
OK so, I have never heard of MinGW, that might be the problem.
I will try the other solutions you guys posted and see if they work.

I tried code blocks, it didn't compile, but I don't want to get into that.

Browni3141 (101011102)
On a side note, you, Browni, should probably upgrade to wxDev-C++ as well,

I've wanted to upgrade for awhile, but it would be much easier if I could multiply 11000.0112 Kb/s by a factor of at least 101011102. I hate dial-up. :-(
Forgive me for depriving you the pleasure of announcing you're accomplishment. My inner programmer just jumps at the sight of a power of 2 (or a power of 2 minus 1). Not to mention my inner mathematician jumping at the sight of a Mersenne number.
Last edited on
Nah, don't mention it (and yes, dial-up sucks... do you have access to a university computer which is hooked up to a faster internet connection that you can maybe use under the pretext of "improving your computer science self-education"?).

-Albatross
I installed wxdev-C++, ran the origianl code and got this.
[
Linker Error] undefined reference to `__dyn_tls_init_callback'
ld returned 1 exit status

Least I am down to one problem now : )

How come this happens though? And how do I fix it?
You need to have the version with the compiler integrated in it (for Dev-C++, this is the version with MinGW, I don't know about wxdev).
how do I get that?
http://www.bloodshed.net/dev/devcpp.html

You should choose:
Dev-C++ 5.0 beta 9.2 (4.9.9.2) (9.0 MB) with Mingw/GCC 3.4.2

Not:
Dev-C++ 5.0 beta 9.2 (4.9.9.2), executable only (2.4 MB)
did that, tried to run my code and I got "source code not compiled"

I am sorry about asking every little detail, but I am doing my best to understand, what at the moment is, gibberish to me.
did that, tried to run my code and I got "source code not compiled"


This would seem to indicate that you wrote some code, and then tried to run the executable without having actually made it.

It is not enough to just write code. You then have to compile it into objects, and then link it into an executable, and then you can run that executable.

Often, the compile and link stages are done together.
that error in the top post has something to do with the libraries in Dev-C++ being outdated... I still suggest using something else like wxDev-C++, but you can also do this..

under tools->compiler options->directories->libraries

delete the Dev-C++ file location there (probably only one file)... I would like to go through them one day and find the specific library that conflicts, but that seemed to help when I was messing around with Dev-C++
Last edited on
Pages: 12