Saturday, December 31, 2011

Can't Step into Functions in Library That a Project is Using

Problem: Can't step into the OpenCV source code files that had been compiled into a .lib to be used in other projects from within Eclipse.

Explanation: if the OpenCV source wasn't built on your machine, you may not have the .pdb files that were generated and dumped into the /bin directory. These files are necessary for stepping into the code.

Solution: Either get the .pdb files from the original build or rebuild OpenCV to generate them, and place them in the Visual Studio source directories list (Tools -> Options -> VC++ Directories -> Source Files)

Ensuring Compatible Calling Conventions Eclipse

Runtime error:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

Solution: in Eclipse, verify that Property pages -> configuration properties -> C/C++ -> Advanced -> Calling convention is the same in the callee as well as the caller. For example, make sure any DLLs that your project depends on were compiled with the same calling convention.

LNK2019: unresolved external symbol

You got LNK2019: unresolved external symbol but you're sure you declared the symbol in a .h file and you defined it the corresponding .cpp file?

The problem may be that you didn't prefix the function definition with the class name.

Cuda + OpenCV

Error: "this operator is not allowed in a template argument expression"
Explanation: If you include a large library in a CUDA source file (extention .cu), you are requiring the cuda compiler to process it. The cuda compiler can't handle such a large library (I still don't know exactly why).
Solution: Keep your .cu files OpenCV-reference-free. They should not know about anything related to OpenCV. Eliminate OpenCV references in a middle "buffer" layer and then deal with the

TO BE CONT'd

Using Scripts For Project Configurations

Say you are specifying your path for a Java project within an IDE like Eclipse. Instead of setting the path and other project-specific configurations within the IDE, it would be beneficial to have a record of the specific settings that the project needs to run independent of your workstation. If you keep the configuration information in a script (whose last task is starting the IDE you're developing in) then you can take the project to a customer, for example, and not have to reset all of the settings that are specific to your workspace.

Static Initializers

If you have a block of Java code that looks like this, within a class:

static {
    ...
}

then you've encountered a static initializer. Some facts about them include:
(1) They are executed once per class (more specifically, they are executed once per time the class is loaded).
(2) One can place multiple static initializers within a single class -- they are then aggregated and execute in the order in which they appear in the original code, top to bottom.
(3) They are thread-safe.

some appropriate times to use them:

(1) To load a native library which is known at compile time:

static {
      System.loadLibrary("NameOfLibrary");
}

(2) To initialize static data belonging to a class. For example, a static map:

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Opposite{

        private static final Map<String, String> oppStrings;

        static {
                Map<String, String> oppStrings = new HashMap<String, String>();
                oppStrings.put("light", "dark");
                oppStrings.put("small", "large");
                myMap = Collections.unmodifiableMap(oppStrings);
        }

        ...
}

An alternative to a static initialization block, in certain cases, is a private static method: 

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Opposite{

      public static final OPP_STRINGS = constructOppositeMap();

      private static Map<String, String> constructOppositeMap() {
            Map<String, String> oppositeStrings = new HashMap<String, String>();
            oppositeStrings.put("light", "dark");
            oppositeStrings.put("small", "large");
            return Collections.unmodifiableMap(oppositeStrings);
      }
      ...
}

I find this second method to be much more clearly indicative of the fact that OPP_MAP is being initialized. The static initializer could be buried toward the bottom of the file! In this case it wouldn't be immediately apparent where oppmap was being initialized (though you would know that if it compiles then it would have to be initialized somewhere, since the Map is declared "final"). An aptly-named static initializer-mimicker in the form of a private static method ensures easy and intuitive location of where the initialization code resides.

Parameterized Unit Testing (PUT) with JUnit

You've found yourself writing JUnit tests that only seem to vary in their input. You've realized it's time to collect like terms. JUnit 4's parameterized annotation was created to address this need. Here is an excellent post describing how to construct such a system:

http://blogs.oracle.com/jacobc/entry/parameterized_unit_tests_with_junit

java.lang.NoClassDefFoundError

If you get this error it is probably because the necessary jar files aren't on your build path.

(in Eclipse)
(1) Right-click your project -> Build Path... -> Configure Build Path
(2) Click the Libraries tab and click "Add JARs..." if the jar file is local to the project directory or else "Add External JARs..." if the jar file is outside the project directory.
(3) If necessary, associate a native library by opening the file explorer tab on the left side of the jar file once it is listed within the Libraries tab. You can also specify the Javadoc location for the jar file if it was created without the source.

Mapping a Network Drive to a Server

In a Windows Explorer:
(1) Press alt
(2) Select Tools -> Map Network Drive
(3) Enter server location