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. [Two projects use one file on visual studio 2008] [C++]

[Two projects use one file on visual studio 2008] [C++]

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++csharpvisual-studiotutorial
7 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.
  • T Offline
    T Offline
    Thong LeTrung
    wrote on last edited by
    #1

    Hi all . step 1: create new project on visual studio (project1.exe) step 2: create WinUtils.h and WinUtils.cpp on project1.exe and main1.cpp step 3 : add new project (project2.exe) and create main2.cpp Now I want to use WinUtils.h and WinUtils.cpp on project2.exe example //-----------------main2.cpp-------------------- #include "../utils/WinUtils.h" int main() { bool value = WinUtils::isWin64bit();/ function static return 0 ; } //-------------------------------------------- when i build code ,I saw error: + error LNK2001: unresolved external symbol "public: static int __cdecl WinUtils::Is64BitOS(void)" (?Is64BitOS@WinUtils@@SAHXZ) + fatal error LNK1120: 1 unresolved externals I make sure that isWin64bit() function is "public static" Please help me this problem .because my code has very much h and cpp files. Thanks Thong LT

    M 1 Reply Last reply
    0
    • T Thong LeTrung

      Hi all . step 1: create new project on visual studio (project1.exe) step 2: create WinUtils.h and WinUtils.cpp on project1.exe and main1.cpp step 3 : add new project (project2.exe) and create main2.cpp Now I want to use WinUtils.h and WinUtils.cpp on project2.exe example //-----------------main2.cpp-------------------- #include "../utils/WinUtils.h" int main() { bool value = WinUtils::isWin64bit();/ function static return 0 ; } //-------------------------------------------- when i build code ,I saw error: + error LNK2001: unresolved external symbol "public: static int __cdecl WinUtils::Is64BitOS(void)" (?Is64BitOS@WinUtils@@SAHXZ) + fatal error LNK1120: 1 unresolved externals I make sure that isWin64bit() function is "public static" Please help me this problem .because my code has very much h and cpp files. Thanks Thong LT

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      Did you add the file "WinUtils.cpp" (and optionally WinUtils.h) to the new projects? Including the header file will make your project compile, but when linking will fail if the code is not there.

      I'd rather be phishing!

      T 1 Reply Last reply
      0
      • M Maximilien

        Did you add the file "WinUtils.cpp" (and optionally WinUtils.h) to the new projects? Including the header file will make your project compile, but when linking will fail if the code is not there.

        I'd rather be phishing!

        T Offline
        T Offline
        Thong LeTrung
        wrote on last edited by
        #3

        Thank Maximilien, I didn't add this file . I will add this file. How to have any ways ? . if we don't add WinUtils.cpp and WinUtils.h inside new project. I know will dll , lib files we only use configure but we don't need add h and cpp file inside new project. Thanks Thong LT

        M A 2 Replies Last reply
        0
        • T Thong LeTrung

          Thank Maximilien, I didn't add this file . I will add this file. How to have any ways ? . if we don't add WinUtils.cpp and WinUtils.h inside new project. I know will dll , lib files we only use configure but we don't need add h and cpp file inside new project. Thanks Thong LT

          M Offline
          M Offline
          Maximilien
          wrote on last edited by
          #4

          If the code WinUtils.cpp will be used as a library, then it would be a good thing to either build them as a DLL or a static library (.lib). After that, you will only need to have the header file (WinUtils.h) and you will link with the library.

          I'd rather be phishing!

          1 Reply Last reply
          0
          • T Thong LeTrung

            Thank Maximilien, I didn't add this file . I will add this file. How to have any ways ? . if we don't add WinUtils.cpp and WinUtils.h inside new project. I know will dll , lib files we only use configure but we don't need add h and cpp file inside new project. Thanks Thong LT

            A Offline
            A Offline
            Albert Holguin
            wrote on last edited by
            #5

            If you don't put the cpp file, it won't get compiled, therefore the object doesn't exist. Header file is simply a reference, it doesn't produce an object.

            T 1 Reply Last reply
            0
            • A Albert Holguin

              If you don't put the cpp file, it won't get compiled, therefore the object doesn't exist. Header file is simply a reference, it doesn't produce an object.

              T Offline
              T Offline
              Thong LeTrung
              wrote on last edited by
              #6

              Thanks all friends . My code now run well . I have some error and how to fix . + fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] Configuration Properties\Gerenal\Use of MFC and select "Use MFC in a Shared DLL" + error LNK2001: unresolved external Configuration Properties\Linker\input\Additional dependencies\ Then go to the end and type ";ws2_32.lib". or use code: #include #pragma comment(lib,"shlwapi.lib") #include // Link with Iphlpapi.lib #pragma comment(lib, "IPHLPAPI.lib") Thong LT

              A 1 Reply Last reply
              0
              • T Thong LeTrung

                Thanks all friends . My code now run well . I have some error and how to fix . + fatal error C1189: #error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] Configuration Properties\Gerenal\Use of MFC and select "Use MFC in a Shared DLL" + error LNK2001: unresolved external Configuration Properties\Linker\input\Additional dependencies\ Then go to the end and type ";ws2_32.lib". or use code: #include #pragma comment(lib,"shlwapi.lib") #include // Link with Iphlpapi.lib #pragma comment(lib, "IPHLPAPI.lib") Thong LT

                A Offline
                A Offline
                Albert Holguin
                wrote on last edited by
                #7

                Are you asking a question? ...I'm not sure what you're saying.

                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