Eclipse CDT and shared libraries

I had some trouble getting Eclipse CDT (C/C++ Development Toolkit) to work across separate projects. My setup is Eclipse 3.3.1 with CDT 4.0.1 on Windows with the MinGW toolchain. I have two separate projects in Eclipse: One is a shared library and the other is an executable. The executable uses the shared library so naturally it needs to read the header files from the other project in order to sucessfully compile and link. It would also be nice if it was possible to use the Run As Local C/C++ Application feature without the need to copy the shared library file to the directory where the executable file is. I set out on a quest to find the answers.

The first thing you have to do is right-click on the executable project in the Project Explorer, and then go to Properties -> Project References. There you have to select the shared or static library project you want to link to. Then click OK. If you try to build the project it still won’t work because it cannot find the required files.

Let’s open the project properties window again, but this time go to C/C++ General -> Paths and symbols -> References. Make sure that you select the shared/static library under all your configurations. The standard setup contains the Debug and Release configurations which you can switch between with the dropdown list at the top of the window. To make sure that you always link against the Release version of the library when you build the Release version of your executable you can expand the library reference node and select Release instead of the default [Active] selection. The same thing goes for building against the Debug version of the library when you’re building the Debug version of the executable. Click Apply when you’re done.

You might think that everything should be good to go by now, but we have a bit more to do first. In the project properties window go to C/C++ Build -> Settings -> Tool settings -> MinGW C++ Linker -> Libraries. Click the document with the green plus sign (Add button) right next to where it says Libraries (-l). In the input box that appears you should type the name of the library without its file extension. If your library file is “useful.dll” or “useful.so” then you should only type “useful”. Don’t forget that you have to do this for both the Release and Debug configurations if you don’t want any nasty surprises later on. Click OK when you’re done.

At least now it should compile, but you would maybe like to run it from within Eclipse as well? First you have to create a so called run configuration for your executable. Right-click on the executable in the Project Explorer and go to Run As… -> Local C/C++ Application. This will actually launch the program, but it will also automatically create a run configuration for it. The program will terminate without any error messages because it couldn’t find the library file. On the top menu go to Run -> Open Run Dialog…, select the run configuration for your program (if it isn’t already selected, obviously) and go to the Environment tab. Click New…, name the new environment variable “Path” and give it the value “${env_var:Path};${workspace_loc:/useful/Debug}”. Substitute “useful” for the name of your shared library. This will modify the system environment “Path” variable by adding the full path to the library so that the executable will find it.

If you want to use the Release version of the library then just substitute “Debug” from the environment value with “Release”. Unfortunately I haven’t found a way to detect which build configuration is active so you have to manually change this value if you switch between Debug and Release. An alternative is to create a separate run configuration for Debug and Release. This can easily be done by right-clicking on the run configuration and clicking Duplicate.

NOTE: This post has been imported from my old it’s learning ePortfolio blog.

Advertisements

Guns and ammo

In C, you merely shoot yourself in the foot.

In C++, you accidentally create a dozen instances of yourself and shoot them all in the foot. Providing emergency medical care is impossible, because you can’t tell which are bitwise copies and which are just pointing at others and saying, “That’s me, over there.”

Borrowed from: Const Correctness in C++

NOTE: This post has been imported from my old it’s learning ePortfolio blog.

Progress report for week 38

Another week with bad news: My laptop broke down this weekend and the warranty has expired. It’s a Dell XPS/Inspiron M170 with a juicy nVidia GeForce Go 7800 GTX card. Let me give you a few words of advice.

You know you have a broken video card when:

  1. A short horizontal line appears on the screen while you are happily coding the n-queens transform for DECS.
  2. You ignore it.
  3. Another short horizontal line appears.
  4. You continue to ignore it.
  5. The two horizontal lines start some kind of mating ritual and they start reproducing all over the screen.
  6. You “ignore” the defects by slamming your fists into the keyboard.
  7. The defects are still present after having uninstalled the unofficial graphics card driver (which you had to install to keep up with the latest version from nVidia, because Dell will at best release new versions of their GeForce Go card drivers once a year) and installed the official one.
  8. You boot up Ubuntu Linux hoping to be able to blame Windows XP for the screen corruption, only to find out that a bit of Beryl action reproduces the problem there as well.
  9. You figure out that Ubuntu is better than Windows because in Ubuntu the problem only slows the OS down instead of both slowing it down, crashing the display drivers and continuously flashing the screen on and off, all at the same time.
  10. The defects are still present after you have rebooted more than 24 times in an effort to flush them out of the system.
  11. Half the time you reboot the screen turns black, but you can see that the LCD back light is on and the hard disk activity light is flashing.
  12. You hook up an external monitor, but even that doesn’t exorcise the evil horizontal line spirits.
  13. The external monitor also experiences the black screen on reboot sometimes.
  14. You open the cover above the keyboard, pull out the monitor cable and reattach it just because the Dell support personnel said so.
  15. You run the Dell Hardware Diagnostics program, choose the video corruption symptom and get a bunch of messages like this: “Error Code 5300:0119 Detected a failure while writing and reading video memory. Address SOMEHEXh, expected to read 0h, but read FFFFFFFFh instead.”.
  16. You run the Dell Pre-boot System Assessment program and the color bars are full of defects.
  17. After having told the Pre-boot System Assessment program that the color bars had defects, you are thrown into an infinite loop of full screen frenzy of white, black, red, green, blue and a beeping system speaker without ANY defects showing up whatsoever.

If most of the above apply to you, you have the same laptop as me and your warranty has expired then you should contact the English XPS Premium Technical Support line and have a chat with on of their people from India. They are nice and will get a Dell sales rep to contact you so that you can get your warranty extended and a technician to replace the faulty video card. Unfortunately every third word they say will be unintelligible and every fourth word you say to them will be misunderstood.

My laptop is unfortunately the only computer in the house which has all the applications I need to work on DECS. I’ve hijacked one of the desktop machines at home and started installing the applications I need. So far MiKTeX, TeXnicCenter and TortoiseSVN is ready, but the whole Eclipse C/C++ development environment will take me a bit more time.

Now to the good news: I’ve specified the file format I intend to use for storage and transfer of the DLX matrices. I’ve not taken a stand in the byte order war yet, as I’m uncertain which will be best for the Grid middleware I’m going to use. I’ll cross that bridge when it comes. Currently the memory contents is written to the file without any modification, which works fine for the time being. I remember seeing the byte order debate for the network protocol in the OpenTTD project a while back. Maybe I can take a peek at how they did it since their code is GPL and all?

In other news: I also started on the n-queens forward transform before disaster struck. It requires the generalized form of the DLX algorithm with primary and secondary columns. The modifications to generalize my code to support secondary columns doesn’t appear to be overly dramatic. Just a touch there, a touch there and a computer free of hardware defects would just about do it. I’ve still got some catching up to do according to the project plan, but I’ll make it.

NOTE: This post has been imported from my old it’s learning ePortfolio DECS blog.

Comparison of the IEEE 802.11, 802.15.1, 802.15.4 and 802.15.6 wireless standards

This paper (LaTeX source) was written as an assignment for a course in wireless communication. It expands on the previous Wireless Technology Survey paper by going more into the details on how some of the IEEE standards work. The standards written about in this paper is:

  • 802.11a/b/g/n – Wi-Fi
  • 802.15.1 – Bluetooth
  • 802.15.4 – ZigBee
  • 802.15.6 – Mysterious…

NOTE: This post has been imported from my old it’s learning ePortfolio readables blog.

Progress report for week 37

In week 37 I’ve been working on the report and I’ve written about the architecture design and about exact cover problems and a bit about how the Dancing Links algorithm works. I’ve been looking into some of the other Dancing Links implementations which are released as open source and tried to see how they solved the problems. Most of the implementations were made for one specific purpose (solve sudoku, n-queens and polyomino problems). This is different from my implementation which will be a generic solver, but with direct support for some of the specific problems.

The file format which the problem matrices will be stored in has been sketched out, but I need to investigate what features the Grid middleware has for dealing with file transfer and reading. My main canditate is BOINC, but I’ll be checking out other possible options soon.

I’ve been a bit busy with another report so I’ve not been able to fully implement one of the problem transform like I had planned. Other than that everything is going according to the plan. I’ll make an extra effort to neutralize the slippage the following weeks.

NOTE: This post has been imported from my old it’s learning ePortfolio DECS blog.

Wireless Technology Survey

This paper (LaTeX source) was written as an assignment for a course in wireless communication. It gives an overview of the most important wireless technologies.

NOTE: This post has been imported from my old it’s learning ePortfolio readables blog.

Progress report for week 36

In order to expand my limited knowledge of C/C++ I’ve started to read and use the following books as reference material:

  • “Thinking in C++, Volume 1, 2nd Edition” by Bruce Eckel (free version)
  • “Effective C++, 3rd Edition” by Scott Meyers
  • “Sams’ Teach Yourself C in 21 Days, 4th Edition” by Peter Aitken and Bradley L. Jones

I’ve also read an article or two in the book “Game Programming Gems” (edited by Mark DeLoura) while looking for a good way to store and manipulate the boolean matrices for the DLX algorithm. I’m leaning towards using Andrew Kirmse’s code from the “Simple, Fast Bit Arrays” article which has a license on the following form: “As long as you keep the copyright notice you can do whatever you want with it”. Not sure how that will interact with the GPL license I’m using, but I’ll figure out something.

I’ve checked out Donald Knuth’s own DLX program: dance.w. He uses a system called CWEB (hence the .w) to write his programs so I had to download, compile and run that in order to convert dance.w into dance.c. Then I could finally compile it. With my limited C knowledge I only understood bits and pieces, but I’ll keep trying as I learn more. I could argue that I don’t understand everything because he uses a handful of GOTO statements, but that’s not where I get stuck. Still, I don’t think Dijkstra would have approved of those GOTOs. Knuth has also written a more general version of the DLX program named gdance.w, but I’ll visit that after I’ve intellectually conquered dance.w.

My own implementation of the DLX algorithm in C++ is also complete. I’ve spent more than a few hours trying to befriend C++ and I think I’m finally getting the hang of it. I’ve implemented the algorithm as a shared library (.dll in Windows .so in Linux) by following the pseudo code from Knuth’s paper. My code uses the same variable names and it follows the same structure as in the paper. The storage, manipulation and transformation algorithms which takes the input boolean matrix and turns it into a collection of objects is still under development. This means that I’ve not actually tested the DLX implementation, but seeing how similar it’s to the pseudo code there is a fair chance that it might actually work.

I’ve also reread the paper “PRP – Parallel Recursive Procedures” by Arne Maus and Torfinn Aas in order to get some more ideas on how to parallelize the DLX algorithm. As I was implementing the DLX algorithm I wrote a bit about the implementation and some other challenges which are yet to come. Currently the progress on the project is as scheduled by the project plan.

NOTE: This post has been imported from my old it’s learning ePortfolio DECS blog.