Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Symbol Already defined...

Symbol Already defined...

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcsharpooptutorial
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Polite Programmer
    wrote on last edited by
    #1

    I am new to VC++ and MFC and not very much strong on it... I am having this problem. I have a dialog application which contains a ListView control. I want to have the column names in Urdu. so here what I do.

    TCHAR szCol7[] = {0x6A9, 0x644, 0x20, 0x646, 0x642, 0x637, 0x6C1, 0x20, 0x62C, 0x627, 0x62A} ;

    As my Dialog class, UrduAppDlg contains the ListView contorl, what I do is that place the above mentioned defination of Unicode string in UrduAppDlg.h file before the clas defination... Right? So far so good... But when I build the solution, I get the following error
    UrduTextAnalyzer error LNK2005: "wchar_t * szCol7" (?szCol7@@3PA_WA) already defined in UrduTextAnalyzer.obj
    But placing the same defination in UrduTextDlg.cpp does not create any problems and I get my job done... Please tell me what this phenomen is and why? Where should I put such data like col names? I cannot use resource compiler I think becuase Its not Unicode compatible I think... Please guide me in this regard. Mohsin Polite Programmer


    More Object Oriented then C#

    N S H 3 Replies Last reply
    0
    • P Polite Programmer

      I am new to VC++ and MFC and not very much strong on it... I am having this problem. I have a dialog application which contains a ListView control. I want to have the column names in Urdu. so here what I do.

      TCHAR szCol7[] = {0x6A9, 0x644, 0x20, 0x646, 0x642, 0x637, 0x6C1, 0x20, 0x62C, 0x627, 0x62A} ;

      As my Dialog class, UrduAppDlg contains the ListView contorl, what I do is that place the above mentioned defination of Unicode string in UrduAppDlg.h file before the clas defination... Right? So far so good... But when I build the solution, I get the following error
      UrduTextAnalyzer error LNK2005: "wchar_t * szCol7" (?szCol7@@3PA_WA) already defined in UrduTextAnalyzer.obj
      But placing the same defination in UrduTextDlg.cpp does not create any problems and I get my job done... Please tell me what this phenomen is and why? Where should I put such data like col names? I cannot use resource compiler I think becuase Its not Unicode compatible I think... Please guide me in this regard. Mohsin Polite Programmer


      More Object Oriented then C#

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      I guess you have accidently included the .cpp file instead of the .h file or you have forgotten to add #pragma once to the top of the .h file.


      Nibu thomas Software Developer Faqs by Michael dunn

      1 Reply Last reply
      0
      • P Polite Programmer

        I am new to VC++ and MFC and not very much strong on it... I am having this problem. I have a dialog application which contains a ListView control. I want to have the column names in Urdu. so here what I do.

        TCHAR szCol7[] = {0x6A9, 0x644, 0x20, 0x646, 0x642, 0x637, 0x6C1, 0x20, 0x62C, 0x627, 0x62A} ;

        As my Dialog class, UrduAppDlg contains the ListView contorl, what I do is that place the above mentioned defination of Unicode string in UrduAppDlg.h file before the clas defination... Right? So far so good... But when I build the solution, I get the following error
        UrduTextAnalyzer error LNK2005: "wchar_t * szCol7" (?szCol7@@3PA_WA) already defined in UrduTextAnalyzer.obj
        But placing the same defination in UrduTextDlg.cpp does not create any problems and I get my job done... Please tell me what this phenomen is and why? Where should I put such data like col names? I cannot use resource compiler I think becuase Its not Unicode compatible I think... Please guide me in this regard. Mohsin Polite Programmer


        More Object Oriented then C#

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        I think the reason is that szCol7 is defined in a header that is included in multiple .CPP files and thus defined multiple times. Use something like this instead: // In a .CPP file TCHAR szCol7[] = {0x6A9, 0x644, 0x20, 0x646, 0x642, 0x637, 0x6C1, 0x20, 0x62C, 0x627, 0x62A} ; // In a header file extern TCHAR szCol7[]; You include the header file into and .CPP file from which you want to access szCol7. Steve

        1 Reply Last reply
        0
        • P Polite Programmer

          I am new to VC++ and MFC and not very much strong on it... I am having this problem. I have a dialog application which contains a ListView control. I want to have the column names in Urdu. so here what I do.

          TCHAR szCol7[] = {0x6A9, 0x644, 0x20, 0x646, 0x642, 0x637, 0x6C1, 0x20, 0x62C, 0x627, 0x62A} ;

          As my Dialog class, UrduAppDlg contains the ListView contorl, what I do is that place the above mentioned defination of Unicode string in UrduAppDlg.h file before the clas defination... Right? So far so good... But when I build the solution, I get the following error
          UrduTextAnalyzer error LNK2005: "wchar_t * szCol7" (?szCol7@@3PA_WA) already defined in UrduTextAnalyzer.obj
          But placing the same defination in UrduTextDlg.cpp does not create any problems and I get my job done... Please tell me what this phenomen is and why? Where should I put such data like col names? I cannot use resource compiler I think becuase Its not Unicode compatible I think... Please guide me in this regard. Mohsin Polite Programmer


          More Object Oriented then C#

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          yes i agree with Nibu thomas i guess you have forgotten #pragma once in header file or change location szCol7 from header file

          S 1 Reply Last reply
          0
          • H Hamid Taebi

            yes i agree with Nibu thomas i guess you have forgotten #pragma once in header file or change location szCol7 from header file

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            #pragma once or not you can define an array twice in two compilation units. Try this for example. // Header "a.h" #pragma once char g_hello[] = "Hello";   // Header "b.h" #pragma once char g_hello[] = "Hello";   // File c.cpp #include "a.h" #include "b.h" This code will result in "error C2374: 'g_hello' : redefinition; multiple initialization". Steve

            H 1 Reply Last reply
            0
            • S Stephen Hewitt

              #pragma once or not you can define an array twice in two compilation units. Try this for example. // Header "a.h" #pragma once char g_hello[] = "Hello";   // Header "b.h" #pragma once char g_hello[] = "Hello";   // File c.cpp #include "a.h" #include "b.h" This code will result in "error C2374: 'g_hello' : redefinition; multiple initialization". Steve

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              yes I misread this error with another error but...

              P 1 Reply Last reply
              0
              • H Hamid Taebi

                yes I misread this error with another error but...

                P Offline
                P Offline
                Polite Programmer
                wrote on last edited by
                #7

                Thats right, I have #pragma once included at the top of my header, and I am including .h file not the .cpp. However, extern solution worked very well... But the question is that extern only is giving declaratin, not defination... is it? Then is any need to declare the arrays in the header file using extern keyword and then redefine the arrays in a cpp file where they are needed? Please explain a little logic behind this and what role the extern keyword has to play there? Polite Programmer


                More Object Oriented then C#

                J 1 Reply Last reply
                0
                • P Polite Programmer

                  Thats right, I have #pragma once included at the top of my header, and I am including .h file not the .cpp. However, extern solution worked very well... But the question is that extern only is giving declaratin, not defination... is it? Then is any need to declare the arrays in the header file using extern keyword and then redefine the arrays in a cpp file where they are needed? Please explain a little logic behind this and what role the extern keyword has to play there? Polite Programmer


                  More Object Oriented then C#

                  J Offline
                  J Offline
                  Justin Tay
                  wrote on last edited by
                  #8

                  extern tells your compiler that this symbol is defined elsewhere and not to worry about it if it can't find it in this compilation unit (object code). Basically it passes the problem to the linker. If you have more than one definition for this symbol in separate cpp files the linker will complain that the symbol is already defined. This is what will happen if you try to define your array in more than one cpp file. If you have no definition for this symbol in all your cpp files the linker will complain that it can't find the symbol. In certain cases where it is desirable to have the definition in the header file, you can use __declspec(selectany) to indicate to the linker that if it finds multiple symbols, to just pick one.

                  S 1 Reply Last reply
                  0
                  • J Justin Tay

                    extern tells your compiler that this symbol is defined elsewhere and not to worry about it if it can't find it in this compilation unit (object code). Basically it passes the problem to the linker. If you have more than one definition for this symbol in separate cpp files the linker will complain that the symbol is already defined. This is what will happen if you try to define your array in more than one cpp file. If you have no definition for this symbol in all your cpp files the linker will complain that it can't find the symbol. In certain cases where it is desirable to have the definition in the header file, you can use __declspec(selectany) to indicate to the linker that if it finds multiple symbols, to just pick one.

                    S Offline
                    S Offline
                    Stephen Hewitt
                    wrote on last edited by
                    #9

                    A good concise explanation. The only thing missing is to point out that __declspec(selectany) isn't portable; but I guess that would be obvious to most as it's a __declspec. Steve

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups