[Two projects use one file on visual studio 2008] [C++]
-
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
-
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
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 whenlinking
will fail if the code is not there.I'd rather be phishing!
-
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 whenlinking
will fail if the code is not there.I'd rather be phishing!
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
-
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
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!
-
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
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.
-
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.
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
-
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
Are you asking a question? ...I'm not sure what you're saying.