Undefined error Reference to Std

Asked

Viewed 2,472 times

3

#include <iostream>
using namespace std;
int main()
{
  int nombre, carre ;
  cout << "Introduza un numero : " ;
  cin >> nombre ;
  carre = nombre * nombre ;
  cout << "A raiz quadrada est ; " << carre ;
}

When I compile with GCC:

gcc -Wall -Wextra -Werror -o calc_carre calc_carre.cpp

Obtenho:

calc_carre.cpp:(.text+0xe): Undefined Reference to std::cout' calc_carre.cpp:(.text+0x13): undefined reference to Std::basic_ostream >&Std::Operator<< >(Std::basic_ostream >&, char const*)' calc_carre.cpp:(.text+0x1f): Undefined Reference to std::cin' calc_carre.cpp:(.text+0x24): undefined reference toStd::istream::Operator>>(int&)' calc_carre.cpp:(.text+0x3a): Undefined Reference to std::cout' calc_carre.cpp:(.text+0x3f): undefined reference to Std::basic_ostream >&Std::Operator<< >(Std::basic_ostream >&, char const*)' calc_carre.cpp:(.text+0x4f): Undefined Reference to std::ostream::operator<<(int)' /tmp/cclJ9vPR.o: In function __static_initialization_and_destruction_0(int, int)': calc_carre.cpp:(.text+0x7d): Undefined Reference to std::ios_base::Init::Init()' calc_carre.cpp:(.text+0x8c): undefined reference toStd::ios_base::Init::~Init()' collect2: error: Ld returned 1 Exit status

In the C:

#include <stdio.h>
int main()
{
  int nombre, carre ;
  printf ("Introduza un numero") ;
  scanf ("%d", &nombre) ;
  carre = nombre * nombre ;
  printf (" A sua raiz quadrada é: %d, nombre) ;
}

When I compile I get no mistake, but look through your eyes: Foto do resultado do programa

  • Use #include <iostream> or #include<stdio. h>

  • Just do not include it in stackoverflow because the site does not leave but it is present

  • printf ("o seu quadrado é: ...", carre)

  • OK; Merci, just one more question How can I take the % that appears at the end I will send a photo for you to see, here is the link: https://goo.gl/photos/b1imFWZyo6k2mDmu7

1 answer

5


If you are using C++ with g++:

g++ -Wall -Wextra -Werror -o calc_carre calc_carre.cpp

If you want to gcc, which I don’t recommend, add the standard library:

gcc -lstdc++ -Wall -Wextra -Werror -o calc_carre calc_carre.cpp

In C there is error too:

#include <stdio.h>
int main() {
    int nombre, carre ;
    printf("Introduza un numero");
    scanf("%d", &nombre);
    carre = nombre * nombre;
    printf("A sua raiz quadrada é: %d", carre);
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

This code is obviously not calculating the square root, but then it’s just mathematics.

  • Thank you, you solved my problem, but in the C it does not give me the square root and is always the % present in the code

  • @Micaelandré because it is nombre and the right thing is carre as you did in c++. You can vote on all the site posts as well as you find useful. See [tour].

  • you can be more specific, this one speaking on Cout or the variable "Carre"::: Carre = Nombre * Nombre ; Creates a response with the modifications in the code please

  • @Micaelandré I edited.

  • Good idea to put on github

  • Okay; Merci, just one more question How can I take the % that appears at the end I will send a photo for you to see, here is the link: goo.Gl/photos/b1imFWZyo6k2mDmu7

  • As you can see running in two different places this does not appear, so your code is different

  • Yes it is different, follow the answers given, but if you want the completeness of the modified code I send

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.