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. How to resolve: error LNK2001: unresolved external symbol "public: static void *

How to resolve: error LNK2001: unresolved external symbol "public: static void *

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studiojsonhelp
5 Posts 5 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.
  • M Offline
    M Offline
    mlong30
    wrote on last edited by
    #1

    Hi All,

    I'm trying to create a C++ DLL using the WinInet API, but for some odd reason, I get no errors during compiling but get external link errors regarding variables within my class. Any idea how I can resolve this? Visual Studio 2015.

    ----------------------------------------header test.h -------------------------------------------
    // #include "stdafx.h"
    using namespace std;
    // #include
    #include
    #include
    #include
    #include
    #include
    #include
    //#include
    #pragma comment(lib, "wininet.lib")
    #pragma comment(lib, "user32.lib")
    #define FTP_FUNCTIONS_BUFFER_SIZE MAX_PATH+8

    namespace Win32_FTP
    {
    class FTP_Win32_ClientV1
    {
    private:

        public:
                        static LPCWSTR sFileSearch;
                        static char \* sIpAddress;
                        static  LPCWSTR sUsername;
                        static LPCWSTR sPassword;
                        static string sRemoteDir;
                        static string sLocalDir;
                        static string sFilename;
                        static DWORD dwError;
                        static HINTERNET hFTPConnect;
                        static HINTERNET hFind;
                        static HINTERNET hConnect;
    
                        static HANDLE hFile;
                        static WIN32\_FIND\_DATA   FindFileData;
                        static string strTemp;
    
    
                static  \_\_declspec(dllexport) void Test1();
                static  \_\_declspec(dllexport) void FtpCloseConnection();
    
        };
    

    }

    ----------------------------------------source test.cpp -------------------------------------------

    //using namespace std;
    #include
    #include "test.h"
    // using namespace std;

    namespace Win32_FTP
    {

        void FTP\_Win32\_Client::Test1()
        {
                cout << "This is a test from Cplus to Csharp DLL";
        }
    
    
        void FTP\_Win32\_Client::FtpCloseConnection()
        {
    
                InternetCloseHandle(FTP\_Win32\_Client::hFind);
                InternetCloseHandle(FTP\_Win32\_Client::hFTPConnect);
                InternetCloseHandle(FTP\_Win32\_Client::hConnect);
        }
    

    }

    ***************************LINK ERRORS ************************
    Test.obj : error LNK2001: unresolved external symbol "public: static void * Win32_FTP::FTP_Win32_Client::hFTPConnect" (?hFTPConnect@FTP_Win32_Client@Win32_F

    V CPalliniC L D 4 Replies Last reply
    0
    • M mlong30

      Hi All,

      I'm trying to create a C++ DLL using the WinInet API, but for some odd reason, I get no errors during compiling but get external link errors regarding variables within my class. Any idea how I can resolve this? Visual Studio 2015.

      ----------------------------------------header test.h -------------------------------------------
      // #include "stdafx.h"
      using namespace std;
      // #include
      #include
      #include
      #include
      #include
      #include
      #include
      //#include
      #pragma comment(lib, "wininet.lib")
      #pragma comment(lib, "user32.lib")
      #define FTP_FUNCTIONS_BUFFER_SIZE MAX_PATH+8

      namespace Win32_FTP
      {
      class FTP_Win32_ClientV1
      {
      private:

          public:
                          static LPCWSTR sFileSearch;
                          static char \* sIpAddress;
                          static  LPCWSTR sUsername;
                          static LPCWSTR sPassword;
                          static string sRemoteDir;
                          static string sLocalDir;
                          static string sFilename;
                          static DWORD dwError;
                          static HINTERNET hFTPConnect;
                          static HINTERNET hFind;
                          static HINTERNET hConnect;
      
                          static HANDLE hFile;
                          static WIN32\_FIND\_DATA   FindFileData;
                          static string strTemp;
      
      
                  static  \_\_declspec(dllexport) void Test1();
                  static  \_\_declspec(dllexport) void FtpCloseConnection();
      
          };
      

      }

      ----------------------------------------source test.cpp -------------------------------------------

      //using namespace std;
      #include
      #include "test.h"
      // using namespace std;

      namespace Win32_FTP
      {

          void FTP\_Win32\_Client::Test1()
          {
                  cout << "This is a test from Cplus to Csharp DLL";
          }
      
      
          void FTP\_Win32\_Client::FtpCloseConnection()
          {
      
                  InternetCloseHandle(FTP\_Win32\_Client::hFind);
                  InternetCloseHandle(FTP\_Win32\_Client::hFTPConnect);
                  InternetCloseHandle(FTP\_Win32\_Client::hConnect);
          }
      

      }

      ***************************LINK ERRORS ************************
      Test.obj : error LNK2001: unresolved external symbol "public: static void * Win32_FTP::FTP_Win32_Client::hFTPConnect" (?hFTPConnect@FTP_Win32_Client@Win32_F

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Have a look at [Linking errors while linking a dll in c++](https://social.msdn.microsoft.com/Forums/en-US/f3b696ec-2a9f-4c9f-a50c-92395008c3bf/linking-errors-while-linking-a-dll-in-c?forum=Vsexpressvc) and many other discussions here: [Google](https://www.google.com/search?newwindow=1&ei=LidlXLKjJYXFwQKnsrOYAw&q=error+LNK2001%3A+unresolved+external+symbol+dll+class&oq=error+LNK2001%3A+unresolved+external+symbol+dll+class&gs\_l=psy-ab.3...1008.15703..16700...4.0..0.505.1494.10j3j5-1......0....1..gws-wiz.......0i71j35i39j0i20i263j0j0i22i30j0i22i10i30j33i160j33i21.oA1rbIz38WU)

      1 Reply Last reply
      0
      • M mlong30

        Hi All,

        I'm trying to create a C++ DLL using the WinInet API, but for some odd reason, I get no errors during compiling but get external link errors regarding variables within my class. Any idea how I can resolve this? Visual Studio 2015.

        ----------------------------------------header test.h -------------------------------------------
        // #include "stdafx.h"
        using namespace std;
        // #include
        #include
        #include
        #include
        #include
        #include
        #include
        //#include
        #pragma comment(lib, "wininet.lib")
        #pragma comment(lib, "user32.lib")
        #define FTP_FUNCTIONS_BUFFER_SIZE MAX_PATH+8

        namespace Win32_FTP
        {
        class FTP_Win32_ClientV1
        {
        private:

            public:
                            static LPCWSTR sFileSearch;
                            static char \* sIpAddress;
                            static  LPCWSTR sUsername;
                            static LPCWSTR sPassword;
                            static string sRemoteDir;
                            static string sLocalDir;
                            static string sFilename;
                            static DWORD dwError;
                            static HINTERNET hFTPConnect;
                            static HINTERNET hFind;
                            static HINTERNET hConnect;
        
                            static HANDLE hFile;
                            static WIN32\_FIND\_DATA   FindFileData;
                            static string strTemp;
        
        
                    static  \_\_declspec(dllexport) void Test1();
                    static  \_\_declspec(dllexport) void FtpCloseConnection();
        
            };
        

        }

        ----------------------------------------source test.cpp -------------------------------------------

        //using namespace std;
        #include
        #include "test.h"
        // using namespace std;

        namespace Win32_FTP
        {

            void FTP\_Win32\_Client::Test1()
            {
                    cout << "This is a test from Cplus to Csharp DLL";
            }
        
        
            void FTP\_Win32\_Client::FtpCloseConnection()
            {
        
                    InternetCloseHandle(FTP\_Win32\_Client::hFind);
                    InternetCloseHandle(FTP\_Win32\_Client::hFTPConnect);
                    InternetCloseHandle(FTP\_Win32\_Client::hConnect);
            }
        

        }

        ***************************LINK ERRORS ************************
        Test.obj : error LNK2001: unresolved external symbol "public: static void * Win32_FTP::FTP_Win32_Client::hFTPConnect" (?hFTPConnect@FTP_Win32_Client@Win32_F

        CPalliniC Online
        CPalliniC Online
        CPallini
        wrote on last edited by
        #3

        Class static variables, like Win32_FTP::FTP_Win32_Client::hFTPConnect must be also defined in one source file. That is you have to write

        HINTERNET Win32_FTP::FTP_Win32_Client::hFTPConnect;

        (and so on...) in your test.cpp source file. An altrernative, available only with C++ 17 compliant compilers is to declare such variables inline inside the header file (see, for instance INLINE VARIABLES[^]).

        In testa che avete, signor di Ceprano?

        1 Reply Last reply
        0
        • M mlong30

          Hi All,

          I'm trying to create a C++ DLL using the WinInet API, but for some odd reason, I get no errors during compiling but get external link errors regarding variables within my class. Any idea how I can resolve this? Visual Studio 2015.

          ----------------------------------------header test.h -------------------------------------------
          // #include "stdafx.h"
          using namespace std;
          // #include
          #include
          #include
          #include
          #include
          #include
          #include
          //#include
          #pragma comment(lib, "wininet.lib")
          #pragma comment(lib, "user32.lib")
          #define FTP_FUNCTIONS_BUFFER_SIZE MAX_PATH+8

          namespace Win32_FTP
          {
          class FTP_Win32_ClientV1
          {
          private:

              public:
                              static LPCWSTR sFileSearch;
                              static char \* sIpAddress;
                              static  LPCWSTR sUsername;
                              static LPCWSTR sPassword;
                              static string sRemoteDir;
                              static string sLocalDir;
                              static string sFilename;
                              static DWORD dwError;
                              static HINTERNET hFTPConnect;
                              static HINTERNET hFind;
                              static HINTERNET hConnect;
          
                              static HANDLE hFile;
                              static WIN32\_FIND\_DATA   FindFileData;
                              static string strTemp;
          
          
                      static  \_\_declspec(dllexport) void Test1();
                      static  \_\_declspec(dllexport) void FtpCloseConnection();
          
              };
          

          }

          ----------------------------------------source test.cpp -------------------------------------------

          //using namespace std;
          #include
          #include "test.h"
          // using namespace std;

          namespace Win32_FTP
          {

              void FTP\_Win32\_Client::Test1()
              {
                      cout << "This is a test from Cplus to Csharp DLL";
              }
          
          
              void FTP\_Win32\_Client::FtpCloseConnection()
              {
          
                      InternetCloseHandle(FTP\_Win32\_Client::hFind);
                      InternetCloseHandle(FTP\_Win32\_Client::hFTPConnect);
                      InternetCloseHandle(FTP\_Win32\_Client::hConnect);
              }
          

          }

          ***************************LINK ERRORS ************************
          Test.obj : error LNK2001: unresolved external symbol "public: static void * Win32_FTP::FTP_Win32_Client::hFTPConnect" (?hFTPConnect@FTP_Win32_Client@Win32_F

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

          Why are you creating a class and then making everything static?

          1 Reply Last reply
          0
          • M mlong30

            Hi All,

            I'm trying to create a C++ DLL using the WinInet API, but for some odd reason, I get no errors during compiling but get external link errors regarding variables within my class. Any idea how I can resolve this? Visual Studio 2015.

            ----------------------------------------header test.h -------------------------------------------
            // #include "stdafx.h"
            using namespace std;
            // #include
            #include
            #include
            #include
            #include
            #include
            #include
            //#include
            #pragma comment(lib, "wininet.lib")
            #pragma comment(lib, "user32.lib")
            #define FTP_FUNCTIONS_BUFFER_SIZE MAX_PATH+8

            namespace Win32_FTP
            {
            class FTP_Win32_ClientV1
            {
            private:

                public:
                                static LPCWSTR sFileSearch;
                                static char \* sIpAddress;
                                static  LPCWSTR sUsername;
                                static LPCWSTR sPassword;
                                static string sRemoteDir;
                                static string sLocalDir;
                                static string sFilename;
                                static DWORD dwError;
                                static HINTERNET hFTPConnect;
                                static HINTERNET hFind;
                                static HINTERNET hConnect;
            
                                static HANDLE hFile;
                                static WIN32\_FIND\_DATA   FindFileData;
                                static string strTemp;
            
            
                        static  \_\_declspec(dllexport) void Test1();
                        static  \_\_declspec(dllexport) void FtpCloseConnection();
            
                };
            

            }

            ----------------------------------------source test.cpp -------------------------------------------

            //using namespace std;
            #include
            #include "test.h"
            // using namespace std;

            namespace Win32_FTP
            {

                void FTP\_Win32\_Client::Test1()
                {
                        cout << "This is a test from Cplus to Csharp DLL";
                }
            
            
                void FTP\_Win32\_Client::FtpCloseConnection()
                {
            
                        InternetCloseHandle(FTP\_Win32\_Client::hFind);
                        InternetCloseHandle(FTP\_Win32\_Client::hFTPConnect);
                        InternetCloseHandle(FTP\_Win32\_Client::hConnect);
                }
            

            }

            ***************************LINK ERRORS ************************
            Test.obj : error LNK2001: unresolved external symbol "public: static void * Win32_FTP::FTP_Win32_Client::hFTPConnect" (?hFTPConnect@FTP_Win32_Client@Win32_F

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

            Definitely remove the line: using namespace std; My advice: NEVER do that.

            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