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. C to C++ link error

C to C++ link error

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
7 Posts 2 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.
  • J Offline
    J Offline
    jimNLX
    wrote on last edited by
    #1

    I'm trying to convert a C program into a VC++ program and have everything compiling but I get a ton of Link errors. The error I get is: error LNK2005: ... already defined in ... I'm getting 230+ of these error and don't really know why. I've used #pragam once in all the headers, but still get this error. Any help on this error or converting C to C++? Thanks, Jim

    J 1 Reply Last reply
    0
    • J jimNLX

      I'm trying to convert a C program into a VC++ program and have everything compiling but I get a ton of Link errors. The error I get is: error LNK2005: ... already defined in ... I'm getting 230+ of these error and don't really know why. I've used #pragam once in all the headers, but still get this error. Any help on this error or converting C to C++? Thanks, Jim

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      Does the symbol correspond to a global variable? Something like this?

      int global;

      If so, try writing this in the .h file:

      extern int global;

      and then this in just one .cpp:

      int global=0;

      If this works and you're curious, I can try to explain the reason of your problem. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      J 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        Does the symbol correspond to a global variable? Something like this?

        int global;

        If so, try writing this in the .h file:

        extern int global;

        and then this in just one .cpp:

        int global=0;

        If this works and you're curious, I can try to explain the reason of your problem. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        J Offline
        J Offline
        jimNLX
        wrote on last edited by
        #3

        It's defined in a header with the extern key word.

        J 1 Reply Last reply
        0
        • J jimNLX

          It's defined in a header with the extern key word.

          J Offline
          J Offline
          jimNLX
          wrote on last edited by
          #4

          Here is what is defined in the header file: #ifdef ELABORATE_ALL_VARIABLES D2N_GLBL_STRUCT *D2N_GLBL; void D2N_GLBL_Elab( void ); void D2N_GLBL_Elab( void ) { D2N_GLBL = (D2N_GLBL_STRUCT *) calloc( sizeof(D2N_GLBL_STRUCT), 1); } #else extern D2N_GLBL_STRUCT *D2N_GLBL; #endif

          J J 2 Replies Last reply
          0
          • J jimNLX

            Here is what is defined in the header file: #ifdef ELABORATE_ALL_VARIABLES D2N_GLBL_STRUCT *D2N_GLBL; void D2N_GLBL_Elab( void ); void D2N_GLBL_Elab( void ) { D2N_GLBL = (D2N_GLBL_STRUCT *) calloc( sizeof(D2N_GLBL_STRUCT), 1); } #else extern D2N_GLBL_STRUCT *D2N_GLBL; #endif

            J Offline
            J Offline
            Joaquin M Lopez Munoz
            wrote on last edited by
            #5

            remove extern D2N_GLBL_STRUCT *D2N_GLBL;

            ??????? What is that remove thing? Could you explain what this file (is it a header?) is supposed to do, and what role does the macro ELABORATE_ALL_VARIABLES play? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

            1 Reply Last reply
            0
            • J jimNLX

              Here is what is defined in the header file: #ifdef ELABORATE_ALL_VARIABLES D2N_GLBL_STRUCT *D2N_GLBL; void D2N_GLBL_Elab( void ); void D2N_GLBL_Elab( void ) { D2N_GLBL = (D2N_GLBL_STRUCT *) calloc( sizeof(D2N_GLBL_STRUCT), 1); } #else extern D2N_GLBL_STRUCT *D2N_GLBL; #endif

              J Offline
              J Offline
              jimNLX
              wrote on last edited by
              #6

              I wish I knew, but I've never seen the program run before! I'm just having to port it to C++. The remove was something I forgot to remove when debugging. I think that this Macro does two different things based on what function is using it.

              J 1 Reply Last reply
              0
              • J jimNLX

                I wish I knew, but I've never seen the program run before! I'm just having to port it to C++. The remove was something I forgot to remove when debugging. I think that this Macro does two different things based on what function is using it.

                J Offline
                J Offline
                Joaquin M Lopez Munoz
                wrote on last edited by
                #7

                Ok. We can try to make an educated guess :) My opinion is that the header is used both for declaring things and for defining them. The second use is activated by ELABORATE_ALL_VARIABLES. Let's say the header is called a.h: then I guess you have to #include it like always everywhere except in the one file a.cpp, where you should have to write:

                // a.cpp
                #define ELABORATE_ALL_VARIABLES
                #include "a.h"
                ... // rest of stuff

                or, alternatively, define this macro for a.cpp in the properties section of the file (Fileview pane->right click on a.cpp->Settings->Preprocessor definitions). Good luck. Let me know if I can give you more assistance. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                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