Undefined symbols ... "_myextension_register_prims"

I’m currently working on a plugin for OpenFL for the Upsight/Kontagent analytics framework, for our upcoming iOS port of Try Harder.
The plugin itself is building, but when I try to build a project that include it, I’m getting the following:

Undefined symbols for architecture armv7:
  "_openflkontagent_register_prims", referenced from:
      _main in Main.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any ideas?
All the code is drawn from already existing (And working) extensions.

The ExternalInterface.cpp looks like this:

#ifndef STATIC_LINK
#define IMPLEMENT_API
#endif

#if defined(HX_WINDOWS) || defined(HX_MACOS) || defined(HX_LINUX)
#define NEKO_COMPATIBLE
#endif

#include <hx/CFFI.h>
#include <stdio.h>
#include <hxcpp.h>
#include "OpenFLKontagent.h"

using namespace openflkontagent;

AutoGCRoot* kontagentEventHandle = 0;

static value openflkontagent_startSession(value apiKey, value production) {
	#ifdef IPHONE
	startSession(val_string(apiKey), val_bool(production));
	#endif
	return alloc_null();
}
DEFINE_PRIM(openflkontagent_startSession, 2);

extern "C" int openflkontagent_register_prims() { return 0; }

My first guess would be that you did not build it for armv7,
how are you building your extension?

Also this post could interest you: Gathering Extensions!

using this to build (from inside the extension folder)

lime rebuild ./project ios -clean

outputs no errors

I also noticedd that the error I showed in the original post also happens for 64 a bit higher up in the output

Undefined symbols for architecture arm64:
  "_openflkontagent_register_prims", referenced from:
      _main in Main.o

(and yes, we’re definitely planning to contribute these extensions once it makes sense :slight_smile: at the end oft his project we’ll have built several for marketing & analytics frameworks that we’re implementing for a client, and I don’t see any reason why anybody should ever go through this again if we already have :slight_smile: )

Looks like armv7 and arm64 are built by default https://github.com/openfl/lime/blob/master/lime/tools/platforms/IOSPlatform.hx#L318 so it’s possible the error isn’t because it’s missing.

The only difference I see with the lime’s ExternalInterface.cpp is the namespace, could you try with this:

#ifndef STATIC_LINK
#define IMPLEMENT_API
#endif

#if defined(HX_WINDOWS) || defined(HX_MACOS) || defined(HX_LINUX)
#define NEKO_COMPATIBLE
#endif

#include <hx/CFFI.h>
#include <stdio.h>
#include <hxcpp.h>
#include "OpenFLKontagent.h"

namespace openflkontagent {

  AutoGCRoot* kontagentEventHandle = 0;

  static value openflkontagent_startSession(value apiKey, value production) {
  	#ifdef IPHONE
	startSession(val_string(apiKey), val_bool(production));
	#endif
	return alloc_null();
  }
  DEFINE_PRIM(openflkontagent_startSession, 2);
}

extern "C" int openflkontagent_register_prims() { return 0; }

I tried it, as well as commenting out the

AutoGCRoot* kontagentEventHandle = 0;

(I just copied it from an existing plugin, not sure why it’s there)

still get the same error. I’ve been cleaning & building multiple times.

Do you have an include.xml with an <ndll name="openflkontagent" /> tag? Does that match the naming of your files?

yup, this is the include.xml

<?xml version="1.0" encoding="utf-8"?>
<project>
    <ndll name="openflkontagent" if="ios" />
	<ios linker-flags="-all_load" />
    <dependency path="framework/Kontagent.framework" if="ios" />
</project>

I realized that if I open the exported Xcode project, the Other Linker Flags are
-lstd -lregexp -llime -lstd -lregexp -llime -lstd -lregexp -llime -lgamecenter -lopenflunityads -lopenflupsight -lApplicationMain -stdlib=libc++ -all_load

I’ve added -lopenflkontagent to it, and then I get a bit further.

Undefined symbols for architecture i386:
OBJC_CLASS$_Kontagent”, referenced from:
objc-class-ref in libopenflkontagent.a(7c9cd8f0_OpenFLKontagent.o)

I have several .a files that are referenced in the extension. I tried to put them in the Build.XML
like this:

<lib name="/lib/libKontagent.a" />

But that generates the error above (after manually adding -lopenflkontagent to the linker flags.

So to continue, my question is now twofold:

  • how do I get -lopenflkontagent to automatically be put into the other linker flags?
  • how do I properly include .a libraries into an extension?

What are you using in your project to include your extension? <include path="to/extension" /> or <haxelib name="of-extension" />?

And what happens if you remove the “all_load” flag?

@singmajesty Hi, I’m also working on this project. We’re using the haxelib tag, and removing the all_load flag has no effect.