gpt4 book ai didi

c++ - Unresolved external 错误 - 使用 FTD2XX.h 的 Visual C++

转载 作者:太空宇宙 更新时间:2023-11-04 11:51:38 25 4
gpt4 key购买 nike

我是 C++ 编程的新手,所以请多多包涵。我正在 visual studio 中编写一个小型应用程序,用于与 FTDI 模块(UM232H 高速 USB 模块)进行通信。 FTDI 为该模块提供 D2XX 驱动程序,可在其网站上轻松获得。现在我的程序非常简单。它正在调用一个名为 FT_Open (ftd2xx.h) 的函数来简单地打开设备并检查设备是否已连接到计算机。

但是现在我一直收到 error LNK2019,未解析的外部符号。现在我确实通读了 Visual Studio 网站提供的应用说明,但我似乎仍然无法解决我的错误。我想我犯了一个愚蠢的错误,如果你们能帮助我,我希望你们能给我一些指导。

我提供了我的代码以及 FTDI 网站提供的头文件 (ftd2xx.h)。

主程序:

// ConsoleApplication2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "ftd2xx.h"
#include <iostream>

using namespace std;
FT_HANDLE ftHandle;
FT_STATUS ftStatus;

int main(){
ftStatus = FT_Open(0,&ftHandle);

if (ftStatus == FT_OK) {
cout << "hello world";
// FT_Open OK, use ftHandle to access device
}
else {
// FT_Open failed
}
return 0;
}


ftd2xx.h:
#include "windows.h"
/*#include <stdarg.h>
#include <windef.h>
#include <winnt.h>
#include <winbase.h>*/

/*++
Copyright © 2001-2011 Future Technology Devices International Limited

THIS SOFTWARE IS PROVIDED BY FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
FUTURE TECHNOLOGY DEVICES INTERNATIONAL LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

FTDI DRIVERS MAY BE USED ONLY IN CONJUNCTION WITH PRODUCTS BASED ON FTDI PARTS.

FTDI DRIVERS MAY BE DISTRIBUTED IN ANY FORM AS LONG AS LICENSE INFORMATION IS NOT MODIFIED.

IF A CUSTOM VENDOR ID AND/OR PRODUCT ID OR DESCRIPTION STRING ARE USED, IT IS THE
RESPONSIBILITY OF THE PRODUCT MANUFACTURER TO MAINTAIN ANY CHANGES AND SUBSEQUENT WHQL
RE-CERTIFICATION AS A RESULT OF MAKING THESE CHANGES.

Module Name:
ftd2xx.h

Abstract:
Native USB device driver for FTDI FT232x, FT245x, FT2232x and FT4232x devices
FTD2XX library definitions

Environment:
kernel & user mode
--*/


#ifndef FTD2XX_H
#define FTD2XX_H

// The following ifdef block is the standard way of creating macros
// which make exporting from a DLL simpler. All files within this DLL
// are compiled with the FTD2XX_EXPORTS symbol defined on the command line.
// This symbol should not be defined on any project that uses this DLL.
// This way any other project whose source files include this file see
// FTD2XX_API functions as being imported from a DLL, whereas this DLL
// sees symbols defined with this macro as being exported.

#ifdef FTD2XX_EXPORTS
#define FTD2XX_API __declspec(dllexport)
#else
#define FTD2XX_API __declspec(dllimport)
#endif

typedef PVOID FT_HANDLE;
typedef ULONG FT_STATUS;

//
// Device status
//
enum {
FT_OK,
FT_INVALID_HANDLE,
FT_DEVICE_NOT_FOUND,
FT_DEVICE_NOT_OPENED,
FT_IO_ERROR,
FT_INSUFFICIENT_RESOURCES,
FT_INVALID_PARAMETER,
FT_INVALID_BAUD_RATE,

FT_DEVICE_NOT_OPENED_FOR_ERASE,
FT_DEVICE_NOT_OPENED_FOR_WRITE,
FT_FAILED_TO_WRITE_DEVICE,
FT_EEPROM_READ_FAILED,
FT_EEPROM_WRITE_FAILED,
FT_EEPROM_ERASE_FAILED,
FT_EEPROM_NOT_PRESENT,
FT_EEPROM_NOT_PROGRAMMED,
FT_INVALID_ARGS,
FT_NOT_SUPPORTED,
FT_OTHER_ERROR,
FT_DEVICE_LIST_NOT_READY,
};


#define FT_SUCCESS(status) ((status) == FT_OK)
//
// FT_OpenEx Flags
//
#define FT_OPEN_BY_SERIAL_NUMBER 1
#define FT_OPEN_BY_DESCRIPTION 2
#define FT_OPEN_BY_LOCATION 4

//
// FT_ListDevices Flags (used in conjunction with FT_OpenEx Flags
//

#define FT_LIST_NUMBER_ONLY 0x80000000
#define FT_LIST_BY_INDEX 0x40000000
#define FT_LIST_ALL 0x20000000

#define FT_LIST_MASK (FT_LIST_NUMBER_ONLY|FT_LIST_BY_INDEX|FT_LIST_ALL)
//
// Baud Rates
//
#define FT_BAUD_300 300
#define FT_BAUD_600 600
#define FT_BAUD_1200 1200
#define FT_BAUD_2400 2400
#define FT_BAUD_4800 4800
#define FT_BAUD_9600 9600
#define FT_BAUD_14400 14400
#define FT_BAUD_19200 19200
#define FT_BAUD_38400 38400
#define FT_BAUD_57600 57600
#define FT_BAUD_115200 115200
#define FT_BAUD_230400 230400
#define FT_BAUD_460800 460800
#define FT_BAUD_921600 921600
//
// Word Lengths
//
#define FT_BITS_8 (UCHAR) 8
#define FT_BITS_7 (UCHAR) 7
//
// Stop Bits
//
#define FT_STOP_BITS_1 (UCHAR) 0
#define FT_STOP_BITS_2 (UCHAR) 2
//
// Parity
//
#define FT_PARITY_NONE (UCHAR) 0
#define FT_PARITY_ODD (UCHAR) 1
#define FT_PARITY_EVEN (UCHAR) 2
#define FT_PARITY_MARK (UCHAR) 3
#define FT_PARITY_SPACE (UCHAR) 4
//
// Flow Control
//
#define FT_FLOW_NONE 0x0000
#define FT_FLOW_RTS_CTS 0x0100
#define FT_FLOW_DTR_DSR 0x0200
#define FT_FLOW_XON_XOFF 0x0400

//
// Purge rx and tx buffers
//
#define FT_PURGE_RX 1
#define FT_PURGE_TX 2
//
// Events
//
typedef void (*PFT_EVENT_HANDLER)(DWORD,DWORD);
#define FT_EVENT_RXCHAR 1
#define FT_EVENT_MODEM_STATUS 2
#define FT_EVENT_LINE_STATUS 4

//
// Timeouts
//
#define FT_DEFAULT_RX_TIMEOUT 300
#define FT_DEFAULT_TX_TIMEOUT 300

//
// Device types
//
typedef ULONG FT_DEVICE;

enum {
FT_DEVICE_BM,
FT_DEVICE_AM,
FT_DEVICE_100AX,
FT_DEVICE_UNKNOWN,
FT_DEVICE_2232C,
FT_DEVICE_232R,
FT_DEVICE_2232H,
FT_DEVICE_4232H,
FT_DEVICE_232H,
FT_DEVICE_X_SERIES
};

//
// Bit Modes
//
#define FT_BITMODE_RESET 0x00
#define FT_BITMODE_ASYNC_BITBANG 0x01
#define FT_BITMODE_MPSSE 0x02
#define FT_BITMODE_SYNC_BITBANG 0x04
#define FT_BITMODE_MCU_HOST 0x08
#define FT_BITMODE_FAST_SERIAL 0x10
#define FT_BITMODE_CBUS_BITBANG 0x20
#define FT_BITMODE_SYNC_FIFO 0x40

//
// FT232R CBUS Options EEPROM values
//
#define FT_232R_CBUS_TXDEN 0x00 // Tx Data Enable
#define FT_232R_CBUS_PWRON 0x01 // Power On
#define FT_232R_CBUS_RXLED 0x02 // Rx LED
#define FT_232R_CBUS_TXLED 0x03 // Tx LED
#define FT_232R_CBUS_TXRXLED 0x04 // Tx and Rx LED
#define FT_232R_CBUS_SLEEP 0x05 // Sleep
#define FT_232R_CBUS_CLK48 0x06 // 48MHz clock
#define FT_232R_CBUS_CLK24 0x07 // 24MHz clock
#define FT_232R_CBUS_CLK12 0x08 // 12MHz clock
#define FT_232R_CBUS_CLK6 0x09 // 6MHz clock
#define FT_232R_CBUS_IOMODE 0x0A // IO Mode for CBUS bit-bang
#define FT_232R_CBUS_BITBANG_WR 0x0B // Bit-bang write strobe
#define FT_232R_CBUS_BITBANG_RD 0x0C // Bit-bang read strobe

//
// FT232H CBUS Options EEPROM values
//
#define FT_232H_CBUS_TRISTATE 0x00 // Tristate
#define FT_232H_CBUS_TXLED 0x01 // Tx LED
#define FT_232H_CBUS_RXLED 0x02 // Rx LED
#define FT_232H_CBUS_TXRXLED 0x03 // Tx and Rx LED
#define FT_232H_CBUS_PWREN 0x04 // Power Enable
#define FT_232H_CBUS_SLEEP 0x05 // Sleep
#define FT_232H_CBUS_DRIVE_0 0x06 // Drive pin to logic 0
#define FT_232H_CBUS_DRIVE_1 0x07 // Drive pin to logic 1
#define FT_232H_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang
#define FT_232H_CBUS_TXDEN 0x09 // Tx Data Enable
#define FT_232H_CBUS_CLK30 0x0A // 30MHz clock
#define FT_232H_CBUS_CLK15 0x0B // 15MHz clock
#define FT_232H_CBUS_CLK7_5 0x0C // 7.5MHz clock

//
// FT X Series CBUS Options EEPROM values
//
#define FT_X_SERIES_CBUS_TRISTATE 0x00 // Tristate
#define FT_X_SERIES_CBUS_RXLED 0x01 // Tx LED
#define FT_X_SERIES_CBUS_TXLED 0x02 // Rx LED
#define FT_X_SERIES_CBUS_TXRXLED 0x03 // Tx and Rx LED
#define FT_X_SERIES_CBUS_PWREN 0x04 // Power Enable
#define FT_X_SERIES_CBUS_SLEEP 0x05 // Sleep
#define FT_X_SERIES_CBUS_DRIVE_0 0x06 // Drive pin to logic 0
#define FT_X_SERIES_CBUS_DRIVE_1 0x07 // Drive pin to logic 1
#define FT_X_SERIES_CBUS_IOMODE 0x08 // IO Mode for CBUS bit-bang
#define FT_X_SERIES_CBUS_TXDEN 0x09 // Tx Data Enable
#define FT_X_SERIES_CBUS_CLK24 0x0A // 24MHz clock
#define FT_X_SERIES_CBUS_CLK12 0x0B // 12MHz clock
#define FT_X_SERIES_CBUS_CLK6 0x0C // 6MHz clock
#define FT_X_SERIES_CBUS_BCD_CHARGER 0x0D // Battery charger detected
#define FT_X_SERIES_CBUS_BCD_CHARGER_N 0x0E // Battery charger detected inverted
#define FT_X_SERIES_CBUS_I2C_TXE 0x0F // I2C Tx empty
#define FT_X_SERIES_CBUS_I2C_RXF 0x10 // I2C Rx full
#define FT_X_SERIES_CBUS_VBUS_SENSE 0x11 // Detect VBUS
#define FT_X_SERIES_CBUS_BITBANG_WR 0x12 // Bit-bang write strobe
#define FT_X_SERIES_CBUS_BITBANG_RD 0x13 // Bit-bang read strobe
#define FT_X_SERIES_CBUS_TIMESTAMP 0x14 // Toggle output when a USB SOF token is received
#define FT_X_SERIES_CBUS_KEEP_AWAKE 0x15 //


// Driver types
#define FT_DRIVER_TYPE_D2XX 0
#define FT_DRIVER_TYPE_VCP 1

#ifdef __cplusplus
extern "C" {
#endif

FTD2XX_API
FT_STATUS WINAPI FT_Open(
int deviceNumber,
FT_HANDLE *pHandle
);

--由于我能写的字符数限制,头文件的其余部分被省略了。

很抱歉我在这里提供了大量代码,我只是想确保我提供了我可能提供的所有内容。让我知道是否需要提供头文件的其余部分。

最佳答案

也许要晚一点才能得到答案。我对旧的过时的 ftd2xx.lib 文件有同样的错误。添加新的 ftd2xx.lib、ftd2xx.dll 和 ftd2xx.h 文件后,清理并重建项目,问题就解决了。

关于c++ - Unresolved external 错误 - 使用 FTD2XX.h 的 Visual C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17956835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com