## libftdi@developer.intra2net.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

#### Compiling libftdi with MSVC on Windows Thomas HellerWed Apr 04 03:01:04 2012

Actually it is really easy to compile libftdi on Windows, with MSVC (currently I'm only interested in the dll itself, not the other stuff).
```
```
Inside a MSVC command prompt, I have built libftdi.dll with this command line:
```
```
cl /Ox /LD -I ..\..\libusb-win32-bin-1.2.6.0\include ftdi.c /Felibftdi.dll ..\..\libusb-win32-bin-1.2.6.0\lib\msvc\libusb.lib
```
```
I had to specify the path of the libusb import library and the directory of the libusb include file.
```Unfortunately the libusb include file must be renamed or copied
from lusb0_usb.h to usb.h.

```
This library does not define any exported functions, I have made a patch that fixes this which is appended.
```
```
Would a patch like this (it is against the libftdi-0.x branch of the git repository) be accepted?
```
Thomas

PS: Building with CMAKE also works on windows, although again I only
tested building the DLL itself, neither examples, docs, or whatever.

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [EMAIL PROTECTED]   ```
```diff --git a/src/ftdi.h b/src/ftdi.h
index 6bb7a3e..daa8fdb 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -172,11 +172,14 @@ enum ftdi_module_detach_mode

#ifdef __GNUC__
#define DEPRECATED(func) func __attribute__ ((deprecated))
+    #define EXPORT /**/
#elif defined(_MSC_VER)
#define DEPRECATED(func) __declspec(deprecated) func
+    #define EXPORT __declspec(dllexport)
#else
#pragma message("WARNING: You need to implement DEPRECATED for this
compiler")
#define DEPRECATED(func) func
+    #define EXPORT /**/
#endif

@@ -361,95 +364,95 @@ extern "C"
{
#endif

-    int ftdi_init(struct ftdi_context *ftdi);
-    struct ftdi_context *ftdi_new(void);
-    int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface
interface);
-
-    void ftdi_deinit(struct ftdi_context *ftdi);
-    void ftdi_free(struct ftdi_context *ftdi);
-    void ftdi_set_usbdev (struct ftdi_context *ftdi, usb_dev_handle *usbdev);
-
-    int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list
**devlist,
-                          int vendor, int product);
-    void ftdi_list_free(struct ftdi_device_list **devlist);
-    void ftdi_list_free2(struct ftdi_device_list *devlist);
-    int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct usb_device *dev,
-                             char * manufacturer, int mnf_len,
-                             char * description, int desc_len,
-                             char * serial, int serial_len);
-
-    int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
-    int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
+    int EXPORT ftdi_init(struct ftdi_context *ftdi);
+    struct ftdi_context EXPORT *ftdi_new(void);
+    int EXPORT ftdi_set_interface(struct ftdi_context *ftdi, enum
ftdi_interface interface);
+
+    void EXPORT ftdi_deinit(struct ftdi_context *ftdi);
+    void EXPORT ftdi_free(struct ftdi_context *ftdi);
+    void EXPORT ftdi_set_usbdev (struct ftdi_context *ftdi, usb_dev_handle
*usbdev);
+
+    int EXPORT ftdi_usb_find_all(struct ftdi_context *ftdi, struct
ftdi_device_list **devlist,
+                                 int vendor, int product);
+    void EXPORT ftdi_list_free(struct ftdi_device_list **devlist);
+    void EXPORT ftdi_list_free2(struct ftdi_device_list *devlist);
+    int EXPORT ftdi_usb_get_strings(struct ftdi_context *ftdi, struct
usb_device *dev,
+                                    char * manufacturer, int mnf_len,
+                                    char * description, int desc_len,
+                                    char * serial, int serial_len);
+
+    int EXPORT ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int
product);
+    int EXPORT ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int
product,
const char* description, const char* serial);
-    int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int
product,
-                           const char* description, const char* serial,
unsigned int index);
-    int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct usb_device *dev);
-    int ftdi_usb_open_string(struct ftdi_context *ftdi, const char*
description);
+    int EXPORT ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor,
int product,
+                                        const char* description, const char*
serial, unsigned int index);
+    int EXPORT ftdi_usb_open_dev(struct ftdi_context *ftdi, struct usb_device
*dev);
+    int EXPORT ftdi_usb_open_string(struct ftdi_context *ftdi, const char*
description);

-    int ftdi_usb_close(struct ftdi_context *ftdi);
-    int ftdi_usb_reset(struct ftdi_context *ftdi);
-    int ftdi_usb_purge_rx_buffer(struct ftdi_context *ftdi);
-    int ftdi_usb_purge_tx_buffer(struct ftdi_context *ftdi);
-    int ftdi_usb_purge_buffers(struct ftdi_context *ftdi);
+    int EXPORT ftdi_usb_close(struct ftdi_context *ftdi);
+    int EXPORT ftdi_usb_reset(struct ftdi_context *ftdi);
+    int EXPORT ftdi_usb_purge_rx_buffer(struct ftdi_context *ftdi);
+    int EXPORT ftdi_usb_purge_tx_buffer(struct ftdi_context *ftdi);
+    int EXPORT ftdi_usb_purge_buffers(struct ftdi_context *ftdi);

-    int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
-    int ftdi_set_line_property(struct ftdi_context *ftdi, enum ftdi_bits_type
bits,
-                               enum ftdi_stopbits_type sbit, enum
ftdi_parity_type parity);
-    int ftdi_set_line_property2(struct ftdi_context *ftdi, enum ftdi_bits_type
bits,
-                                enum ftdi_stopbits_type sbit, enum
ftdi_parity_type parity,
-                                enum ftdi_break_type break_type);
+    int EXPORT ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
+    int EXPORT ftdi_set_line_property(struct ftdi_context *ftdi, enum
ftdi_bits_type bits,
+                                      enum ftdi_stopbits_type sbit, enum
ftdi_parity_type parity);
+    int EXPORT ftdi_set_line_property2(struct ftdi_context *ftdi, enum
ftdi_bits_type bits,
+                                       enum ftdi_stopbits_type sbit, enum
ftdi_parity_type parity,
+                                       enum ftdi_break_type break_type);

-    int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int
size);
-    int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int
chunksize);
-    int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int
*chunksize);
+    int EXPORT ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf,
int size);
+    int EXPORT ftdi_read_data_set_chunksize(struct ftdi_context *ftdi,
unsigned int chunksize);
+    int EXPORT ftdi_read_data_get_chunksize(struct ftdi_context *ftdi,
unsigned int *chunksize);

-    int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int
size);
-    int ftdi_write_data_set_chunksize(struct ftdi_context *ftdi, unsigned int
chunksize);
-    int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int
*chunksize);
+    int EXPORT ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf,
int size);
+    int EXPORT ftdi_write_data_set_chunksize(struct ftdi_context *ftdi,
unsigned int chunksize);
+    int EXPORT ftdi_write_data_get_chunksize(struct ftdi_context *ftdi,
unsigned int *chunksize);

-    int ftdi_write_data_async(struct ftdi_context *ftdi, unsigned char *buf,
int size);
-    void ftdi_async_complete(struct ftdi_context *ftdi, int wait_for_more);
+    int EXPORT ftdi_write_data_async(struct ftdi_context *ftdi, unsigned char
*buf, int size);
+    void EXPORT ftdi_async_complete(struct ftdi_context *ftdi, int
wait_for_more);

-    int DEPRECATED(ftdi_enable_bitbang(struct ftdi_context *ftdi, unsigned
-    int ftdi_disable_bitbang(struct ftdi_context *ftdi);
-    int ftdi_set_bitmode(struct ftdi_context *ftdi, unsigned char bitmask,
unsigned char mode);
-    int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
+    int EXPORT DEPRECATED(ftdi_enable_bitbang(struct ftdi_context *ftdi,
+    int EXPORT ftdi_disable_bitbang(struct ftdi_context *ftdi);
+    int EXPORT ftdi_set_bitmode(struct ftdi_context *ftdi, unsigned char
+    int EXPORT ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);

-    int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char
latency);
-    int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char
*latency);
+    int EXPORT ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char
latency);
+    int EXPORT ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char
*latency);

-    int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short
*status);
+    int EXPORT ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned
short *status);

/* flow control */
-    int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl);
-    int ftdi_setdtr_rts(struct ftdi_context *ftdi, int dtr, int rts);
-    int ftdi_setdtr(struct ftdi_context *ftdi, int state);
-    int ftdi_setrts(struct ftdi_context *ftdi, int state);
+    int EXPORT ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl);
+    int EXPORT ftdi_setdtr_rts(struct ftdi_context *ftdi, int dtr, int rts);
+    int EXPORT ftdi_setdtr(struct ftdi_context *ftdi, int state);
+    int EXPORT ftdi_setrts(struct ftdi_context *ftdi, int state);

-    int ftdi_set_event_char(struct ftdi_context *ftdi, unsigned char eventch,
unsigned char enable);
-    int ftdi_set_error_char(struct ftdi_context *ftdi, unsigned char errorch,
unsigned char enable);
+    int EXPORT ftdi_set_event_char(struct ftdi_context *ftdi, unsigned char
eventch, unsigned char enable);
+    int EXPORT ftdi_set_error_char(struct ftdi_context *ftdi, unsigned char
errorch, unsigned char enable);

/* set eeprom size */
-    void ftdi_eeprom_setsize(struct ftdi_context *ftdi, struct ftdi_eeprom
*eeprom, int size);
+    void EXPORT ftdi_eeprom_setsize(struct ftdi_context *ftdi, struct
ftdi_eeprom *eeprom, int size);

/* init and build eeprom from ftdi_eeprom structure */
-    void ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom);
-    void ftdi_eeprom_free(struct ftdi_eeprom *eeprom);
-    int ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char *output);
-    int ftdi_eeprom_decode(struct ftdi_eeprom *eeprom, unsigned char *output,
int size);
+    void EXPORT ftdi_eeprom_initdefaults(struct ftdi_eeprom *eeprom);
+    void EXPORT ftdi_eeprom_free(struct ftdi_eeprom *eeprom);
+    int EXPORT ftdi_eeprom_build(struct ftdi_eeprom *eeprom, unsigned char
*output);
+    int EXPORT ftdi_eeprom_decode(struct ftdi_eeprom *eeprom, unsigned char
*output, int size);

/* "eeprom" needs to be valid 128 byte eeprom (generated by the eeprom
generator)
the checksum of the eeprom is valided */
-    int ftdi_read_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
-    int ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int *chipid);
-    int ftdi_read_eeprom_getsize(struct ftdi_context *ftdi, unsigned char
*eeprom, int maxsize);
-    int ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char *eeprom);
-    int ftdi_erase_eeprom(struct ftdi_context *ftdi);
+    int EXPORT ftdi_read_eeprom(struct ftdi_context *ftdi, unsigned char
*eeprom);
+    int EXPORT ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int
*chipid);
+    int EXPORT ftdi_read_eeprom_getsize(struct ftdi_context *ftdi, unsigned
char *eeprom, int maxsize);
+    int EXPORT ftdi_write_eeprom(struct ftdi_context *ftdi, unsigned char
*eeprom);
+    int EXPORT ftdi_erase_eeprom(struct ftdi_context *ftdi);

unsigned short *eeprom_val);
-    int ftdi_write_eeprom_location(struct ftdi_context *ftdi, int eeprom_addr,
unsigned short eeprom_val);
+    int EXPORT ftdi_read_eeprom_location (struct ftdi_context *ftdi, int
+    int EXPORT ftdi_write_eeprom_location(struct ftdi_context *ftdi, int

-    char *ftdi_get_error_string(struct ftdi_context *ftdi);
+    char EXPORT *ftdi_get_error_string(struct ftdi_context *ftdi);

#ifdef __cplusplus
}
```