2012-03-10 49 views
0

我正在做一些需要获取跨平台cmoputer的HWID的东西。这是用C++编写的,我正在Qt Creator中使用Qt框架。我真的没有发现太多,所以我会解释。我试图在Windows上获取HWID,并且一旦我尝试编译它,它会一直说我有无法解析的外部符号。这里是我的HWID填充码:HWID Windows - 使用Qt框架

#include "mainwindow.h" 
#include "ui_mainwindow.h" 

#ifdef _WIN32 | _WIN64//Windows 
#define _WIN32_WINNT 0x0400 
#include <Windows.h> 
#define get_hwid() windows_hwid() 

#elif defined __APPLE__ //Mac 
#define get_hwid() mac_hwid() 

#else //Unknown OS 
#define get_hwid() unknown_hwid() 

#endif 

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) 
{ 
    ui->setupUi(this); 
    QMessageBox::about(this, "About", get_hwid()); 
} 

QString MainWindow::windows_hwid() 
{ 
    HW_PROFILE_INFO hwProfInfo; 
    if(GetCurrentHwProfile(&hwProfInfo)) 
    { 
     return "we got it."; 
    } 
    return "couldn't get it"; 
} 

QString MainWindow::mac_hwid() 
{ 
    QProcess proc; 

    QStringList args; 
    args << "-c" << "ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { print $3; }'"; 
    proc.start("/bin/bash", args); 
    proc.waitForFinished(); 

    return proc.readAll(); 
} 

QString MainWindow::unknown_hwid() 
{ 
    return "hello unknown person!"; 
} 

这将引发这些错误:

mainwindow.obj:-1: error: LNK2019: unresolved external symbol _imp[email protected] referenced in function "public: class QString __thiscall MainWindow::windows_hwid(void)" ([email protected]@@[email protected]@XZ)

debug\MCBruter.exe:-1: error: LNK1120: 1 unresolved externals

我敢肯定,99%的底部有一个引起我的第一一,所以我会忽略这一点。我不知道该怎么办...... Mac的工作正常,只是Windows给我的问题。谢谢,Hetelek。

+0

你添加以下Windows库:Advapi32.lib? – akhisp 2012-03-10 23:26:40

回答

1

你有一个链接器错误,是由于你已经包含了相关的包含文件,但是你没有链接你的目标文件和正确的导入库。将Advapi32.lib添加到库链接并错误将消失。

顺便说一句,来链接特定API正确的库及其在MSDN文档中总是被指定:如果你看一下page of GetCurrentHwProfile,你会发现:

Header: Winbase.h (include Windows.h)

Library: Advapi32.lib

DLL: Advapi32.dll