Jump to content

Odd compiler error

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
Kay, so I was trying to compile code i'm almost 100% certain works, I click compile and get below errors;

Quote

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

So, I thought perhaps it was due to using Dev-C++ on Windows Vista. The code is an example of scopes

/*

 * scope is a term used to define the visibility and lifetime

 * of declared variable or function

 * visibility refers ot the question from what part of the code may the variable

 * be accessed?

 * lifetime asks how long will it exist

 * a block is a unit of code surrounded by parentheses

 * a function is just blocks named

 * you can have blocks within a block

 * blocks are loaded onto the stack

 * variables can only be declared at the beginning of a block

 * variables are only visible in the block it is declared

 * or any of its sub-blocks

 * when the block is completed, variable is destroyed

 * scope of a global variable is all blocks

 * two vars can be declared with same name

 * as long as they aren't in the same block

 */


#include <stdio.h>


int   a = 1;


int funct()

{

       int  b = 2;

       

       a = b;

       

       { /* begin a block */

            int c = 3;

            

            a = b + c;

       }

       

       a = b;

       

       { /* begin another block */

       

         int d = 4;

         

         a = b + d;

       }

       

       a = b;

}


main()

{

      int  e = 5;

      

      a = e;

      

      { /* begin a block */

         int     f = 6;

         

         a = e + f;

         

         {

             int g = 7;

             

             a = e + f + g;

         }

         

         a = e + f;

      }

      

      a = e;

}


Posted Image

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
My guess is that there's a problem with your stdio.h.

Is there a reason for not using iostream? (C vs C++?)
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
Only that i'm more comfortable with C
Posted Image

#4
deltatux

deltatux

    Newbie

  • Members
  • PipPip
  • 17 posts
well, you don't even have any IO operations in this source code.

Try declaring your main as int main () and then return 0; within the function. Sometimes that fixes weird issues depending on compiler.

deltatux

#5
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
I tried it in dev c++ on xp and also on tcc, and it compiled. What version of dev is that?

Edited by fread, 23 February 2009 - 02:50 PM.
spelling/grammer

Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#6
Phoenixz

Phoenixz

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts

deltatux said:

well, you don't even have any IO operations in this source code.

Try declaring your main as int main () and then return 0; within the function. Sometimes that fixes weird issues depending on compiler.

deltatux

It's C, not C++, and I use v4.9.9.2
Posted Image

#7
deltatux

deltatux

    Newbie

  • Members
  • PipPip
  • 17 posts

Phoenixz said:

It's C, not C++, and I use v4.9.9.2

What I replied is C. lol, I do C coding as well.

deltatux

#8
fread

fread

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 787 posts
I use the same thing and it compiles.
Try this: YouTube - How to install Dev-C++ on Windows Vista
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:

#9
deltatux

deltatux

    Newbie

  • Members
  • PipPip
  • 17 posts

fread said:

I use the same thing and it compiles.
Try this: YouTube - How to install Dev-C++ on Windows Vista

usually, I'd stick to GCC when compiling on any machine for C code. For GCC on Windows, I use MinGW.

deltatux

#10
deltatux

deltatux

    Newbie

  • Members
  • PipPip
  • 17 posts
ok, I just ran your program and modified it a little to print the 'a' variable. It works perfectly on GCC. However, since I don't have the Windows installed yet, I used my college's UNIX servers to compile and ran it.

Quote

<username>@matrix:~/devel/c> gcc -o test1 test1.c
<username>@matrix:~/devel/c> ./test1
a = 5

deltatux

#11
TkTech

TkTech

    The Crazy One

  • Moderators
  • 1,396 posts
*cough*
__cpu_features_init is a function defined in the crt, which is essentially bootstrap code added to every executable to set it up for the host environment. This is a well-known problem with MingW, caused by library collisions. Make sure you have nothing from a previous version installed.