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. error LNK2019

error LNK2019

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++questionlearning
6 Posts 4 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I have an header file, where I have a function:

    #ifdef __cplusplus
    extern "C" {
    #endif
    ....
    struct_t* function_new(const struct_type_t* test);
    ...
    #ifdef __cplusplus
    } /* closing brace for extern "C" */
    #endif

    for this function I get 2 links errors:

    error LNK2019: unresolved external symbol _function_new referenced in function ....

    now, in cpp file, of course that I have the body of this function, but is not recognized at all ... if this body function is written in cpp, or if I would delete the body of this function, the error is exactly the same ... strange, no ? What could be the problem here, I am struggle to solve this error for days ...

    L P S 3 Replies Last reply
    0
    • _ _Flaviu

      I have an header file, where I have a function:

      #ifdef __cplusplus
      extern "C" {
      #endif
      ....
      struct_t* function_new(const struct_type_t* test);
      ...
      #ifdef __cplusplus
      } /* closing brace for extern "C" */
      #endif

      for this function I get 2 links errors:

      error LNK2019: unresolved external symbol _function_new referenced in function ....

      now, in cpp file, of course that I have the body of this function, but is not recognized at all ... if this body function is written in cpp, or if I would delete the body of this function, the error is exactly the same ... strange, no ? What could be the problem here, I am struggle to solve this error for days ...

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      For some reason the implementation file is not being built into your project. Once again we need more details in order to help you. I would suggest that you move to using the Visual Studio IDE to build your projects as it is easier to see why problems like this occur, and you also get a standard structure for your projects.

      1 Reply Last reply
      0
      • _ _Flaviu

        I have an header file, where I have a function:

        #ifdef __cplusplus
        extern "C" {
        #endif
        ....
        struct_t* function_new(const struct_type_t* test);
        ...
        #ifdef __cplusplus
        } /* closing brace for extern "C" */
        #endif

        for this function I get 2 links errors:

        error LNK2019: unresolved external symbol _function_new referenced in function ....

        now, in cpp file, of course that I have the body of this function, but is not recognized at all ... if this body function is written in cpp, or if I would delete the body of this function, the error is exactly the same ... strange, no ? What could be the problem here, I am struggle to solve this error for days ...

        P Offline
        P Offline
        phil o
        wrote on last edited by
        #3

        The name function_new in your header file and the name **_**function_new reported by the linker do not match. Maybe the start of a track to explore here?

        while (!(success = Try()));

        L 1 Reply Last reply
        0
        • P phil o

          The name function_new in your header file and the name **_**function_new reported by the linker do not match. Maybe the start of a track to explore here?

          while (!(success = Try()));

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          The compiler adds the underscore at the beginning of function names in object files.

          1 Reply Last reply
          0
          • _ _Flaviu

            I have an header file, where I have a function:

            #ifdef __cplusplus
            extern "C" {
            #endif
            ....
            struct_t* function_new(const struct_type_t* test);
            ...
            #ifdef __cplusplus
            } /* closing brace for extern "C" */
            #endif

            for this function I get 2 links errors:

            error LNK2019: unresolved external symbol _function_new referenced in function ....

            now, in cpp file, of course that I have the body of this function, but is not recognized at all ... if this body function is written in cpp, or if I would delete the body of this function, the error is exactly the same ... strange, no ? What could be the problem here, I am struggle to solve this error for days ...

            S Offline
            S Offline
            Stefan_Lang
            wrote on last edited by
            #5

            Some things that might have gone wrong: 1. You did not link the object file containing the implementation to your program. Check your build options to make sure it's there. 2. The declaration in your header does not match your implementation. Make sure there is no typo, the argument type and number matches, and ... 3. ... that it's compiled as C code. You mentioned a cpp file: if your compiler deducts how to compile a file by it's suffix, it may have compiled a C++ instead of a C function! In that case the linker won't find it. You could check your compiler's documentation for an option to force compilation as C. Alternately, just to find out you're on the right track, try removing 'extern "C"' in your header to find out whether that's actually the cause. P.S.: Here's a good site pointing out all the details you need to watch out for when mixing C++ and C: How to mix C and C++[^]

            GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

            _ 1 Reply Last reply
            0
            • S Stefan_Lang

              Some things that might have gone wrong: 1. You did not link the object file containing the implementation to your program. Check your build options to make sure it's there. 2. The declaration in your header does not match your implementation. Make sure there is no typo, the argument type and number matches, and ... 3. ... that it's compiled as C code. You mentioned a cpp file: if your compiler deducts how to compile a file by it's suffix, it may have compiled a C++ instead of a C function! In that case the linker won't find it. You could check your compiler's documentation for an option to force compilation as C. Alternately, just to find out you're on the right track, try removing 'extern "C"' in your header to find out whether that's actually the cause. P.S.: Here's a good site pointing out all the details you need to watch out for when mixing C++ and C: How to mix C and C++[^]

              GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

              _ Offline
              _ Offline
              _Flaviu
              wrote on last edited by
              #6

              "2. The declaration in your header does not match your implementation. Make sure there is no typo, the argument type and number matches, and ..." That was the problem. Thank you all of you !

              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