Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

  • 3 odgovora
  • 1.854 pregleda

Najnovija ↓

Linker error - multiple definition 20.02.2009. u 15:00 · pre 215 meseci
izmenjeno 1 put, poslednji put kish 20.02.2009. u 15:17
  1. kish20.02.2009. u 15:17zapis iz teksta poruke
#1
Dakle, projekat ima sledecu strukturu:
main.cpp:
Code:

#include <iostream>
#include "test1.h"
#include "test2.h"
using namespace std;

int main()
{
    set();
    cout << "testint = " << testint << endl;
    return 0;
}


test1.h:
Code:

#ifndef TEST1_H
#define TEST1_h

void set();

#endif


test1.cpp:
Code:

#include "test1.h"
#include "test2.h"

void set() {
    testint=1;
}


test2.h:
Code:

#ifndef TEST2_H
#define TEST2_H

int testint;

#endif


Pri kompajliranju dobijam sledecu gresku:
Code:

Compiling: main.cpp
Linking console executable: C:\Trash\coding\c++\htest\console.exe
.objs\main.o:main.cpp:(.bss+0x0): multiple definition of `testint'
.objs\test1.o:test1.cpp:(.bss+0x0): first defined here
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 2 seconds)


Izgleda da kompajler pokusava dva puta da definise promenjivu testint, medjutim TEST2_H bi bas to trebao da spreci. U cemu je tacno problem? Unapred hvala.
EDIT: Sad vidim da ima i poseban podforum za c++. Nek se tema prebaci na svoje mesto. Sorry.
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme