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. Tell linker to add cpp files

Tell linker to add cpp files

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
9 Posts 3 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.
  • D Offline
    D Offline
    dehseth
    wrote on last edited by
    #1

    Hey guys, I got a linker problem.. I have written some .h files and .cpp files for being used in any project, and put them to a folder named "common". :) Now I have a project and I set up the vc directories. I add include and source file folders to there. And I include the main .h header file. Compiling is ok :) but when it comes to linking linker says unresolved external symbol :doh: ... So it couldn't find the body in the cpp file. So how can I tell the linker to use the cpp file? :confused: Thank you... :-D

    S C 2 Replies Last reply
    0
    • D dehseth

      Hey guys, I got a linker problem.. I have written some .h files and .cpp files for being used in any project, and put them to a folder named "common". :) Now I have a project and I set up the vc directories. I add include and source file folders to there. And I include the main .h header file. Compiling is ok :) but when it comes to linking linker says unresolved external symbol :doh: ... So it couldn't find the body in the cpp file. So how can I tell the linker to use the cpp file? :confused: Thank you... :-D

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      You don't tell the linker to use the cpp file - the cpp file's source code, but the linker wants object code... What you need to do is give the linker a command line that tells it all the object files that are produced by the compiler, plus any import libraries for system libraries (DLLs) that you reference. BTW - just suggesting here, but we might be able to help even more if you gave an exact error message.

      D 1 Reply Last reply
      0
      • D dehseth

        Hey guys, I got a linker problem.. I have written some .h files and .cpp files for being used in any project, and put them to a folder named "common". :) Now I have a project and I set up the vc directories. I add include and source file folders to there. And I include the main .h header file. Compiling is ok :) but when it comes to linking linker says unresolved external symbol :doh: ... So it couldn't find the body in the cpp file. So how can I tell the linker to use the cpp file? :confused: Thank you... :-D

        C Offline
        C Offline
        Code o mat
        wrote on last edited by
        #3

        You need to add your cpp files to your project otherwise it won't know where it should look for the actual implementations of the methods and rest declared in the header files.

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

        D 1 Reply Last reply
        0
        • S Stuart Dootson

          You don't tell the linker to use the cpp file - the cpp file's source code, but the linker wants object code... What you need to do is give the linker a command line that tells it all the object files that are produced by the compiler, plus any import libraries for system libraries (DLLs) that you reference. BTW - just suggesting here, but we might be able to help even more if you gave an exact error message.

          D Offline
          D Offline
          dehseth
          wrote on last edited by
          #4

          Error 1 error LNK2019: unresolved external symbol "public: __thiscall CXControl::~CXControl(void)" (??1CXControl@@QAE@XZ) referenced in function "public: __thiscall CXDesktop::~CXDesktop(void)" (??1CXDesktop@@QAE@XZ) DX.obj This is one of the errors... SO how can I tell Linker/Compiler to do that :confused:

          S 1 Reply Last reply
          0
          • C Code o mat

            You need to add your cpp files to your project otherwise it won't know where it should look for the actual implementations of the methods and rest declared in the header files.

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

            D Offline
            D Offline
            dehseth
            wrote on last edited by
            #5

            Actually this is exacly I am trying to avoid... I do not want to add .cpp files. But if I have to then I will.. So any other suggestions?

            C S 2 Replies Last reply
            0
            • D dehseth

              Actually this is exacly I am trying to avoid... I do not want to add .cpp files. But if I have to then I will.. So any other suggestions?

              C Offline
              C Offline
              Code o mat
              wrote on last edited by
              #6

              Well, you could build libraries of your implementations and link to these using #import or such. I never did this so i don't know how it works but i believe that is one way of doing it.

              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Life: great graphics, but the gameplay sux. <

              1 Reply Last reply
              0
              • D dehseth

                Error 1 error LNK2019: unresolved external symbol "public: __thiscall CXControl::~CXControl(void)" (??1CXControl@@QAE@XZ) referenced in function "public: __thiscall CXDesktop::~CXDesktop(void)" (??1CXDesktop@@QAE@XZ) DX.obj This is one of the errors... SO how can I tell Linker/Compiler to do that :confused:

                S Offline
                S Offline
                Stuart Dootson
                wrote on last edited by
                #7

                I should have read your original message more closely - anyway - what Code-o-mat said, add the cpp files to your VC++ project. It'll compile them and link their object files into the final executable.

                Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                1 Reply Last reply
                0
                • D dehseth

                  Actually this is exacly I am trying to avoid... I do not want to add .cpp files. But if I have to then I will.. So any other suggestions?

                  S Offline
                  S Offline
                  Stuart Dootson
                  wrote on last edited by
                  #8

                  Create a separate static library project for the CPP files and get that to build a static library from the cpp files for you. Then, tell the project that uses that functionality to link against the static library.

                  Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                  D 1 Reply Last reply
                  0
                  • S Stuart Dootson

                    Create a separate static library project for the CPP files and get that to build a static library from the cpp files for you. Then, tell the project that uses that functionality to link against the static library.

                    Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                    D Offline
                    D Offline
                    dehseth
                    wrote on last edited by
                    #9

                    Yeah that's what I did.. Thank you. ;) I create a static library put all my .h and .cpp files in it and compile create my .lib file. And put it into my application. Now it works.. :thumbsup: Thank you again. :-D

                    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