Monday, February 24, 2014

Netbeans and CppUnit on Mac OS X Mavericks

To continue logging my progress with NetBeans.

I wanted to get into this whole unit testing business, since there's never been a class I actually used that for, and a lot of actual jobs want you to know it. So, since NetBeans is my current IDE of choice (I actually do not have a reason  for this, except that I managed to make GDB and C++ work on it) and since the project has a logical folder called "Test Files", I decided to give it a try.

I'm mostly using this guide, but it's sort of misleading, since it's doing CUnit and I wanted to do CppUnit. So, I followed that guide to install CUnit, and then I went on to add a CppUnit, oops. Turns out those two are different, so I had to install the CppUnit also. Which was confusing on Mac OS (I downloaded the file but couldn't figure out how to configure it on the first go through). 

Then I remembered that I have Homebrew installed, so I decided to take full advantage of that. So, I did a:
brew install cppunit
which worked out-of-the-box.

And then I went on following the guide. I wrote the equivalent of their example (yeah, removed the .h includes essentially)
#include <cstdlib>
#include <iostream>

using namespace std;

long factorial(int arg) {
    long result = 1;
    int i;
    for (i = 2; i <= arg; ++i) {
        result *= i;
     }
    return result;
}

int main(int argc, char** argv) {
    printf("Type an integer and press Enter to calculate the integer's factorial: \n");
    int arg;
    cin>>arg;
    cout<<"factorial("<<arg<<") = "<<factorial(arg)<<endl;
    return 0;
}

And then I right-clicked on the cpp file, selected Create Test -> New CppUnit Test, and then selected my cpp file (at the top of the options, which automatically also selected the factorial function). I left everything else default, per the tutorial.

And then I happily right clicked the Test Files logical folder, and selected Test from there, only to get a bunch of errors. Turns out Homebrew doesn't put the cppunit files where Netbeans expects them.

Turns out the newtestclass.h file contains this include
#include <cppunit/extensions/HelperMacros.h>
And the compiler has no idea where to look for that. This was an easy fix:
Preferences -> C/C++ -> Code Assistance -> C++ Compiler

Select Add on the right-hand-side, and add this:
/usr/local/Cellar/cppunit/1.12.1/include
So, that gets rid of the warning, but then the big error came.
/bin/sh: cppunit-config: command not found
along with many other information.

But! If I went to my terminal and ran
cppunit-config
it worked!

So, I googled forever for an answer, which took me through the netbeans.conf file to no avail. The only thing that worked was starting Netbeans from the terminal.


Note: I should now have syntax highlighting here, thanks to Awesome code syntax highlighting made easy and SyntaxHighlighter (which is the main reason I quoted that much code). But it took me forever to get this to work, I'll make another post right after this one.

Monday, January 27, 2014

Netbeans C++ and GDB on Mac OS X Mavericks

I'm starting to use an IDE for the first time since basically high school (I used Visual Studio for a school project briefly but reverted to just using a make file because my Mac is more powerful and new than my PC after only 2 class projects), and I decided to use Netbeans (after some search this seemed to be more appropriate for my small project needs than Xcode).

But lo and behold, Macs/Xcode/Command Line Tools no longer support GDB, and GDB is the "supported" debugger in Netbeans (they have an option for Clang, but I found that out later). So, if you have Mavericks and want to use GDB to debug your C/C++ projects in Netbeans, this is what worked for me!

Install homebrew. You can do this with MacPorts or by just downloading GDB and building it, but I used homebrew cause that's what I had installed.

Download GDB using homebrew. Now, this is the command that you should use (there are many bad links out there): 
>> brew install https://raw.github.com/Homebrew/homebrew-dupes/master/gdb.rb

Now, basically follow what this link says. I'll write exactly what I did below in any case.

Start Keychain Access application (/Applications/Utilities/Keychain Access.app)

Open menu /Keychain Access/Certificate Assistant/Create a Certificate...

Choose a name (gdb-cert in the example), set Identity Type to Self Signed Root, set Certificate Type to Code Signing and select the Let me override defaults

Click several times on Continue until you get to the Specify a Location For The Certificate screen, then set Keychain to System.

In Keychains -> System in the main window, right click on your certificate and select Get Info.

Open the Trust item (down the page), and set Code Signing to Always Trust.

Quit Keychain Access.

Kill all taskgated processes. Note that these need sudo:
>> sudo killall taskgated

Now, find your copy of gdb, if you used homebrew to install version 7.6.2 do this:
>> cd /usr/local/Cellar/gdb/7.6.2/bin

And codesign it:
>> codesign -s gdb-cert gdb

One last step, if you want to actually be able to use gdb in Netbeans and get a debugger is missing or invalid error, go to NetBeans->Preferences->C/C++->Build Tools and set Debugger Command to /usr/local/bin/gdb.


Monday, February 11, 2013

Installing Bundler on Linux: A Tutorial

This is a mix of all the steps necessary to install Bundler + CMVS + PMVS2 on Ubuntu 11.10. I think other versions of Ubuntu work the same.

Edit: If you're interested in doing this, do yourself a favor and download the necessary files that I've modified form here (64-bit Ubuntu compatible) or from my GitHub repo here. The steps outlined below are actually not enough, you need to add the necessary flags to tell your compiler that you're compiling 32-bit compatible code.
I'd love to know if this helped, so let me know in the comments.

0.1 Pre-Install

These are the libraries you need to install before proceeding with the instalation. I've used Synaptic to install these on my system.
Install LAPACK, BLAS, CBLAS, MINPACK, f2c, libjpeg, libzip and imagemagick.
Optionally, also install gfortran and libmagicwand-dev (I installed them because it wasn't clear what I was supposed to install, so you might need them too).

0.2. Download

These are all the things you need to download (and unzip/untar). Also perform the steps in parenthesis.

0.3. Directory Structure

I've created a folder called Installs in my home directory.
Move the folders created above (bundler, pmvs2, clapack, cmvs, graclus1.2) to this Installs folder.

Edit your .bashrc file so that you set the library path correctly:

LD_LIBRARY_PATH=~/Installs/bundler/lib
export LD_LIBRARY_PATH

1. Installing Bundler 

> cd  Installs/bundler/src

Edit the Makefile such that the second line of code says:

OPTFLAGS=-O3 -Wall -fpermissive

The -fpermissive makes sure that warnings from previous versions of gcc are not treated as errors in the newer versions.

> make all

2. Installing PMVS2

> cd Installs/pmvs-2/program/base/numeric

Edit mylapac.cc lines 6 and 7 say:

#include <f2c.h>
#include <clapack.h>


(instead of clapack/*.h)

> cd Installs/pmvs-2/program/main

Edit the MakeFile so that you have

YOURINCLUDEPATH = -I/home/user/Installs/clapack/
and
YOURLDLIBPATH = -L/home/user/Installs/graclus1.2/

> make clean
> make depend
> make

3. Installing Graclus

My system is a 32-bit system. If you're installing on a 64-bit system, make sure you change 32 to 64 everywhere below.

> cd Installs/graclus1.2

Edit MakeFile.in. Make sure

COPTIONS = -DNUMBITS=32

> make

4. Installing CMVS

My system is a 32-bit system. If you're installing on a 64-bit system, make sure you change 32 to 64 everywhere below.

> cd Installs/cmvs/program/main


Edit MakeFile such that you have set the numbits appropriately in this line (there are 2 instances)

CXXFLAGS_CMVS = -O2 -Wall -Wno-deprecated -DNUMBITS=32 \
        ${YOUR_INCLUDE_PATH} ${YOUR_INCLUDE_METIS_PATH} \
        -fopenmp -DNUMBITS=32 ${OPENMP_FLAG}



Copy mylapack.o from pmvs2 to the cmvs directory.

> cd Installs
> cp pmvs-2/program/main/mylapack.o cmvs/program/main/


> cd cmvs/program/base/cmvs

Edit bundle.cc such that it includes the following libraries:

#include <vector>
#include <numeric>


> cd cmvs/program/main/


Edit genOption.cc such that it includes

#include <stdlib.h>

> cd cmvs/program/main/

Edit the MakeFile to set the dependencies (and comment out each line above each of these):

YOUR_INCLUDE_PATH = -I/home/adina/Installs/clapack/
YOUR_INCLUDE_METIS_PATH = -I/home/adina/Installs/graclus1.2/metisLib
YOUR_LDLIB_PATH = -L/home/adina/Installs/graclus1.2/


> make depends
> make

5. Run Bundler

> cd Installs/bundler/bin

Edit extract_focal.pl so that you have the focal length of the camera you use (line 293-ish).
     "SONY DSC-W80"                     => 5.75,   # 1/2.5"
     "Apple iPhone 4"                   => 3.85,
     "KODAK EASYSHARE C653 ZOOM DIGITAL CAMERA"         => 6,
     "Panasonic DMC-FH1"                => 6.17, # 1/2.33"
     "Apple iPhone 4S"                  => 4.28, 


> cd Installs/bundler

Edit RunBundler.sh by adding these lines at the end:

sleep 1
echo "[- Running Bundle2PMVS -]"

$BASE_PATH/bin/Bundle2PMVS list.txt bundle/bundle.out


I made a script to run everything (edit the paths on the first line; to run, put it in the folder with the images)

> ./runBundler_linux