Closed zhengdi1992 closed 5 years ago
the only things in qpOASES-macos-x86_64.jar was that..without any jni dylib
It looks like you forgot to specify some class or package for the execution of javacpp-compiler
.
The default is defined here but that doesn't match your class names, so you'll need to override that:
https://github.com/bytedeco/javacpp-presets/blob/master/pom.xml#L297
thank you for your advice..
cool, it's right..
i have change the mapper class
from
target = "qpOASES",
target = "org.bytedeco.qpOASES.presets.qpOASES",
and now it was match the default path..
[INFO] clang++ -I~/cpptest/javacpp-presets/qpOASES/cppbuild/macosx-x86_64/include/ -I/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/include/darwin ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/jniqpOASES.cpp ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/jnijavacpp.cpp -march=x86-64 -m64 -O3 -Wl,-rpath,@loader_path/. -Wall -fPIC -dynamiclib -undefined dynamic_lookup -o libjniqpOASES.dylib -L~/cpptest/javacpp-presets/qpOASES/cppbuild/macosx-x86_64/lib/ -Wl,-rpath,~/cpptest/javacpp-presets/qpOASES/cppbuild/macosx-x86_64/lib/ -framework JavaVM
and some compile type error ..
just like
unknown type name 'QProblem'; did you mean 'qpOASES::QProblem'?
i think it should modify the mapper class, first . i will figure it out : )
i have build it successfully...
[INFO] --- javacpp:1.5.1-SNAPSHOT:build (javacpp-compiler) @ qpOASES ---
[INFO] Detected platform "macosx-x86_64"
[INFO] Building for platform "macosx-x86_64"
[INFO] Generating ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/jnijavacpp.cpp
[INFO] Generating ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/jniqpOASES.cpp
[INFO] Compiling ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/libjniqpOASES.dylib
[INFO] clang++ -I~/cpptest/javacpp-presets/qpOASES/cppbuild/macosx-x86_64/include/ -I/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/include/darwin ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/jniqpOASES.cpp ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/jnijavacpp.cpp -march=x86-64 -m64 -O3 -Wl,-rpath,@loader_path/. -Wall -fPIC -dynamiclib -undefined dynamic_lookup -o libjniqpOASES.dylib -L~/cpptest/javacpp-presets/qpOASES/cppbuild/macosx-x86_64/lib/ -Wl,-rpath,~/cpptest/javacpp-presets/qpOASES/cppbuild/macosx-x86_64/lib/ -framework JavaVM
[INFO] Deleting ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/jniqpOASES.cpp
[INFO] Deleting ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/jnijavacpp.cpp
[INFO]
but in runtime i simple call a native method qpOASES.QProblem_cleanup();
occur a link error
dyld: lazy symbol binding failed: Symbol not found: __Z16QProblem_cleanupv
Referenced from: ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/libjniqpOASES.dylib
Expected in: flat namespace
dyld: Symbol not found: __Z16QProblem_cleanupv
Referenced from: ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/libjniqpOASES.dylib
Expected in: flat namespace
i has check the libjniqpOASES.dylib by otool -L libjniqpOASES.dylib
show like this
otool -L libjniqpOASES.dylib
libjniqpOASES.dylib:
libjniqpOASES.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/JavaVM.framework/Versions/A/JavaVM (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
otool -L libqpOASES.dylib
libqpOASES.dylib:
libqpOASES.3.2.dylib (compatibility version 3.2.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
the generate jnilib has no link the dylib which installed by cppbuild.sh ? and other advice for this error?
Use @Platform(link = "qpOASES", ...)
to link with it.
Please let me know if you encounter any more errors! Thanks
all build was successful, and jnilib also link to the qpOASES.dylib, the only problem was that, when i call simple native method occur
dyld: lazy symbol binding failed: Symbol not found: __Z16QProblem_cleanupv
Referenced from: ~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64/libjniqpOASES.dylib
Expected in: flat namespace
i' m not sure it was the problem by cpp or not.
mapper class was that
@Properties(
target = "org.bytedeco.qpOASES.presets.qpOASES",
value = {
@Platform(
link = "qpOASES",
includepath = "~/cpptest/javacpp-presets/qpOASES/cppbuild/macosx-x86_64/include/",
linkpath = "~/cpptest/javacpp-presets/qpOASES/cppbuild/macosx-x86_64/lib/",
include = {
"qpOASES_wrapper.h"
}
)
}
)
public class qpOASESConfig implements InfoMapper {
@Override
public void map(InfoMap infoMap) {
infoMap
.put(new Info(
"QProblemBClass","OptionsClass","returnValue","QProblem","QProblemB","SQProblem","Options").skip());
}
}
and i can also get the QProblem_cleanup
method from the qpOASES_wrapper.h file
/*
* This file is part of qpOASES.
*
* qpOASES -- An Implementation of the Online Active Set Strategy.
* Copyright (C) 2007-2017 by Hans Joachim Ferreau, Andreas Potschka,
* Christian Kirches et al. All rights reserved.
*
* qpOASES is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* qpOASES is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with qpOASES; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/**
* \file interfaces/c/qpOASES_wrapper.h
* \author Hans Joachim Ferreau
* \version 3.2
* \date 2014-2017
*
* Interface that enables to call qpOASES from plain C.
*
*/
#ifndef QPOASES_WRAPPER_H
#define QPOASES_WRAPPER_H
#ifndef QPOASES_TYPES_HPP
/**
* Defined integer type for calling BLAS/LAPACK. Should usually be
* "(unsigned) int", currently set to "(unsigned) long" for backwards
* compatibility. This will change in a future release.
*/
typedef long la_int_t;
typedef unsigned long la_uint_t;
/** Defines real_t for facilitating switching between double and float. */
#ifdef __USE_SINGLE_PRECISION__
typedef float real_t;
#else
typedef double real_t;
#endif /* __USE_SINGLE_PRECISION__ */
/** Defines int_t for facilitating switching between int and long int. */
#ifdef __USE_LONG_INTEGERS__
typedef long int_t;
typedef unsigned long uint_t;
#else
typedef int int_t;
typedef unsigned int uint_t;
#endif /* __USE_LONG_INTEGERS__ */
/** Defines FORTRAN integer type. Might be platform dependent! */
#ifdef __USE_LONG_FINTS__
typedef long fint_t;
#else
typedef int fint_t;
#endif /* __USE_LONG_FINTS__ */
/**
* Integer type for sparse matrix row/column entries. Make this "int"
* for 32 bit entries, and "long" for 64-bit entries on x86_64 platform.
*
* Most sparse codes still assume 32-bit entries here (HSL, BQPD, ...)
*/
typedef int_t sparse_int_t;
/* dummy definitions, not used when calling from C */
#define QProblemBClass int_t
#define OptionsClass int_t
#define returnValue int_t
/* HessianType */
#define HST_ZERO 0
#define HST_IDENTITY 1
#define HST_POSDEF 2
#define HST_POSDEF_NULLSPACE 3
#define HST_SEMIDEF 4
#define HST_INDEF 5
#define HST_UNKNOWN 6
/* SubjectToStatus */
#define ST_LOWER -1
#define ST_INACTIVE 0
#define ST_UPPER 1
#define ST_INFEASIBLE_LOWER 2
#define ST_INFEASIBLE_UPPER 3
#define ST_UNDEFINED 4
/* PrintLevel */
#define PL_DEBUG_ITER -2
#define PL_TABULAR -1
#define PL_NONE 0
#define PL_LOW 1
#define PL_MEDIUM 2
#define PL_HIGH 3
#else
#define QProblemBClass QProblemB
#define OptionsClass REFER_NAMESPACE_QPOASES Options
/* only declare when compiling C++ library */
static QProblem* globalQProblemObject = 0;
static QProblemB* globalQProblemBObject = 0;
static SQProblem* globalSQProblemObject = 0;
static Options globalOptionsObject;
#endif /* QPOASES_TYPES_HPP */
/**
* \brief Manages all user-specified options for solving QPs.
*
* This struct manages all user-specified options used for solving
* quadratic programs.
*
* \author Hans Joachim Ferreau
* \version 3.2
* \date 2014-2017
*/
typedef struct
{
int_t printLevel; /**< Print level. */
int_t enableRamping; /**< Specifies whether ramping shall be enabled or not. */
int_t enableFarBounds; /**< Specifies whether far bounds shall be used or not. */
int_t enableFlippingBounds; /**< Specifies whether flipping bounds shall be used or not. */
int_t enableRegularisation; /**< Specifies whether Hessian matrix shall be regularised in case semi-definiteness is detected. */
int_t enableFullLITests; /**< Specifies whether condition-hardened LI test shall be used or not. */
int_t enableNZCTests; /**< Specifies whether nonzero curvature tests shall be used. */
int_t enableDriftCorrection; /**< Specifies the frequency of drift corrections (0 = off). */
int_t enableCholeskyRefactorisation; /**< Specifies the frequency of full refactorisation of proj. Hessian (otherwise updates). */
int_t enableEqualities; /**< Specifies whether equalities shall be always treated as active constraints. */
real_t terminationTolerance; /**< Termination tolerance. */
real_t boundTolerance; /**< Lower/upper (constraints') bound tolerance (an inequality constraint whose lower and
upper bounds differ by less is regarded to be an equality constraint). */
real_t boundRelaxation; /**< Offset for relaxing (constraints') bounds at beginning of an initial homotopy. It is also as initial value for far bounds. */
real_t epsNum; /**< Numerator tolerance for ratio tests. */
real_t epsDen; /**< Denominator tolerance for ratio tests. */
real_t maxPrimalJump; /**< Maximum allowed jump in primal variables in nonzero curvature tests. */
real_t maxDualJump; /**< Maximum allowed jump in dual variables in linear independence tests. */
real_t initialRamping; /**< Start value for Ramping Strategy. */
real_t finalRamping; /**< Final value for Ramping Strategy. */
real_t initialFarBounds; /**< Initial size of Far Bounds. */
real_t growFarBounds; /**< Factor to grow Far Bounds. */
int_t initialStatusBounds; /**< Initial status of bounds at first iteration. */
real_t epsFlipping; /**< Tolerance of squared Cholesky diagonal factor which triggers flipping bound. */
int_t numRegularisationSteps; /**< Maximum number of successive regularisation steps. */
real_t epsRegularisation; /**< Scaling factor of identity matrix used for Hessian regularisation. */
int_t numRefinementSteps; /**< Maximum number of iterative refinement steps. */
real_t epsIterRef; /**< Early termination tolerance for iterative refinement. */
real_t epsLITests; /**< Tolerance for linear independence tests. */
real_t epsNZCTests; /**< Tolerance for nonzero curvature tests. */
real_t rcondSMin; /**< Minimum reciprocal condition number of S before refactorization is triggered */
int_t enableInertiaCorrection; /**< Specifies whether the working set should be repaired when negative curvature is discovered during hotstart. */
int_t enableDropInfeasibles; /**< ... */
int_t dropBoundPriority; /**< ... */
int_t dropEqConPriority; /**< ... */
int_t dropIneqConPriority; /**< ... */
int_t printResiduals; /**< If true, it will print the internal qpOASES residuals and other information per iteration */
} qpOASES_Options;
int_t qpOASES_Options_init( qpOASES_Options* const options,
int_t mode
);
int_t qpOASES_Options_copy( const qpOASES_Options* const from,
OptionsClass* const to
);
int_t qpOASES_obtainOutputs( const QProblemBClass* const globalQpObject,
returnValue returnvalue,
real_t* const x,
real_t* const y,
real_t* const obj,
int_t* const status
);
int_t QProblem_setup( int_t nV,
int_t nC,
int_t hessianType
);
int_t QProblem_init( const real_t* const H,
const real_t* const g,
const real_t* const A,
const real_t* const lb,
const real_t* const ub,
const real_t* const lbA,
const real_t* const ubA,
int_t* const nWSR,
real_t* const cputime,
const qpOASES_Options* const options,
real_t* const x,
real_t* const y,
real_t* const obj,
int_t* const status
);
int_t QProblem_hotstart( const real_t* const g,
const real_t* const lb,
const real_t* const ub,
const real_t* const lbA,
const real_t* const ubA,
int_t* const nWSR,
real_t* const cputime,
real_t* const x,
real_t* const y,
real_t* const obj,
int_t* const status
);
int_t QProblem_cleanup( );
int_t QProblemB_setup( int_t nV,
int_t hessianType
);
int_t QProblemB_init( const real_t* const H,
const real_t* const g,
const real_t* const lb,
const real_t* const ub,
int_t* const nWSR,
real_t* const cputime,
const qpOASES_Options* const options,
real_t* const x,
real_t* const y,
real_t* const obj,
int_t* const status
);
int_t QProblemB_hotstart( const real_t* const g,
const real_t* const lb,
const real_t* const ub,
int_t* const nWSR,
real_t* const cputime,
real_t* const x,
real_t* const y,
real_t* const obj,
int_t* const status
);
int_t QProblemB_cleanup( );
int_t SQProblem_setup( int_t nV,
int_t nC,
int_t hessianType
);
int_t SQProblem_init( const real_t* const H,
const real_t* const g,
const real_t* const A,
const real_t* const lb,
const real_t* const ub,
const real_t* const lbA,
const real_t* const ubA,
int_t* const nWSR,
real_t* const cputime,
const qpOASES_Options* const options,
real_t* const x,
real_t* const y,
real_t* const obj,
int_t* const status
);
int_t SQProblem_hotstart( const real_t* const H,
const real_t* const g,
const real_t* const A,
const real_t* const lb,
const real_t* const ub,
const real_t* const lbA,
const real_t* const ubA,
int_t* const nWSR,
real_t* const cputime,
real_t* const x,
real_t* const y,
real_t* const obj,
int_t* const status
);
int_t SQProblem_cleanup( );
#endif /* QPOASES_WRAPPER_H */
/*
* end of file
*/
It's possible that libqpOASES.dylib wasn't
built properly to work with rpath. What does otool -L
say?
$ otool -L libqpOASES.dylib
libqpOASES.dylib:
libqpOASES.3.2.dylib (compatibility version 3.2.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
rename for libqpOASES.3.2.dylib and still the same problem
cppbuild.sh
cp ~/or/qpOASES2/build/libs/libqpOASES.3.2.dylib ~/cpptest/javacpp-presets/qpOASES/cppbuild/macosx-x86_64/lib/libqpOASES.3.2.dylib
mapper.java
@Platform(
link = "qpOASES.3.2",
....
)
now otool -L
otool -L libqpOASES.3.2.dylib
libqpOASES.3.2.dylib:
libqpOASES.3.2.dylib (compatibility version 3.2.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
Yeah, that's not going to work. To get this working, we can run the following before the building the presets:
install_name_tool -add_rpath @loader_path/. -id @rpath/libqpOASES.3.2.dylib libqpOASES.3.2.dylib
i'v add the rpath.. and maven rebuild it
now otools says that in the dir auto generated
~/cpptest/javacpp-presets/qpOASES/target/native/org/bytedeco/qpOASES/macosx-x86_64
$ otool -L libjniqpOASES.dylib
libjniqpOASES.dylib:
libjniqpOASES.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libqpOASES.3.2.dylib (compatibility version 3.2.0, current version 0.0.0)
/System/Library/Frameworks/JavaVM.framework/Versions/A/JavaVM (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
$ otool -L libqpOASES.3.2.dylib
libqpOASES.3.2.dylib:
@rpath/libqpOASES.3.2.dylib (compatibility version 3.2.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)
but the same error still exist :(
So it looks like the library provides no definition for the QProblem_cleanup()
function.
You'll need to skip any missing symbols like that:
infoMap.put(new Info("QProblem_cleanup", ...).skip())
you got it .. the warpper .h file was extra create for define some important method for use qpOASES methods... but never compile and install to a dylib.. (i misunderstand that cpp will did this things..)
so i should do it first install a dylib which between the jni dylib and the qpOASES.dylib...
or
i also could user the generated java interface qpOASES.java
to wrapper the same things?
java swig can use a extra wrapper .cpp/.cxx file to generate the jni lib, but cpp Actually not?
JavaCPP can do the same, yes.
one more question.. sometimes we only want to use part of the c++ functions dylib, so we will make a warpper file.. if i use javacpp to generate jni interface... for the configeMapper.java should i only include the only warpper file ? or recursion include all dependency file which define the struct whose userd in the warpper file ? Any good idea if possiable can use the configeMapper.java with infoMap? recursion include maybe a very huge job ...
We only need to include what's useful for the wrapper.
It's also possible to include only portions of files: https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#skipping-lines-from-header-files
i'm try to create new preset for qpOASES..all it works, and build successful but the jnixxx.dylib has not created.. refer to this https://github.com/bytedeco/javacpp/wiki/Basic-Architecture
1.Runs optional external build scripts, such as cppbuild.sh from the JavaCPP Presets (successfully, for easy, I build qpOASES locally first and only cp command in the cppbuild.sh file.) 2.Runs the Parser on the given InfoMap and the header files listed in the @Platform annotation (successfully, i got the file generated qpOASES.java) 3.Runs the Generator on the Java interfaces(maybe failed or omit by some reason?) 4.Runs the native C++ compiler (GCC, Clang, MSVC, NVCC, etc) on the JNI code(maybe failed or omit by some reason?)
where should i check ,and good ideas? thanks a lot.. this is the console by
maven install --projects .,qpOASES