bytedeco/javacpp

How to convert C++ templates with "using" keyword

Open

#807 aberto em 28 de mai. de 2025

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)Java (620 forks)batch import
help wantedquestion

Métricas do repositório

Stars
 (4.279 stars)
Métricas de merge de PR
 (Mesclagem média 2d) (1 fundiu PR em 30d)

Description

I need to convert the following code

template <typename M0>
using CallbackFunc = std::function<void(const std::shared_ptr<M0>&)>;

This is a part of the header file. Irrelevant code has been omitted.

namespace apollo {
namespace cyber {

template <typename M0>
using CallbackFunc = std::function<void(const std::shared_ptr<M0>&)>;

template <typename MessageT>
class Reader : public ReaderBase {
public:
explicit Reader(const proto::RoleAttributes& role_attr,
                  const CallbackFunc<MessageT>& reader_func = nullptr,
                  uint32_t pending_queue_size = DEFAULT_PENDING_QUEUE_SIZE);
private:
CallbackFunc<MessageT> reader_func_;
}

This is my configuration file.Irrelevant code has been omitted.

import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;
import org.bytedeco.javacpp.tools.*;

@Properties(
    value = @Platform(
        define = {"ENABLE_LIBCPP","NDEBUG", "UNIQUE_PTR_NAMESPACE std", "SHARED_PTR_NAMESPACE std"},
        exclude = "google/protobuf/port_def.inc",
        compiler = "cpp14",
        include = {
            "google/protobuf/port_def.inc",
            "google/protobuf/arena.h",
            "google/protobuf/message_lite.h",
            "google/protobuf/unknown_field_set.h",
            "google/protobuf/descriptor.h",
            ...
        }
public class xxxconfig implements InfoMapper {
        public void map(InfoMap infoMap) {
        infoMap.put(new Info("apollo::cyber::CallbackFunc<apollo::cyber::node_wrapper::proto::Person>").pointerTypes("CallbackFuncPerson"));
        infoMap.put(new Info("std::function<void(const std::shared_ptr<apollo::cyber::node_wrapper::proto::Person>&)>").pointerTypes("CallbackFuncPerson"));
}
    public static class CallbackFuncPerson extends FunctionPointer {
    static {Loader.load();}
    /** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
    public CallbackFuncPerson(Pointer p){ super(p); }
    protected CallbackFuncPerson() { allocate(); }
    private native void allocate();
    public native void call(@ByVal @Cast("const std::shared_ptr<apollo::cyber::node_wrapper::proto::Person>*") Pointer message);
    }
}

I used Maven to build and successfully generated the dynamic library.But when I wrote the test program to reference the dynamic library, I received an error message.This is error message.

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java (default-cli) on project testcyber: An exception occurred while executing the Java class. 'void com.kernelsoft.presets.cyber_config$CallbackFuncPerson.allocate()' -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Could you please advice me something?

Guia do colaborador