Fatal error lnk1169 обнаружен многократно определенный символ один или более

fatal error LNK1169: обнаружен многократно определенный символ - один или более C++ Решение и ответ на вопрос 513515

unreal

0 / 0 / 1

Регистрация: 26.02.2012

Сообщений: 118

1

06.03.2012, 18:36. Показов 57256. Ответов 9

Метки нет (Все метки)


код который показан снизу я компилировал в двух программах на visual c++ и dev c++
в dev c++ всё прошло успешно но в visual c++ выдаёт ошибку «fatal error LNK1169: обнаружен многократно определенный символ — один или более».. как решить это ?

C++
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
 int main()
 {
 int c=7;
 int& d = c; 
 cout <<c;
 system("pause");
 return 0;    
 
 }

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



Эксперт С++

5826 / 3477 / 358

Регистрация: 08.02.2010

Сообщений: 7,448

06.03.2012, 18:45

2

unreal, скорее всего, у тебя в проекте есть еще файл, в котором определена функция main. Выложи сообщение об ошибке полностью



1



unreal

0 / 0 / 1

Регистрация: 26.02.2012

Сообщений: 118

06.03.2012, 20:33

 [ТС]

3

даже так

C++
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
 int main()
 {
 int c=7;
 //int& d = c; 
 cout << c << endl;
 system("pause");
 return 0;    
 
 }

пишеть ошибку.
MSVCRTD.lib(crtexew.obj) : error LNK2019: ссылка на неразрешенный внешний символ _WinMain@16 в функции ___tmainCRTStartup
visual studioc++azadDebugazad.exe : fatal error LNK1120: 1 неразрешенных внешних элементов

что делать прошу помогите



0



5225 / 3197 / 362

Регистрация: 12.12.2009

Сообщений: 8,101

Записей в блоге: 2

06.03.2012, 20:50

4

unreal, ты проект ни того типа создал. Создай консольное приложение.



1



0 / 0 / 1

Регистрация: 26.02.2012

Сообщений: 118

06.03.2012, 20:52

 [ТС]

5

спс. а какое их отличие ?



0



5225 / 3197 / 362

Регистрация: 12.12.2009

Сообщений: 8,101

Записей в блоге: 2

06.03.2012, 20:54

6

Разные ключи компиляции для консольного и неконсольного приложения.



1



0 / 0 / 1

Регистрация: 26.02.2012

Сообщений: 118

06.03.2012, 21:04

 [ТС]

7

почему в visual c++ не откроет <iostream.h> ?



0



5225 / 3197 / 362

Регистрация: 12.12.2009

Сообщений: 8,101

Записей в блоге: 2

07.03.2012, 08:09

8

Цитата
Сообщение от unreal
Посмотреть сообщение

почему в visual c++ не откроет <iostream.h> ?

Потому что это старый стандарт, сейчас пишут просто <iostream>



1



-=ЮрА=-

Заблокирован

Автор FAQ

07.03.2012, 16:35

9

Цитата
Сообщение от unreal
Посмотреть сообщение

int& d = c;

Цитата
Сообщение от unreal
Посмотреть сообщение

_WinMain@16 в функции ___tmainCRTStartup
visual studioc++azadDebugazad.exe : fatal error LNK1120: 1 неразрешенных внешних элементов

— это означает что по всей видимости ты выбрал тим проекта Win32 вместо Console aplication. Просто создай по новой проект и выбери правильный тип проекта



1



1 / 1 / 0

Регистрация: 05.11.2012

Сообщений: 8

07.11.2012, 20:13

10

Цитата
Сообщение от Nameless One
Посмотреть сообщение

unreal, скорее всего, у тебя в проекте есть еще файл, в котором определена функция main. Выложи сообщение об ошибке полностью

У меня вообще не выдает ошибку только, если 1 файл в проекте.



0



I have 3 files:

SilverLines.h
SilverLines.cpp
main.cpp

At SilverLines.cpp I have:

#include "SilverLines.h."

When I don’t do:

#include "SilverLines.h"

at the main.cpp, everything is just fine. The project compiles.

But when I do:

#include "SilverLines.h"

in the main.cpp (Which i need to do), i get these 2 errors:

fatal errors

What’s the problem?

> edit:

As you requested, this is the entire *.h code:

#ifndef SILVER_H
#define SILVER_H

#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <string>
#include <map>

using namespace std;

typedef unsigned short int u_s_int;

map<string /*phone*/,string /*company*/> companies; // a map of a phone number and its     company
string findCompany(const string& phoneNum); //Given a phone number, the function     returns the right company

//The Abstract Client Class:

class AbsClient //Abstract Client Class
{
protected:
//string phone_number;
int counter; //CALL DURATION TO BE CHARGED
double charge;
public:
string phone_number; //MOVE TO PROTECTED LATER
void setCharge(double ch) {charge=ch;}
void setCoutner(int count) {counter=count;}
AbsClient(string ph_num): phone_number(ph_num),counter(0), charge(0.0) {} //c'tor     that must be given a phone#.
                                                                            //Initializes the counter and the charge to 0.
virtual void registerCall(string /*phone#*/, int /*minutes*/) = 0; //make a call     and charge the customer
void printReport(string /*phone#*/) const; //prints a minutes report
};

//The Temporary Client Class:

class TempClient : public AbsClient //TempClient class (NO DISCOUNT!) 2.3 NIS PER MINUTE, inherits from ABS
{
private:
string company;
public:
//string company;
TempClient(string ph_num, string cmp_name): AbsClient(ph_num), company(cmp_name) {}
virtual void registerCall(string /*phone#*/, int /*minutes*/); //make a call and     charge the customer
//virtual void printReport(string phone) const {cout << "the number of minutes: " << this->counter << endl;}
};

//The REgistered Client Class:

class RegisteredClient : public AbsClient //RegisteredClient, 10% DISCOUNT! , inherits from ABS
{
protected:
string name;
string id;
long account; //ACCOUNT NUMBER
private:
static const int discount = 10; //STATIC DISCOUNT OF 10% FOR ALL Registered Clients
public:
RegisteredClient(string ph_num, string n, string i, long acc_num):     AbsClient(ph_num), name(n) , id(i) , account(acc_num) {}
virtual void registerCall(string /*phone#*/, int /*minutes*/); //make a call and     charge the customer
//virtual void printReport(string /*phone#*/) const {cout << "the number of     minutes: " << this->counter << endl;}
};

//The VIP Client Class

class VIPClient : public RegisteredClient //VIP Client! X% DISCOUNT! also, inherits from RegisteredClient
{
private: //protected?
int discount; //A SPECIAL INDIVIDUAL DISCOUTN FOR VIP Clients
public:
VIPClient(string ph_num, string n, string i, long acc_num, int X):     RegisteredClient(ph_num,n,i,acc_num), discount(X) {}
virtual void registerCall(string /*phone#*/, int /*minutes*/); //make a call and     charge the customer
//virtual void printReport(string /*phone#*/) const {cout << "the number of     minutes: " << this->counter << endl;}
};

//The SilverLines (the company) class

class SilverLines // The Company Class
{
protected:
vector<AbsClient*> clients;
vector<string> address_book; //DELETE
public:
//static vector<AbsClient*> clients;
//SilverLines();
void addNewClient(string /*phone#*/);
void addNewClient(string /*phone#*/, string /*name*/ , string /*id*/ , u_s_int     /*importance lvl*/ , long /*account#*/);
void registerCall(string /*phone#*/ , int /*call duration*/);
void resetCustomer(string /*phone#*/); //given a phone#, clear the appropriate     customer's data ('charge' and 'counter')
void printReport(string /*phone#*/) const;

~SilverLines(){
    vector<AbsClient*>::iterator it;
    for(it = clients.begin(); it != clients.end(); ++it)
        delete(*it);
}
};

#endif

paercebal’s Answer:

Your code has multiple issues (the

using namespace std;

for one), but the one failing the compilation is the declaration of a global variable in a header:

map<string /*phone*/,string /*company*/> companies;

I’m quite sure most of your sources (main.cpp and SilverLines.cpp, at least) include this header.

You should define your global object in one source file:

// SilverLines.h

extern map<string /*phone*/,string /*company*/> companies;

and then declare it (as extern) in the header:

// global.cpp

extern map<string /*phone*/,string /*company*/> companies;

Hi ULARbro,

Welcome to MSDN forum.

>> Fatal error
LNK1169

## This error is preceded by error
LNK2005. Generally, this error means you have broken the one definition rule, which allows only one definition for any used template, function, type, or object in a given object file, and only one definition across the entire executable for externally visible
objects or functions.

Do you meet this error when you are running test project? And does your project build/debug well without any error?

According to the official document,  You could refer to below possible causes and for
solutions please refer to this link
Possible causes and solutions.

(1) Check if one of your header file defines a variable and maybe include this header file in more than one source file in your project.

(2) This error can occur when a header file defines a function that isn’t inline. If you include this header file in more than one source file, you get multiple definitions of the function in the executable.

(3) This error can also occur if you define member functions outside the class declaration in a header file.

(4) This error can occur if you link more than one version of the standard library or CRT.

(5) This error can occur if you mix use of static and dynamic libraries when you use the /clr option

(6) This error can occur if the symbol is a packaged function (created by compiling with /Gy)
and it was included in more than one file, but was changed between compilations. 

(7)
This error can occur if the symbol is defined differently in two member objects in different libraries, and both member objects are used. One way to fix this issue when the libraries are statically linked is to use the member object from only one library,
and include that library first on the linker command line. 

(8)
This error can occur if an extern const variable is defined twice, and has a different value in each definition. 

(9) This error can occur if you use uuid.lib in combination with other .lib files that define GUIDs (for example, oledb.lib and adsiid.lib).

There are some similar issues and maybe helpful.

LNK1169 and LNK2005 Errors.

Fatal error LNK1169: one or more multiply defined symbols found in game programming.

Fatal error LNK1169: one or more multiply defined symbols found.

Hope all above could help you.

Best Regards,

Tianyu


MSDN Community Support
Please remember to click «Mark as Answer» the responses that resolved your issue, and to click «Unmark as Answer» if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.

  • Proposed as answer by

    Friday, December 13, 2019 9:31 AM

Hi ULARbro,

Welcome to MSDN forum.

>> Fatal error
LNK1169

## This error is preceded by error
LNK2005. Generally, this error means you have broken the one definition rule, which allows only one definition for any used template, function, type, or object in a given object file, and only one definition across the entire executable for externally visible
objects or functions.

Do you meet this error when you are running test project? And does your project build/debug well without any error?

According to the official document,  You could refer to below possible causes and for
solutions please refer to this link
Possible causes and solutions.

(1) Check if one of your header file defines a variable and maybe include this header file in more than one source file in your project.

(2) This error can occur when a header file defines a function that isn’t inline. If you include this header file in more than one source file, you get multiple definitions of the function in the executable.

(3) This error can also occur if you define member functions outside the class declaration in a header file.

(4) This error can occur if you link more than one version of the standard library or CRT.

(5) This error can occur if you mix use of static and dynamic libraries when you use the /clr option

(6) This error can occur if the symbol is a packaged function (created by compiling with /Gy)
and it was included in more than one file, but was changed between compilations. 

(7)
This error can occur if the symbol is defined differently in two member objects in different libraries, and both member objects are used. One way to fix this issue when the libraries are statically linked is to use the member object from only one library,
and include that library first on the linker command line. 

(8)
This error can occur if an extern const variable is defined twice, and has a different value in each definition. 

(9) This error can occur if you use uuid.lib in combination with other .lib files that define GUIDs (for example, oledb.lib and adsiid.lib).

There are some similar issues and maybe helpful.

LNK1169 and LNK2005 Errors.

Fatal error LNK1169: one or more multiply defined symbols found in game programming.

Fatal error LNK1169: one or more multiply defined symbols found.

Hope all above could help you.

Best Regards,

Tianyu


MSDN Community Support
Please remember to click «Mark as Answer» the responses that resolved your issue, and to click «Unmark as Answer» if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.

  • Proposed as answer by

    Friday, December 13, 2019 9:31 AM

Hi ULARbro,

Welcome to MSDN forum.

>> Fatal error
LNK1169

## This error is preceded by error
LNK2005. Generally, this error means you have broken the one definition rule, which allows only one definition for any used template, function, type, or object in a given object file, and only one definition across the entire executable for externally visible
objects or functions.

Do you meet this error when you are running test project? And does your project build/debug well without any error?

According to the official document,  You could refer to below possible causes and for
solutions please refer to this link
Possible causes and solutions.

(1) Check if one of your header file defines a variable and maybe include this header file in more than one source file in your project.

(2) This error can occur when a header file defines a function that isn’t inline. If you include this header file in more than one source file, you get multiple definitions of the function in the executable.

(3) This error can also occur if you define member functions outside the class declaration in a header file.

(4) This error can occur if you link more than one version of the standard library or CRT.

(5) This error can occur if you mix use of static and dynamic libraries when you use the /clr option

(6) This error can occur if the symbol is a packaged function (created by compiling with /Gy)
and it was included in more than one file, but was changed between compilations. 

(7)
This error can occur if the symbol is defined differently in two member objects in different libraries, and both member objects are used. One way to fix this issue when the libraries are statically linked is to use the member object from only one library,
and include that library first on the linker command line. 

(8)
This error can occur if an extern const variable is defined twice, and has a different value in each definition. 

(9) This error can occur if you use uuid.lib in combination with other .lib files that define GUIDs (for example, oledb.lib and adsiid.lib).

There are some similar issues and maybe helpful.

LNK1169 and LNK2005 Errors.

Fatal error LNK1169: one or more multiply defined symbols found in game programming.

Fatal error LNK1169: one or more multiply defined symbols found.

Hope all above could help you.

Best Regards,

Tianyu


MSDN Community Support
Please remember to click «Mark as Answer» the responses that resolved your issue, and to click «Unmark as Answer» if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
MSDN Support, feel free to contact MSDNFSF@microsoft.com.

  • Proposed as answer by

    Friday, December 13, 2019 9:31 AM


Recommended Answers

Please use code tags instead, and watch spaces like in using namespace or else if .

#include<iostream>

using namespace std;

int main()
{
   int age;
   char sex;

   cout<<"please input your age:";

   cout<<"please input your sex (M/F):";
   cin>> age;
   cin>> sex;
   if ( age < 100 …

Jump to Post

The same program works fine with me.
Which OS and compiler (version) are u using?

Jump to Post

There must be some information that you can see that you’re not telling us. How did you set up the project? Are there other files in it? Etc.?

Jump to Post

You can have more files, but as the linker seems to be telling you, you can’t have the same thing defined in more than one place. I don’t suppose you’d care to post all the relevant code?

Jump to Post

All 13 Replies

Member Avatar

16 Years Ago

Please use code tags instead, and watch spaces like in using namespace or else if .

#include<iostream>

using namespace std;

int main()
{
   int age;
   char sex;

   cout<<"please input your age:";

   cout<<"please input your sex (M/F):";
   cin>> age;
   cin>> sex;
   if ( age < 100 )
   {
      cout<<"you are pretty young!n";
   }
   else if ( age ==100 && sex == 'm' )
   {
      cout<<"you are pretty old,and you are male!n";
   }
   else if ( age ==100 && sex == 'f' )
   {
      cout<<"you are pretty old, and u r a female!n";
   }
   else
   {
      cout<<"You are relly old!n";
   }
}

Any problem with this?

Member Avatar

16 Years Ago

Thanks for your reply.But still after took care of spaces,it displays that same error.Please help me.I am new to programming.

#include<iostream>
usingnamespace std;
 
int main() 
{
int age; 
char sex;
 
cout<<"please input your age:"; 
 
cout<<"please input your sex (M/F):";
cin>> age; 
cin>> sex;

if (age < 100){ 
cout<<"you are pretty young!n";
}else if (age == 100 && sex == 'm'){
cout<<"you are pretty old,and you are male!n";
}else if (age == 100 && sex == 'f'){
cout<<"you are pretty old, and u r a female!n";
}else{
cout<<"You are relly old!n";
}
}

Also,i don’t know,how to give programs in code.I used

Member Avatar


~s.o.s~

2,560



Failure as a human



Team Colleague



Featured Poster


16 Years Ago

The same program works fine with me.
Which OS and compiler (version) are u using?

Member Avatar

16 Years Ago

OS-windows.XP

Compiler-Microsoft VC++ 2005 enterprise edition

Please help me.I couldn’t able to correct that problem.

Member Avatar

16 Years Ago

There must be some information that you can see that you’re not telling us. How did you set up the project? Are there other files in it? Etc.?

Member Avatar

16 Years Ago

Yes,the project has 2 more files with it.I thought in one project we can place more files.

Thanks for the reply and help me.How can i run this file when more that one file is stored in same project.

Member Avatar

16 Years Ago

You can have more files, but as the linker seems to be telling you, you can’t have the same thing defined in more than one place. I don’t suppose you’d care to post all the relevant code?

Member Avatar

16 Years Ago

This is the full error message

Ex2agesex.obj : error LNK2005: _main already defined in Ex1Sum.obj
Ex3currencydollar.obj : error LNK2005: _main already defined in Ex1Sum.obj
C:Documents and SettingsMohan.RBCHRIT7My DocumentsVisual Studio 2005ProjectsOwnProgramsDebugOwnPrograms.exe : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at «file://c:Documents and SettingsMohan.RBCHRIT7My DocumentsVisual Studio 2005ProjectsOwnProgramsDebugBuildLog.htm»
OwnPrograms — 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How would i set some file as main to run in VC++

Member Avatar

16 Years Ago

Well there you go. You’ve got main defined in more than one file. You can only have one main . Just like the messages are saying. You need a single entry point to your program — decide where it should be.

And again, if you want help with code, it is highly advisable that you post the code you want help with.

Member Avatar

16 Years Ago

Dave thanks for your help and apologize for not asking my question properly.I thought that fatal error would be the problem for my program.

Member Avatar

16 Years Ago

My first program in a project is

#define _CRT_SECURE_NO_DEPRECATE//to take of scanf deprecated warning
#include<stdio.h>
#include<math.h>
//int main()
{
int a,b;
double aSquare,bSquare,sumOfSquare;
printf("input first numbern");
scanf("%d",&a);
printf("input second numbern");
scanf("%d",&b);
printf("sum %dn",a+b);
printf("average %dn",(a+b)/2);
aSquare=sqrt(a);
bSquare=sqrt(b);
sumOfSquare=aSquare+bSquare;
printf("sumOfSquare %fn",sumOfSquare);
}

As you told i have taken off main from it.and my second file is

#include <iostream>
using namespace std;
int main() 
{
int age; 
char sex;
 
cout<<"please input your age:"; 

cout<<"please input your sex (M/F):";
cin>> age; 
cin>> sex;
//cin.ignore(); 
if (age < 100){ 
cout<<"you are pretty young!n";
}else if (age == 100 && sex == 'm'){
cout<<"you are pretty old,and you are male!n";
}else if (age == 100 && sex == 'f'){
cout<<"you are pretty old, and u r a female!n";
}else{
cout<<"You are relly old!n";
}
// cin.get();
}

how can i call the first program in the second one.Displaying two programs output in second file.Please help me.

Member Avatar

16 Years Ago

Make it a function called something other than main , then call it from the other code.

Member Avatar

15 Years Ago

Thanks Dave. Your answer solved my problem as well.


Reply to this topic

Be a part of the DaniWeb community

We’re a friendly, industry-focused community of developers, IT pros, digital marketers,
and technology enthusiasts meeting, networking, learning, and sharing knowledge.

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Fatal error lnk1169 one or more multiply defined symbols found
  • Fatal error lnk1168 не удается открыть exe для записи
  • Fatal error lnk1136 недопустимый или поврежденный файл
  • Fatal error lnk1136 invalid or corrupt file
  • Fatal error lnk1120 неразрешенных внешних элементов

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии