undefined reference?

Hi, as the forum indicates I'm only just beginning to understand the depths of the gulf that is my ignorance on this subject (C++) and have stumbled across this error on my first attempt to code: [Linker error] undefined reference to `__cpu_features_init'

And this is my code to date:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
using namespace std;


int main()
{
    int skill[10], stat[7], statXP[7], advLevel=0, target; 
    for ( target=0 ; target<7 ; ++target ) stat[target]=0;//stat initalisation to 0
    for ( target=0 ; target<10 ; ++target ) skill[target]=0;//skill initalised to 0
    again://goto target
    cout << "Which skill do you wish to increase? (1-5)";
    cout << "enter 20 to finish";
    cin >> target;
    if (target>0&&target<11)
    {
       skill[target-1]++;
       switch (target)
       {
              case 1:
                   statXP[5]+=4, statXP[3]+=2;
                   if (statXP[5]=advLevel)
                   {
                      stat[5]++;
                      statXP[5]=0;
                      cout << "Agility Increase";
                   }
                   if (statXP[3]=advLevel)
                   {
                      stat[3]++;
                      statXP[3]=0;
                      cout << "Strength Increase";
                   }
                   break;

       }
       //advLevel updated
       for ( target=0 ; target<7 ; target++ )
        {
              advLevel += stat[target];
        }
       for ( target=0 ; target<10 ; target++ )
        {
              advLevel += skill[target];
        } 
       cout << "You are now level";
       cout << advLevel;
       cout << "\n With stats of:\n";
       for (int target=0; target<7; target++) cout << stat[target] << " ";
       cout << "\n";
       goto again;
    }
    return 0;
}


The switches have been abbreviated to save space, there are 5 of them all the same until I get at least this working.
I am using Dev-C++ as my compiler, and would greatly appreciate any advice on this error, please? :D
statXP[5]+=4, statXP[3]+=2;
i dont think you can do this. split it into 2 lines as
statXP[5]+=4;
statXP[3]+=2;

if (statXP[5]=advLevel)
this statement is logically wrong too. the correct one should be
if (statXP[5] == advLevel)

and your program will end in an infinite loop, coz of your goto again loop.
> statXP[5]+=4, statXP[3]+=2;
> i dont think you can do this.

Actually, that's perfectly legal syntax. Nevertheless, I agree with averageGuy that you should make it two statements instead of one.
Well I've made the modifications you have suggested (thanks for those) but am still getting the same error message. (buggerit)

UPDATE:
Just on a hunch I copy/paste this from the tutorials & tried to compile it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// i/o example

#include <iostream>
using namespace std;

int main ()
{
  int i;
  cout << "Please enter an integer value: ";
  cin >> i;
  cout << "The value you entered is " << i;
  cout << " and its double is " << i*2 << ".\n";
  return 0;
}


It failed with the same error.
Any ideas on just how difficult this will be to fix?
Last edited on
[Linker error] undefined reference to `__cpu_features_init'

hmm? maybe it aint the code? but the object linking has some problems.
I have no idea how to go around that though...

and try #include <iostream.h>
iostream sometimes gives errors. I think iostream is a C header, instead of a C++.. i think.

maybe copy pasta your code into a new project?

hope a pro comes along and sheds some light.

its one of the errors i've least encountered....
Last edited on
Sorry, I wasn't paying attention.

I googled your error and it sounds about what I thought: you have library clashes somewhere. Do you have more than one copy of MinGW installed? (The Dev-C++ IDE installs its own copy.)

Either delete the extra copy or make sure that when the Dev IDE runs that only Dev's MinGW lib/ directory is in the PATH variable.

Does this help?


@averageGuy: careful there. <iostream> is the standard C++ header. Anything else is pre-standard.
icic. didn't know that.

I was taught in school to use iostream.h

we did try to use iostream on our own and encountered some unfamiliar errors, that did not happen on .h

similarly on other libraries such as stdio and stdlib...
Yeah, older compilers will do that.

This site has a top-notch reference that will list all the ISO C++ standard includes and functions and classes etc. with the correct includes. The .h was deprecated, and <stdio.h> became <cstdio>, etc.

Newer compilers tend to put-up with older stuff, but since there wasn't a fixed standard for the older stuff, it is unreliable.

lol
ahhh ic ic~

now i know. haha learn something new everyday. =D
Yep you were spot on, after removing my other install of MinGW & Msys it compiled nicely!

Thanks very much
Topic archived. No new replies allowed.