Setting up Eclipse CDT IDE to use the D2XX library

Pinterest icon

eclipse CDT splash screen

Like the previous article  you can skip this section if you are comfortable with the eclipse environment and knows how to setup a compiler , link a library and so on,also i am talking about the C/C++ version of the eclipse, the eclipse CDT.


The Eclipse CDT i am using is this the CDT 8.3.0 Kepler.Go to the download section of the eclipse CDT website and download the CDT 8.3.0 Kepler package,unlike the Code:: Blocks IDE eclipse is a hefty download averaging around 200 MB.The download the zip package and unzip the package in a directory of your choice .Like Code:: Blocks  eclipse do not come with a compiler and debugger and depends upon third party tools like GCC.

After unzipping the package, click on the eclipse.exe to launch the program.The eclipse IDE will immediately asks to create a workspace to store all your related projects.You can create multiple workspaces to organize your projects .In this case let's create a folder called " FTDI " to store all our FTDI related projects.It is possible to switch from one workspace to another from within the eclipse IDE by going to " FileSwitch Workspace ".

eclipse workspace for FTDI

Creating a C Project in Eclipse

After the workspace location is finalized ,Eclipse will greet you with a welcome screen.Close it and go to " File ? New ? C Project " to create a new c project.We are going to use the same C files as in tutorial 2 (dtr.c) in this one also as the emphasis is on how to use the eclipse IDE.It will open a new window called  C Project.Give a name to your project,lets say "dtr_toggle".Now click on  "Empty Project " under the  "Project Type " section and select the "MinGW GCC" under "ToolChains".Click Next and in the second window make sure that the "Debug " and "Release" options are checked ,Press finish .

creating a c project in eclipse kepler

Now under the " Project Explorer " you can see a folder with your projects name (here dtr_toggle),Click on it and it will show the paths to the required files for MinGW.

eclipse compiler paths

By Right clicking on the project folder (dtr_toggle) and selecting " New " you can  add a new C file ,a header file, a folder etc  to your project.Another feature is the " import " feature of the IDE which helps to add files from other locations.When you are " importing " a file from an another location  the file is actually copied into your project folder So the original file remains unchanged.

In this example we are going to create a simple project to toggle the DTR Pin of FT232 using the D2XX library and the "Dtr.c " file from the previous project.

Inside your Project create three folders "Source" for your source codes,"Library" for ftd2xx.lib,"Header" for ftd2xx.h.

After you have created the folders,Right click on the folder(Source) and select " Import..." which would open another window called "Import".Click on "General" and select "File system".

using the import command to add files

After that navigate to the folder where you have the "Dtr.c" using the "Browse" button.Once you have reached the folder ,the right pane will display all the files that are available in the selected folder.Check the file you want to import and click "Finish".The selected file would appear under the "Source" folder.Now repeat that with Library and the Header folder.

After all the files are added ,Your "Project Explorer" should look like this .

Finished view of the project explorer

Linking the Library in Eclipse CDT

To link the library ftd2xx.lib ,Right Click on the project "dtr_toggle" folder and select "Properties".

Which will open the properties window for dtr_toggle,On the left pane click on the "C/C++ Build Settings" ?"Settings"

On the right pane it will open the Settings.

Under " Configuration: " ,Pull down the drop down menu to select " [All Configurations] " instead of debug or release.

Under "Tool Settings" tab, select " MinGW Linker " ? " Libraries ".

On the right side you can see " Libraries (-l) " where you have to give the name of the library .Press the Add button(one with the + sign)  and a dialog will pop up asking for the name of the library ,type " ftd2xx " (without quotes) and  pressOK.

Please note that you have to type " ftd2xx " not " ftd2xx.lib " as the later would result in a file not found error.

Now in the "Library Search Path (-L)  add the path to the ftd2xx.lib by selecting the "Add button".Another dialog will popup asking you to enter the path to your library .There are  two ways to add the path by using either "Workspace" or " File system "."Workspace" option is quite easy compared to file system .

setting the linker options in eclipse cdt

After the configuration for your path is completed .It should look some thing like this.(i have used the workspace option to set up the search path) 

search paths for library in eclipse cdt

Setting up Paths for Header files

And one more thing since the header file in our project is inside the " Header " folder,

We have to configure the search paths for the header file .If we are placing both the ftd2xx.h and Dtr.c in the same folder this problem will not happen.

To set up the paths for the header files,Go to" Tool Settings" Tab under which click " GCC C Compiler ? Includes "and use the add button (one with the + sign)  to select the path to the "Header" folder .

Adding paths to include the header files in eclipse


Building the Project

After all the settings for our project are configured ,Go to menu " Project " ? "Build Project" to build the whole project.If the build is successfully completed with zero errors.You can run your compiled project by going to " Run? " Run ".

running the project in eclipse

Now you can see the output of your program in the eclipse default console like this 

"Press any key to continue "

and if you press any key you will get a jumbled output like this

jumbled output from command line

compared to this

correct order

In the eclipse console output, the order in which the statements are printed  changes compared to the original output (black screen,cmd.exe) .The eclipse console prints only after it has received something as input.If you open your project folder and go to the "Debug" folder and runs the executable separately in the command line,the output will be same as the original (black screen,cmd.exe). This is due to a bug in the eclipse IDE .

To rectify this problem add this lines at the very beginning of your code


like this


with the output now appearing correctly ,Note the position of " Press any key to continue...."

Unlike other IDE's Eclipse do not automatically save the file before compiling.You have to explicitly save the file by pressing CTRL + S ,Otherwise  you will get a message like "nothing to build".


Previous Tutorial                                      MainPage                                         Next Tutorial