Thread: LNK2001: unresolved external symbol

  1. #1
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211

    LNK2001: unresolved external symbol

    hello all,
    I have just wrote an application that looks error free to me, but according to my MSVC 6.0 there is a linker error . here is my code, compiles 0 errors 0 warnings. also note that I am using stdafx for the precompiled header, and I have the following included in stdafx.h:

    Code:
    #include <cstdlib>
    #include <windows.h>
    #include <commctrl.h>
    Code:
    #include "stdafx.h"
    #include "resource.h"
    
    static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
     	WNDCLASS wc;
    	INITCOMMONCONTROLSEX cc;
    
    	memset(&wc, 0, sizeof(wc));
    	wc.lpfnWndProc = DefDlgProc;
    	wc.cbWndExtra = DLGWINDOWEXTRA;
    	wc.hInstance = hInstance;
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    	wc.lpszClassName = "stringscan";
    	RegisterClass(&wc);
    	memset(&cc, 0, sizeof(cc));
    	cc.dwSize = sizeof(cc);
    	cc.dwICC = 0xffffffff;
    	InitCommonControlsEx(&cc);
    
    	return DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, (DLGPROC)DialogFunc);
    }
    
    static int InitApp(HWND hDlg, WPARAM wParam, LPARAM lParam)
    {
             /* initialize some controls with values here */
    	return 1;
    }
    
    static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg) {
    	case WM_INITDIALOG:
    		InitApp(hwndDlg, wParam, lParam);
    		return TRUE;
    	case WM_COMMAND:
    		switch(LOWORD(wParam)) {
    		case IDC_BUTTON_SCAN:
    			/* do some tests and call scan function */
    			break;
    		}
    		case WM_CLOSE:
    			EndDialog(hwndDlg, 0);
    			return TRUE;
    	}
    	return FALSE;
    }
    the full error that I am getting is:

    stringscan.obj : error LNK2001: unresolved external symbol __imp__InitCommonControlsEx@4 Release/stringscan.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe

    stringscan.exe - 2 error(s), 0 warning(s)
    according to it it has something to do with InitCommonControls? don't see what I am doing wrong there . could it have something to do with WIN32_LEAN_AND_MEAN defined in stdafx.h? somehow it might be excluding commctrl.h?

    can anyone please help show me what is going wrong here? thanks in advance.
    Last edited by Bleech; 03-24-2006 at 02:38 PM.

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

  2. #2
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    You need to link in comctl32.lib

    Regards,
    Brian

  3. #3
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Try adding this:
    Code:
    #include <cstdlib>
    #include <windows.h>
    #include <commctrl.h>
    #pragma comment (lib, "comtrl32.lib")
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  4. #4
    Madly in anger with you
    Join Date
    Nov 2005
    Posts
    211
    aha. thanks man!

    edit: hehe, Joelito, typo:

    Code:
    #pragma comment(lib, "comctl32")
    Last edited by Bleech; 03-24-2006 at 02:51 PM.

    Intel Core 2 Quad Q6600 @ 2.40 GHz
    3072 MB PC2-5300 DDR2
    2 x 320 GB SATA (640 GB)
    NVIDIA GeForce 8400GS 256 MB PCI-E

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    #pragma comment(lib, "comctl32")
    I'd like to suggest that instead of doing this you actually use the project settings to link in libraries; you should, arguably, be doing this anyway. If however, you feel you must use #pragmas like this then could you at least consider doing it this way instead:
    Code:
    #if defined __MSC_VER
    #pragma comment(lib, "comctl32")
    #endif
    I am suggesting this because both __MSC_VER and, more importantly, that #pragma is microsoft specific, so if you want anyone who may not be using a microsoft compiler to have any chance of compiling your code you will have to ensure their compiler never sees that #pragma - this, of course, is why it's arguably better to actually use your compiler's project settings to set libs etc. rather than contaminating your code with compiler specific stuff like this.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM
  5. Help with error
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 04-17-2002, 09:36 AM