Question: I've got a very weird issue. I've got this Procedure object that contains two rules. Now I wanted to loop out those rules with a for loop and get 1 rule back. But I always get null. It looks like he is skipping the if statement and directly goes to my return null part.

The name of the first rule is age, and the name of the other rule is accidents. I've included the method here.

My log is giving back:

> 
> rulename: 'age' and variable: 'accidents' and is true ?: 'false'
> 
> 
> rulename: 'accidents' and variable: 'accidents' and is true ?: 'true'
> 
> 
> 

```
private Rule searchRule(String ruleName)
    {
        List<Rule> test = this.procedureObject.getRules();

        for(Rule rule : test)
        {
            Log.d("debug", "rulename: '" + rule.getName() + "' and variable: '"+ruleName+"' and is true ?: '"+rule.getName().equalsIgnoreCase(ruleName)+"'");
            if(rule.getName().equalsIgnoreCase(ruleName))
            {
                return rule;
            }
        }

        return null;
    }

```

**EDIT: it works now.**

I just changed this in the calling code:

```
Rule makeRule = RuleFactory.getNewRuleClassNameInstance(this.searchRule(ref2.getName()).getClass().getSimpleName());

```

to:

```
Rule foundRule = this.searchRule(ref2.getName());

Rule makeRule = RuleFactory.getNewRuleClassNameInstance(foundRule.getClass().getSimpleName());

```

And then it suddenly works.

Answer: 
Turns out that i was building my DLL just fine, and JNA was finding my DLL just fine as well; i made an error in determining how the compiler mangled my symbols. Functions i named like `myfunc` were exported as `myfunc@8` or `myfunc@32` depending on how many bytes they took as arguments. Here's the code i used in my JNA project:

```
import java.util.*;
import com.sun.jna.*;
import com.sun.jna.win32.*;
//
public class Test
  {
  public interface mydll extends StdCallLibrary
    {
    mydll INSTANCE = Native.loadLibrary("mydll", mydll.class, new HashMap {{
      put("myfunc", "myfunc@8");
      //Other functions
      }});
    public int myfunc (long arg);
    //Other functions
    }
  //
  public static void main (String[] args)
    {
    System.out.println
      (mydll.INSTANCE.myfunc((long)0x23A3920F)); //Or whatever
    return 0;
    }
  }

```

My c code:

```
#include <windows.h>
#include <stdio.h>

__declspec(dllexport) int __stdcall myfunc (__int64);
/* Other functions */

__declspec(dllexport) int __stdcall myfunc (__int64 arg)
  {
  /* Whatever */
  return return_value;
  }

```

GCC was happy with just the `-shared` switch and linking against the proper libraries, like in my original question. **I highly recommend downloading [this tool](http://www.nirsoft.net/utils/dll_export_viewer.html) so you can find out exactly what your function names are.**
Look at how the test library within JNA is built (native/Makefile). Following that example will indicate proper export signatures and calling conventions.

`__declspec(dllexport)` indicates that the function name should be exported.

`__stdcall` is what is used by most MS APIs; you normally have no reason to use it in your own code, as it only complicates linking with its mangling of names.

When actually compiling (and linking), you need to tell GCC that you're building a shared library. Simply naming the file "\*.dll" isn't sufficient.

```
gcc -o mydll.dll -shared mydll.c 

```

You may need one or more `-l<libname>` options at the end depending on what native libraries you're accessing.