2

I am having trouble making a program to interact with an FTDI chip. I don't know how much information I can give in regards to the model number of the chip.

I am trying to use the API FTDI provides to communicate with the chip I have. I am using Qt Creator for the program and this is my first time using it. All of the examples I have found use include "ftd2xx.h". Well, I have tried so many ways to get it working. I have manually typed in the directory of the ftd2xx.lib, moved the files to the project directory and chose "Internal Library", used the original directory and chose "External Library", and chosen the "System Library".

The only method that gives me a different error is when I include the driver package files in the project directory and just include the header file with or without the LIBS += .... Even then I get 393 errors saying NAME does not name a type, NAME not declared in scope, etc.

How do I create a Qt Creator C++ project that recognizes the ftd2xx.lib and lets me use the functions from ftd2xx.h?

EDIT: I am using the Windows 64bit driver package. In my frustration, I forgot I should include these important details.

EDIT2: Code below.

main.cpp

#include <QCoreApplication>
#include <iostream>
#include "ftd2xx.h"
using namespace std;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    cout << "test" << endl;

    return a.exec();
}

test.pro

#-------------------------------------------------
#
# Project created by QtCreator 2013-10-04T16:31:18
#
#-------------------------------------------------

QT       += core

QT       -= gui

TARGET = test
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app


SOURCES += main.cpp

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -lftd2xx
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -lftd2xxd
else:unix: LIBS += -L$$PWD/ -lftd2xx

INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

Errors

Errors.png

All of that is followed by more NAME does not name a type errors.

KrimCard
  • 213
  • 2
  • 5
  • 12
  • Pretty sure `.lib` files are wrapped windows DLLs. Are you on windows or linux? I assumed linux because you're using Qt Creator. – Falmarri Oct 04 '13 at 21:27
  • Creator works just fine on Windows... – Chris Oct 04 '13 at 21:40
  • 1
    @Falmarri I am on Windows. Sorry about not mentioning that. I am using Qt Creator because the project won't allow VS. – KrimCard Oct 04 '13 at 21:49
  • `NAME does not name a type` and the like are not linking errors. They are compilation errors. Libraries are irrelevant at this point, as you haven't got to the linking stage yet. Sort out the compilation errors first. – n. m. could be an AI Oct 04 '13 at 22:07
  • If you don't know how to fix a compilation error and ask strangers, you need to show the exact code that doesn't compile; the exact message(s) the compiler emits; and the exact compilation command you are using. – n. m. could be an AI Oct 04 '13 at 22:17
  • @n.m. There isn't much code to show besides one `cout` statement. Those errors come after the last method I detailed. I guess I don't know how to compile the driver package files. – KrimCard Oct 04 '13 at 22:25
  • What do you plan to use it for, serial port or something else? – László Papp Oct 05 '13 at 01:41

1 Answers1

4

The ftd2xx header has a lot of Windows types in it so you need to include windows.h before including the ftdi header.

The .lib file is a DLL link library which provides the linker information required to make use of the DLL at runtime. The following compiles and runs using g++:

#include <windows.h>
#include <stdio.h>
#include <ftd2xx.h>
int main(int argc, char *argv[])
{
    DWORD version = 0;
    FT_STATUS status = FT_GetLibraryVersion(&version);
    printf("version %ld\n", version);
    return (status == FT_OK) ? 0 : 1;
}

Compiled using:

g++ -Wall -Idriver -o check.exe check.cpp driver/i386/ftd2xx.lib

where the driver folder contains the distributed FTDI windows driver package. The -lftd2xx will have the linker searching for something called libftd2xx.a so just explicitly provide the .lib filename.

syam
  • 14,701
  • 3
  • 41
  • 65
patthoyts
  • 32,320
  • 3
  • 62
  • 93
  • This works perfectly. My only concern is if I am allowed to use g++. The project is using Qt Creator because of licensing issues. If Qt Creator is fine then I am sure g++ is, as well. However, I can't verify at the moment if Qt Creator was chosen for other reasons. Would it be too much trouble to do the above in Qt Creator? If not, that is fine. This answer has cleared some things up and I might be able to proceed. Thank you so much. – KrimCard Oct 04 '13 at 23:33
  • I used g++ because I suspect that's what is used by Qt Creator but I don't have that available. The real issue is getting the types defined. Either by including a windows header or making a types header if you need compatibility with non-Windows systems. That and providing the right linker option to get the linker to use the .lib file correctly. The actual compiler used shouldn't matter. The above worked with Visual C++ too. – patthoyts Oct 04 '13 at 23:39
  • Gah, I should really remember the fixes I did before asking for help. I found out what was the problem in Qt Creator. The folder holding the driver package had spaces in the name. I had to remove those to get the g++ working. I immediately forgot that detail after it worked and asked the above question. Now, using a new folder without spaces, Qt Creator works fine. Thanks for the help. – KrimCard Oct 04 '13 at 23:47
  • @KrimCard: Qt Creator is the IDE. Its license is irrelevant for you. Maybe you meant Qt? *Please* don't conflate the two. – Kuba hasn't forgotten Monica Oct 05 '13 at 01:02
  • The ftd2xx.h header is basically a tour the force of how not to write headers. The fact that they didn't include is the dead giveaway of the level of cluelessness there. – Kuba hasn't forgotten Monica Oct 05 '13 at 01:04