Technion - Israel Institute of Technology  
234122 - Introduction to Systems Programming - מבוא לתכנות מערכות
  Spring 2012 EnglishRussianHebrewArabic  
Frequently Asked Questions - Working with Eclipse CDT
.. (parent folder)
Here are a list of problems you may encounter when working with Eclipse CDT. Make sure you look for your problem here before sending an E-mail about it.

Some problems can arise if Eclipse is installed in a directory which has Hebrew directory names in the path to it. For example : C:\מתמ\Eclipse. The problem can also arise if a workspace is opened in such a directory, for example C:\מתמ\Ex1 .
If everything works for you – do not change anything.

If you have problems with mingw libraries, gcc or gdb not found, do the following:

1. Go to Control Panel, "Clock, Language, and Region", "Regional and Language Options".
Go to the last tab "Administrative and change "Language for non-Unicode programs" into "Hebrew (Israel)". (A restart will be required)

If it does not help, do the following:

2. Copy Eclipse directory to some directory without Hebrew names in its path, for example C:\Eclipse. Create a new workspace, for example C:\workspace and import the previous project into the new workspace by using File->Import ->General->Existing Projects into Workspace. Alternatively, you can simply open a new project , add and copy the files one by one to this new project from the old project.
Choosing the right Tool Chain
Please pay attention to selecting MinGW GCC toolchain when you create an Eclipse project, see http://webcourse.cs.technion.ac.il/234122/Spring2009/ho/WCFiles/eclipse_project_toolchain.JPG . If you forget to do it, you can change the toolchain to MinGW GCC in Project -> Properties -> C/C++ Build -> Tool Chain Editor. See http://webcourse.cs.technion.ac.il/234122/Spring2009/ho/WCFiles/eclipse_tool_chain.JPG
Q. How do I use the files you supplied in my Eclipse CDT project? (Such as an object file)
A. First you will need to copy the files, including the object file into your Eclipse project. You can do that by simply dragging them into the project folder in the "Project Explorer" tree in Eclipse.
See http://webcourse.cs.technion.ac.il/234122/Spring2009/ho/WCFiles/eclipse_add_object_project_explorer.JPG
To link the object file (Which contains the implementation) you will need to add the object file for the linker options. To do that:
1. Open Project, Properties.
2. In that dialog select "C++ Build, Settings".
3. Under the Tool Settings tab choose "Linker" or "MinGW C Linker" or equivalent and under that select "Miscellaneous".
4. Under the "Other Objects" press the "Add..." button (the green cross) and type the name of the supplied object. Do not use Workspace or File system options, just type the name of the object.
See "before and after" screenshots:
before: http://webcourse.cs.technion.ac.il/234122/Spring2009/ho/WCFiles/eclipse_add_object.JPG
after: http://webcourse.cs.technion.ac.il/234122/Spring2009/ho/WCFiles/eclipse_added_object.JPG
Q. How do I add a static library file to a project? (Files such as libmtm.a)
A. First you will need to copy the file into your Eclipse project. You can do that by simply dragging it into the project folder in the "Project Explorer" tree in Eclipse.
To link the library (A static library is used similarly to an object file):
1. Open Project, Properties.
2. In that dialog select "C++ Build, Settings".
3. Under the Tool Settings tab choose "Linker" or "MinGW C Linker" or equivalent and under that select "Libraries".
4. Under "Libraries" press the "Add..." button (the green cross) and write the name of the library without the "lib" prefix and ".a" suffix. e.g. in order to link the library file libmtm.a write "mtm".
5. Under "Library search path" press the "Add..." button, select workspace and select the project.
Q. When I try to run my project in Eclipse I get a "Launch failed. Binary not found." error
A. That means there is no compiled binary of the project to run.
Follow the following steps:
- Build your project by choosing "Project | Build all" (Or press Ctrl+B), make sure the build has succeeded - Under your project in the explorer (tree view) you should see a "Binary" label containing all binaries in the project. If you don't see that make sure no compilation errors occurred (Look at the console window, or "problems" window), make sure your project name does not contain spaces.
- Once your project is go to "Run | Run configurations...", double click on "Local C/C++ Application" to create a new suitable configuration. If the project name or application name are missing use "Browse" to select the right project and "Search project" to locate the newly created binary file.
- Select "Run"
Q. I have the following error:
gcc: C:\Documents: No such file or directory
gcc: and: No such file or directory
gcc: Settings\sxxx\workspace\ex1\mtm_ex1.o: No such file or directory
Build error occurred, build is stopped
A. You probably added mtm_ex1.o via Workspace or File system. You should just type "mtm_ex1.o" , as explained in the previous question.
Q. I have the following error : cannot open output file mtm_sale.exe: Permission denied collect2: ld returned 1 exit status Build error occurred, build is stopped
A. You probably have the previous version of your program still running. You should terminate it - go to Debug view and push the red button (Red square - "Terminate").
Q. Sometimes, after I start Eclipse, it shows errors which were already fixed previously. What is the matter ?
A. Just run Project-> Clean and build, and the errors will disappear (if they indeed were fixed).
Q. I have the following error:
..\mtm_ex1.o: In function `mtmPrintErrorMessage': .../mtm_ex1.c:7: undefined reference to `__assert'
A. You probably use a wrong Tool Chain. See "Choosing the right Tool Chain item"
Q. I have the following error:
make: *** No rule to make target `mtm_ex1.o', needed by `mtm_sale.exe'. Stop.
A. You probably use a wrong Tool Chain and a wrong Builder. See "Choosing the right Tool Chain item"
Q. I have the following error:
(Cannot run program "make": Launching failed)
A. You probably use a wrong Builder. See "Choosing the right Tool Chain item"
Q. Eclipse does not print output/error messages to the console !
A. Just insert the following two lines in the beginning of main():
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
Q. Wait! What do these two lines from the previous answer mean?
A. O.K. Here goes:

Input / Output operations (Like writing to a file or the screen) are in fact very slow.
However in a lot of cases writing a reasonably sized string at once can take the same time as writing one character only.
Because of that I/O operations are made using a buffer. For example every time your program prints (by calling printf etc...) the data is first copied into a buffer that is part of the appropriate FILE* and only once in a while the data is actually passed on to the output device.

Unfortunately, this it not the behavior you would want with a terminal window. Because of that output in terminals is usually flushed after each line or every character.
Unfortunately (again), under Windows, Eclipse CDT cannot automatically make its console behave like a terminal which may cause re-ordering of I/O operations.
Luckily, you can simply change the buffer size of a FILE* in C, or remove it completely. To do so you use the function setvbuf.
The two lines mentioned before will simply disable any buffering for stdout and stderr and solve the problem.
If you wish to learn more about setvbuf you can do so here.


Q. How can I find/create useful shortcuts in Eclipse?
A. Press ctrl+shift+L to see the shortcuts. If you wish to change any of them, press ctrl+shift+L twice (that is, once more after you enter the shortcuts window) and you will find the keys prepferences window pop up.
Q. How can I pass arguments to a program in Eclipse ?
A. Go to Run -> Run Configurations -> Arguments , and write the arguments in the Program Arguments box.
Link:  http://webcourse.cs.technion.ac.il/234122/Winter2009-2010/ho/WCFiles/RunConfigurations.JPG
Q. I have a problem with debugging in Eclipse. I put a breakpoint and run the program. Eclipse prints the following message: 149*stopped,reason="breakpoint-hit",bkptno="3",thread-id="1",frame= ... and nothing happens after that message.
A. There is a problem with debugging in Eclipse in a console mode (handling input/output via the console). You should pass the input/output files by using –i and –o flags for debugging. See the question above how to pass arguments to a program in Eclipse.
Q: How do I add a library (.a) file to an Eclipse project?
A: Go to Settings->MinGW C Linker->libraries. There, add mtm as under "libraries" (press the green plus sign) and add the correct directory path under "Library search path" (press the second green plus sign and choose "workspace" and then the project folder.
Link:  http://webcourse.cs.technion.ac.il/234122/Spring2009/ho/WCFiles/eclipse_link_libmtm_library.JPG
Q. I am using Windows Vista and Eclipse there is unable to find includes, even stdio.h. What should I do ?
A. There is a problem in Eclipse in Vista when Eclipse is installed in a directory that has whitespaces in a path, for example "My Documents" or "Program Files". You should just copy the Eclipse to a directory without whitespaces, for example "C:\Eclipse".
Q. When I link the project in Eclipse I get this error message :"..\..\: No such file: No such file or directory"
A. Try to do the following:
1. drag mtm_ex1.o to your project
2. write in the linker options mtm_ex1.o as is, not using Workspace or File system options
Q. Where should I put the tests file ,so Eclipse could read them by providing "-i test.in -o test.out" as arguments ?
A. Two options:
1. You can drag the files into the Eclipse project
2. You can put the tests in any directory and just specify a full path to them (inside quotes, for example: -i "C:\Ex1\tests\test1.in" -o "C:\Ex1\tests\test1.out" )
Q. I have the following strange behavior in Eclipse: Once I have errors in several files and push the "Build" button, I have an error marked in the file. When I push the "Build" button again, the error can disappear and the Eclipse will complain about an error in another file. I push the Build again, and the error marker will appear again. This way once I fix an error and the error marker disappears, I never know if the error was fixed or Eclipse just switched to an error in another file. So I have to push the Build button several times until I can be sure I have fixed the error.
A. You can fix this behavior in the following way:
Go to Project -> Properties -> C/C++ Build -> Behavior tab, uncheck "Stop on first build error"
Q. My Eclipse is unable to find standard headers like stdio.h . What can I do ?
A. You should do the following:
1. Go to Properties -> C/C++ general -> Paths and Symbols -> Includes -> GNU C, Add, and add the following directories C:/eclipse/mingw/include and C:/eclipse/mingw/lib/gcc/mingw32/3.4.5/include . You should use your eclipse directory instead of C:/eclipse.
2. Go to Properties -> C/C++ build -> Settings -> MinGW Linker -> Miscellaneous -> Linker flags and write there :
-B C:/eclipse/mingw/lib -B C:/eclipse/mingw/lib/gcc/mingw32/3.4.5
You should use your eclipse directory instead of C:/eclipse.
Q. The Console view says "mi_cmd_var_create: unable to create variable object"
A. Maybe the "Expressions" view tries to show variables from old projects, which aren't recognized in the current project.