문제
이 코드를 컴파일하려고합니다.
#include <iostream>
#include <cstdlib>
using namespace std;
#define ARRAY_TAM 2
typedef int (*operacion)(int, int);
typedef const char* (*Pfchar)();
int suma(int, int);
int resta(int, int);
const char* descrSuma();
const char* descrResta();
const char* simbSuma();
const char* simbResta();
class OP
{
private:
public:
operacion op;
Pfchar descr;
Pfchar simb;
};
int main (int argv, char *argc[])
{
OP ArrayOP[ARRAY_TAM];
ArrayOP[0].op = suma;
ArrayOP[0].descr = descrSuma;
ArrayOP[1].op = resta;
ArrayOP[1].descr = descrResta;
int op1, op2;
unsigned int i;
char opcion;
bool fin = false;
while (fin != true)
{
cout << "CALCULADORA" << "\n";
cout << "===========" << "\n";
for (i = 0; (i < ARRAY_TAM); i++)
{
cout << i+1;
cout << ".- ";
cout << ArrayOP[i].descr() << "\n";
}
cout << i+1 << ".- " << "Salir" << endl;
cout << "Opcion: ";
cin >> opcion;
opcion = atoi(&opcion);
opcion--;
cout << (int)opcion << endl;
if ((opcion >= 0) && (opcion < ARRAY_TAM))
{
cout << "Operando 1: ";
cin >> op1;
cout << "Operando 2: ";
cin >> op2;
cout << "Resultado: op1 " << ArrayOP[opcion].simb()
<< " op2 = " << ArrayOP[opcion].op(op1, op2);
}
else if (opcion == ARRAY_TAM)
{
fin = true;
}
}
return 0;
}
int suma (int op1, int op2)
{return op1 + op2;}
int resta (int op1, int op2)
{return op1 - op2;}
const char* descrSuma()
{return "Suma";}
const char* descrResta()
{return "Resta";}
const char* simbSuma()
{return "+";}
const char* simbResta()
{return "-";}
IT는 작동하지만 GCC와 Debbugging 기호와 연결하는 데 많은 문제가 있으며 링크되지 않습니다 .-(
도움이 필요하다!
큰 링커 오류 :
Facon@Facon -Laptop : ~/Windows -MIS Documentos/Prog/C/Ejercicios/Pedirentero $ g ++ -o main main.o main.o : in function` _start ':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/i386/elf/start.s:65 :`_start '의 다중 정의
/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crt1.o:/build/buildd/eglibc-2.10.1/csu/ .. /sysdeps/i386/elf/start.s:65 :
여기에 처음 정의 된 main.o :(. Rodata+0x0) :`_fp_hw '의 다중 정의
/usr/lib/gcc/i486-linux-gnu/4.4.44.1/../../../lib/crt1.o :(.rodata+0x0) : 여기에서 먼저 main.o : in 기능
_fini': (.fini+0x0): multiple definition of
_fini '/usr/lib/gcc/i486-linux-gnu/4.4.44.1/../../../lib/crti.o :(.fini+0x0) : 여기에 먼저 정의 된 Main.o :( .Rodata+0x4) :`_io_stdin_used '의 다중 정의
/usr/lib/gcc/i486-linux-gnu/4.4.44.1/../../../lib/crt1.o :(.rodata.cst4+0x0) : 여기에서 먼저 main.o : 기능 중
__data_start': (.data+0x0): multiple definition of
__data_start '/usr/lib/gcc/i486-linux-gnu/4.4.44.1/../../../lib/crt1.o :(.data+0x0) : 여기에 먼저 정의 된 main.o : in 기능
__data_start': (.data+0x4): multiple definition of
__dso_handle '/usr/lib/gcc/i486-linux-gnu/4.4.1/crtbegin.o :(.data+0x0) : 여기에 먼저 정의 된 main.o : 내 기능
_init': (.init+0x0): multiple definition of
_init '/usr/lib/gcc/i486-linux-gnu/4.4.1/../../../../lib/crti.o :(.init+0x0) : 여기에서 먼저 정의되었습니다
/usr/lib/gcc/i486-linux-gnu/4.4.1/crtend.o :(.dtors+0x0) :`의 다중 정의dtor_end'main.o :(. dtors+0x4) : 여기에 처음 정의 됨
/usr/bin/ld : 경고 : .eh_frame_hdr 섹션을 만들 수 없습니다. /usr/bin/ld : main.o (.eh_frame)의 오류; no .eh_frame_hdr 테이블이 만들어집니다.
Collect2 : LD는 1 종료 상태를 반환했습니다
PD : 편집.
해결책
당신은 "... 작동합니다"라고 씁니다. 그러나 당신은 "... 링크와 관련된 문제"를 씁니다.
나는이 질문과 약간 혼란 스럽다.
- 연결에 문제가 있으면 문제가 있습니다 작동하지 않습니다 ...
- 그러나 그것이 효과가 있다면 당신은 당신입니다 가지고 있지 않습니다 연결 문제 ...
그래서 당신은 "컴파일하지만 링크 오류가 있습니다"라고 말하는 것 같아요?
그럴 경우 시도해 볼 수 있습니다.
g++ -g main.cpp -o main
대신에
gcc -g main.cpp -o main
편집 : ... 그리고하십시오 ~ 아니다 언급하다 main.o 명령 줄에서 =;)
편집 : 모든 것이 도움이되지 않는다면 G ++/GCC 설치에 문제가있을 수 있습니까?
우분투에서 시도 해주세요
sudo aptitude install build-essential
다른 팁
당신은 사용 했습니까? gcc
대신에 g++
?
만약에 gcc
C ++ 코드와 함께 사용되면 이상한 연결 오류가 발생합니다. C ++ 코드는 컴파일해야합니다 g++
.
편집하다: 당신이 제공 한 새로운 정보를 기반으로 당신이 실행중인 것을 봅니다. g++ -o main main.o main.o
.
대신 실행해야합니다. g++ -o main main.cpp