Compiling Problem.

If you haven't seen my last post- I am new to C++. I'm having trouble compiling this simple program:

1
2
3
4
5
6
7
8
9
10
11
12
13

#include <iostream>

int main()
{
    using namespace std;
    int user;
    cin >> user;
    cout << "Enter Your Username:" <<endl;
    cout << "Welcome" << user;
    return 0;
}    


My compiler is telling me:

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


Whats going on guys?
I had to do a little research because this isn't related directly to C++, but your compiler.

Answer a few questions and maybe we can get to the bottom of this.

1) Which OS are you running? (I suspect Windows)
2) Which IDE are you using? (I suspect Code::Blocks)
3) Version?
4) Which compiler are you using? (I suspect MinGW)
5) Version?
I would like to add:

Declare using namespace std; after the pre-processor directives. That makes it gloabal, and you wont have to write it under every function.

use the cin>> function AFTER it displays the prompt, that way it displays the message, then allows the user to input.

Those are the only two changes I recommend. Other than that, Volatile Pulse is right on the money. After you answer his questions, we can help you out.
You must look at this the way the program reads it.
Top-bottom, jumping through functions, and all.
Try to avoid using namespaces, especially the standard. You don't want to pollute it.
Consider using the the prefix std:: instead.
Or at the very least, import only the functions you'll use.

1
2
3
using std::cin;
using std::cout;
using std::endl;


In this case, I'm using the prefix. I also changed the order, so you program should work properly now.

1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main()
{
    int user;
    std::cout << "Enter Your Username:" << std::endl;
    std::cin >> user;
    std::cout << "Welcome " << user;
    return 0;
}
Whilst this has been solved, I'd like to draw the OP's attention to a mistake he made that almost certainly cost him a lot of wasted time.

[Linker error] undefined reference to `__dyn_tls_init_callback'


This is not a compilation error. It is a LINKER error. If the linker gives an error, the compilation was successful and looking at the code will only work in the case of spelling errors such that function declarations (e.g in headers) don't match function definitions in libraries/other cpp files, but in those cases the linker error message will make it pretty obvious because it will complain about the function in question.
It means macro is not defined in header file/library.That may be because of currupt files.Have you tried to edit file or accidentally done it?
I was using Dev-Cpp. I got rid of that compiler and moved over to Visual C++ 2010- everything is working fine. Thanks for all the help!
Last edited on
And, just for good measure, I would think that you would want to change int user to string user. Unless you want your name to be a bunch of numbers that you input. To do this, you will have to include the string header file right under your <iostream> header:
1
2
#include <iostream>
#include <string> 
(strings work with letters, ints work with numbers, simply put.)
Last edited on
Thanks Bufflez, I took a note of that.
Topic archived. No new replies allowed.