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

Link error

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

    I have a class on a library on the file Libr.h/.cpp I build a doc/view app. I link the header in Doc.h using #include "Libr.h", and the code is pasted in Doc.cpp using #include "Libr.cpp". View knows that the library exist because in View.h I have #include "Doc.h". So I have some code that use the library in Doc.pp and View.cpp. But the problem is: Doc.cpp OK View.cpp: Link error LNK2019 (functions not finded when link: but no problems when compile) So I tried to past #include "Libr.cpp" in View.cpp, and then: Doc.cpp: Link error LNK2019 View.cpp OK Damn! And this appens only with some functions of the library, and strange thing is that this functions are very very similar to other functions that haven't got any problem!! Can anybody help me?? (sorry for the long message)

    Have a nice code day ;)

    P T V 3 Replies Last reply
    0
    • R Russell

      I have a class on a library on the file Libr.h/.cpp I build a doc/view app. I link the header in Doc.h using #include "Libr.h", and the code is pasted in Doc.cpp using #include "Libr.cpp". View knows that the library exist because in View.h I have #include "Doc.h". So I have some code that use the library in Doc.pp and View.cpp. But the problem is: Doc.cpp OK View.cpp: Link error LNK2019 (functions not finded when link: but no problems when compile) So I tried to past #include "Libr.cpp" in View.cpp, and then: Doc.cpp: Link error LNK2019 View.cpp OK Damn! And this appens only with some functions of the library, and strange thing is that this functions are very very similar to other functions that haven't got any problem!! Can anybody help me?? (sorry for the long message)

      Have a nice code day ;)

      T Offline
      T Offline
      tuxyboy
      wrote on last edited by
      #2

      #include "Libr.cpp" is wrong. Include Libr.h in your Doc.h & include Doc.h in your Doc.cpp

      P 1 Reply Last reply
      0
      • R Russell

        I have a class on a library on the file Libr.h/.cpp I build a doc/view app. I link the header in Doc.h using #include "Libr.h", and the code is pasted in Doc.cpp using #include "Libr.cpp". View knows that the library exist because in View.h I have #include "Doc.h". So I have some code that use the library in Doc.pp and View.cpp. But the problem is: Doc.cpp OK View.cpp: Link error LNK2019 (functions not finded when link: but no problems when compile) So I tried to past #include "Libr.cpp" in View.cpp, and then: Doc.cpp: Link error LNK2019 View.cpp OK Damn! And this appens only with some functions of the library, and strange thing is that this functions are very very similar to other functions that haven't got any problem!! Can anybody help me?? (sorry for the long message)

        Have a nice code day ;)

        P Offline
        P Offline
        Prakash Nadar
        wrote on last edited by
        #3

        you need to add the lib file to the link tab in the project settings.


        -Prakash

        R 1 Reply Last reply
        0
        • T tuxyboy

          #include "Libr.cpp" is wrong. Include Libr.h in your Doc.h & include Doc.h in your Doc.cpp

          P Offline
          P Offline
          Prakash Nadar
          wrote on last edited by
          #4

          tuxyboy wrote:

          #include "Libr.cpp" is wrong.

          is actually not wrong but poor way of programming.


          -Prakash

          1 Reply Last reply
          0
          • P Prakash Nadar

            you need to add the lib file to the link tab in the project settings.


            -Prakash

            R Offline
            R Offline
            Russell
            wrote on last edited by
            #5

            Sorry, but I prefere the simple:sigh: use of #include. I have good news: In libr.h/.cpp there was a lot of inline functions, well... I modify the files cutting that word and now everything is running. But I want to use inline: I need it!! So, do you know if it is possible that the linker doesn't like the keyword inline or if the use of 'inline' could give this error?? Thaks

            Have a nice code day ;)

            P 2 Replies Last reply
            0
            • R Russell

              Sorry, but I prefere the simple:sigh: use of #include. I have good news: In libr.h/.cpp there was a lot of inline functions, well... I modify the files cutting that word and now everything is running. But I want to use inline: I need it!! So, do you know if it is possible that the linker doesn't like the keyword inline or if the use of 'inline' could give this error?? Thaks

              Have a nice code day ;)

              P Offline
              P Offline
              Prakash Nadar
              wrote on last edited by
              #6

              _Russell_ wrote:

              Sorry, but I prefere the simple use of #include.

              linking the library to your project is also a simple way of doing.


              -Prakash

              1 Reply Last reply
              0
              • R Russell

                Sorry, but I prefere the simple:sigh: use of #include. I have good news: In libr.h/.cpp there was a lot of inline functions, well... I modify the files cutting that word and now everything is running. But I want to use inline: I need it!! So, do you know if it is possible that the linker doesn't like the keyword inline or if the use of 'inline' could give this error?? Thaks

                Have a nice code day ;)

                P Offline
                P Offline
                Prakash Nadar
                wrote on last edited by
                #7

                btw, is the doc-view app a MFC project?


                -Prakash

                R 1 Reply Last reply
                0
                • P Prakash Nadar

                  btw, is the doc-view app a MFC project?


                  -Prakash

                  R Offline
                  R Offline
                  Russell
                  wrote on last edited by
                  #8

                  Yes

                  Have a nice code day ;)

                  P 1 Reply Last reply
                  0
                  • R Russell

                    Yes

                    Have a nice code day ;)

                    P Offline
                    P Offline
                    Prakash Nadar
                    wrote on last edited by
                    #9

                    Add the .cpp file to the project and #include the .h file whereever you need. It should compile and link properly.


                    -Prakash

                    1 Reply Last reply
                    0
                    • R Russell

                      I have a class on a library on the file Libr.h/.cpp I build a doc/view app. I link the header in Doc.h using #include "Libr.h", and the code is pasted in Doc.cpp using #include "Libr.cpp". View knows that the library exist because in View.h I have #include "Doc.h". So I have some code that use the library in Doc.pp and View.cpp. But the problem is: Doc.cpp OK View.cpp: Link error LNK2019 (functions not finded when link: but no problems when compile) So I tried to past #include "Libr.cpp" in View.cpp, and then: Doc.cpp: Link error LNK2019 View.cpp OK Damn! And this appens only with some functions of the library, and strange thing is that this functions are very very similar to other functions that haven't got any problem!! Can anybody help me?? (sorry for the long message)

                      Have a nice code day ;)

                      V Offline
                      V Offline
                      vallikumar
                      wrote on last edited by
                      #10

                      Hi, I had the same link error. I feel the problem is inclusion of your header files(#include "Libr.h") in side the Doc.h. Try to include the header files inside the .cpp files, not inside the .h files. If you want exactly inside the .h file, then include inside of #define. otherwise system will produce runtime error because of multiple inclution. in your case you included "#include "Libr.h" inside your doc.h and doc.h is included inside view.h and etc.. try to avoid this and "#include "Libr.h" should be inside your doc.cpp Dont include .cpp file. .h file will take care everythings of .cpp best of luck,, regards Vallikumar A

                      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