custom node.js addon can be built but not able to include - c++

I am writing a custom node.js addon by C++ mixed with C program.
The addon.cc consists of something like
#define BUILDING_NODE_EXTENSION
#include <node.h>
#include <node_buffer.h>
using namespace v8;
using namespace node;
/* other logic and function... */
Handle<Value> RunCallback(const Arguments& args) {
HandleScope scope;
Local<Value> buffer1 = args[0];
size_t size = Buffer::Length(buffer1->ToObject());
char* bufferdata = Buffer::Data(buffer1->ToObject());
/* some logic written in C style ... */
Local<Function> cb = Local<Function>::Cast(args[1]);
const unsigned argc = 1;
Local<Value> argv[argc] = { Local<Value>::New(String::New(outputdata, outputSize)) };
cb->Call(Context::GetCurrent()->Global(), argc, argv);
return scope.Close(Undefined());
}
void Init(Handle<Object> target) {
target->Set(String::NewSymbol("runCallback"), FunctionTemplate::New(RunCallback)->GetFunction());
}
NODE_MODULE(addon, Init)
It also includes other .cc files, so the wscript is like this:
srcdir = '.'
blddir = 'build'
VERSION = '0.0.1'
def set_options(opt):
opt.tool_options('compiler_cxx')
def configure(conf):
conf.check_tool('compiler_cxx')
conf.check_tool('node_addon')
def build(bld):
obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
obj.target = 'addon'
obj.source = ['addon.cc', 'otherFiles.cc']
When I run node-waf configure, it shows:
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
'configure' finished successfully (0.169s)
When I run node-waf build, it shows:
Waf: Entering directory `/path/build'
[ 1/25] cxx: addon.cc -> build/Release/addon_1.o
... list of file ...
build/Release/list of file -> build/Release/addon.node
Waf: Leaving directory `/path/build'
'build' finished successfully (0.544s)
But when I try the following in node REPL, it shows:
var addon = require("./build/Release/addon");
Error: Unable to load shared library /path/build/Release/addon.node
at Object..node (module.js:472:11)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at repl:1:13
at REPLServer.eval (repl.js:80:21)
at repl.js:190:20
at REPLServer.eval (repl.js:87:5)
at Interface.<anonymous> (repl.js:182:12)
It is very strange. I have checked that the file should match with the system architecture:
$ file build/Release/addon.node
build/Release/addon.node: Mach-O 64-bit bundle x86_64
$ file `which node`
/usr/local/bin/node: Mach-O 64-bit executable x86_64
By looking at nm, it shows the following:
nm ./build/Release/addon.node
0000000000011880 s GCC_except_table30
0000000000001160 t _Init
U __Unwind_Resume_or_Rethrow
U ___bzero
U ___gxx_personality_v0
0000000000013220 D _addon_module
U _free
0000000000013600 D _lsfmeanTbl
0000000000013420 D _memLfTbl
U _memcpy
U _memmove
U _puts
U _realloc
0000000000011950 s _ssqEn_win.2272
000000000001341c D _stMemLTbl
00000000000132e0 D _state_frgqTbl
00000000000132c0 D _state_sq3Tbl
U dyld_stub_binder
(... many are omitted ...)
What will be the possible reasons? Is that I cannot just combine C files with C++ files to compile? Should I remove all malloc/realloc/free? Or any other possible reasons?

Wrap the definition of Init() and the NODE_MODULE macro in extern "C" to avoid name C++ mangling of the exported symbols:
extern "C" {
void Init(Handle<Object> target) {
target->Set(String::NewSymbol("runCallback"), FunctionTemplate::New(RunCallback)->GetFunction());
}
NODE_MODULE(addon, Init)
}

By using node.js which version >= 0.7.6. the problem is solved. Also, it has a lot more debug message.

Related

Android NDK: CMake fails while linking static library (OpenSSL)

I'm writing a simple proof of concept app that integrates OpenSSL using NDK. Unfortunately, it gives me undefined reference errors during build.
What I did:
Cross-compiled OpenSSL for Android (x86_64 is shown, and similarly for other ABIs):
openssl-1.1.1q $ ./Configure android-x86_64
openssl-1.1.1q $ make
openssl-1.1.1q $ cp libssl.a <path_to_project_cpp_dir>/libs/x86_64/
openssl-1.1.1q $ cp -r ./include/openssl <path_to_project_cpp_dir>/libs/include/
Added the following CMakeLists.txt into project's cpp dir:
cmake_minimum_required(VERSION 3.18.1)
project("ndk-poc")
add_library(
# Sets the name of the library.
ndk-poc
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
ndk-poc.cpp)
find_library(
# Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that you want CMake to locate.
log)
add_library(libssl STATIC IMPORTED)
set_target_properties(
# Specifies the target library.
libssl
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
${CMAKE_SOURCE_DIR}/libs/${ANDROID_ABI}/libssl.a )
include_directories(${CMAKE_SOURCE_DIR}/libs/include/)
target_link_libraries(
# Specifies the target library.
ndk-poc
# Links the target library to the log library
# included in the NDK.
libssl
${log-lib})
And this is my test ndk-poc.cpp:
#include <jni.h>
#include <string>
#include <openssl/bn.h>
#include <openssl/evp.h>
#include <openssl/sha.h>
extern "C" JNIEXPORT jstring JNICALL
Java_com_techyourchance_android_screens_home_HomeFragment_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
/* Testing OPENSSL prime generation and BigNum. */
BIGNUM *prime1 = NULL;
int bits = 16; /* Number of bits for the generated prime. */
int safe = 0;
prime1 = BN_new();
if (prime1 == NULL) {
printf("Out of memory.\n");
} else if (BN_generate_prime_ex(prime1, bits, safe, NULL, NULL, NULL)) {
printf("Success!\n");
int len;
len = BN_num_bytes(prime1);
unsigned char* buffer;
buffer = static_cast<unsigned char*>(malloc(len));
if (!buffer) {
printf("Out of memory allocating buffer.\n");
} else {
int wlen;
wlen = BN_bn2bin(prime1, buffer);
printf("Wrote %d bytes.\n", wlen);
int i;
for(i=0;i<wlen;++i) {
printf("Byte %d of buffer = %d.\n", i, buffer[i]);
}
free(buffer);
char* st;
st = BN_bn2dec(prime1);
printf("Prime = %s.\n", st);
OPENSSL_free(st);
}
} else {
printf("Error generating prime.\n");
}
std::string result = "Test completed!";
return env->NewStringUTF(result.c_str());
}
Results:
I don't see any errors inside Android Studio, but when I try building the project, all usages of OpenSSL's APIs in my test code result in unresolved reference errors:
...
C:/Users/Vasiliy/projects/ndk-poc/app/src/main/cpp/ndk-poc.cpp:38: error: undefined reference to 'BN_bn2dec'
C:/Users/Vasiliy/projects/ndk-poc/app/src/main/cpp/ndk-poc.cpp:40: error: undefined reference to 'CRYPTO_free'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
What did I miss?
OpenSSL consists of (at least) two libraries: libcrypto which has the general-purpose cryptographic functions; and libssl which is a TLS implementation built on top of libcrypto.
So in your case libcrypto would be the appropriate library to link against.

linking problem with dlfcn DLFCN-WIN32 library

I am currently trying to use the DLFCN-WIN32 library in order to use a c++ script originally implemented to use the dlfcn.h library.
When compiling the code (cantera V2.3), everything goes well except when generating the shared library where the dlopen and dlclose functions are not found.
originally script is :
/**
* #file CustomKinetics.cpp
*
* #ingroup chemkinetics
*/
//
// Author: Q. Cazeres, A. Felden, P. Pepiot
//
//
#include "cantera/kinetics/CustomKinetics.h"
#include <iostream>
#include <dlfcn.h>
using namespace std;
namespace Cantera
{
CustomKinetics::CustomKinetics(thermo_t* th) : GasKinetics(th)
{
printf("WARNING: Using customized kinetics from f90 file.\n");
handle = dlopen("customkinetics.so", RTLD_LAZY);
// load symbol
ck = (ck_t) dlsym(handle, "customkinetics_");
}
void CustomKinetics::get_wdot_reduced(doublereal* wdot)
{
doublereal P = thermo().pressure();
doublereal T = thermo().temperature();
// New yarc2 format
//doublereal rho = thermo().density();
const doublereal* m_y = thermo().massFractions();
ck(&P,&T,&m_y[0],&wdot[0]);
// New yarc2 format
//ck(&P,&T,&rho,&m_y[0],&wdot[0]);
// Old yarc format
//mol/kmol conversion cantera is in kmol
for (size_t i=0;i<thermo().nSpecies();i++) {
wdot[i]=wdot[i]/1000.0;
}
}
The script is compiled with the following command line :
g++ -o build\src\kinetics\CustomKinetics.o -c -std=c++0x -lpsapi -O3 -Wno-inline -g -Wall -include src/pch/system.h -DNDEBUG -Iinclude -Iinclude\cantera\ext -Ibuild\src -Ibuild\src\L -Isrc\L -IL:\LIB_WINDOWS\DLFCN-WIN32\include -IL:\LIB_WINDOWS\BOOST\boost_1_78_0 src\kinetics\CustomKinetics.cpp
The shared library is compiled with the following command line :
scons: warning: Using $CXX to link Fortran and C++ code together.
This may generate a buggy executable if the 'g++'
compiler does not know how to deal with Fortran runtimes.
g++ -static-libgcc -static-libstdc++ -shared -o build\lib\cantera_shared.dll build\ext\libexecstream\exec-stream.o build\ext\fmt\fmt\format.o build\ext\fmt\fmt\ostream.o build\ext\fmt\fmt\posix.o build\ext\sundials\src\sundials\sundials_band.o build\ext\sundials\src\sundials\sundials_dense.o build\ext\sundials\src\sundials\sundials_direct.o build\ext\sundials\src\sundials\sundials_iterative.o build\ext\sundials\src\sundials\sundials_math.o build\ext\sundials\src\sundials\sundials_nvector.o build\ext\sundials\src\sundials\sundials_pcg.o build\ext\sundials\src\sundials\sundials_sparse.o build\ext\sundials\src\sundials\sundials_spbcgs.o build\ext\sundials\src\sundials\sundials_spfgmr.o build\ext\sundials\src\sundials\sundials_spgmr.o build\ext\sundials\src\sundials\sundials_sptfqmr.o build\ext\sundials\src\nvec_ser\fnvector_serial.o build\ext\sundials\src\nvec_ser\nvector_serial.o build\ext\sundials\src\cvodes\cvodea.o build\ext\sundials\src\cvodes\cvodea_io.o build\ext\sundials\src\cvodes\cvodes.o build\ext\sundials\src\cvodes\cvodes_band.o build\ext\sundials\src\cvodes\cvodes_bandpre.o build\ext\sundials\src\cvodes\cvodes_bbdpre.o build\ext\sundials\src\cvodes\cvodes_dense.o build\ext\sundials\src\cvodes\cvodes_diag.o build\ext\sundials\src\cvodes\cvodes_direct.o build\ext\sundials\src\cvodes\cvodes_io.o build\ext\sundials\src\cvodes\cvodes_sparse.o build\ext\sundials\src\cvodes\cvodes_spbcgs.o build\ext\sundials\src\cvodes\cvodes_spgmr.o build\ext\sundials\src\cvodes\cvodes_spils.o build\ext\sundials\src\cvodes\cvodes_sptfqmr.o build\ext\sundials\src\ida\ida.o build\ext\sundials\src\ida\ida_band.o build\ext\sundials\src\ida\ida_bbdpre.o build\ext\sundials\src\ida\ida_dense.o build\ext\sundials\src\ida\ida_direct.o build\ext\sundials\src\ida\ida_ic.o build\ext\sundials\src\ida\ida_io.o build\ext\sundials\src\ida\ida_sparse.o build\ext\sundials\src\ida\ida_spbcgs.o build\ext\sundials\src\ida\ida_spgmr.o build\ext\sundials\src\ida\ida_spils.o build\ext\sundials\src\ida\ida_sptfqmr.o build\src\base\Parser.o build\src\base\ValueCache.o build\src\base\application.o build\src\base\checkFinite.o build\src\base\clockWC.o build\src\base\ct2ctml.o build\src\base\ctexceptions.o build\src\base\ctml.o build\src\base\global.o build\src\base\plots.o build\src\base\stringUtils.o build\src\base\xml.o build\src\thermo\ConstCpPoly.o build\src\thermo\ConstDensityThermo.o build\src\thermo\DebyeHuckel.o build\src\thermo\Elements.o build\src\thermo\FixedChemPotSSTP.o build\src\thermo\GibbsExcessVPSSTP.o build\src\thermo\HMWSoln.o build\src\thermo\HMWSoln_input.o build\src\thermo\IdealGasPhase.o build\src\thermo\IdealMolalSoln.o build\src\thermo\IdealSolidSolnPhase.o build\src\thermo\IdealSolnGasVPSS.o build\src\thermo\IonsFromNeutralVPSSTP.o build\src\thermo\LatticePhase.o build\src\thermo\LatticeSolidPhase.o build\src\thermo\MargulesVPSSTP.o build\src\thermo\MaskellSolidSolnPhase.o build\src\thermo\MetalSHEelectrons.o build\src\thermo\MineralEQ3.o build\src\thermo\MixedSolventElectrolyte.o build\src\thermo\MixtureFugacityTP.o build\src\thermo\MolalityVPSSTP.o build\src\thermo\MolarityIonicVPSSTP.o build\src\thermo\Mu0Poly.o build\src\thermo\MultiSpeciesThermo.o build\src\thermo\Nasa9Poly1.o build\src\thermo\Nasa9PolyMultiTempRegion.o build\src\thermo\NasaPoly2.o build\src\thermo\PDSS.o build\src\thermo\PDSS_ConstVol.o build\src\thermo\PDSS_HKFT.o build\src\thermo\PDSS_IdealGas.o build\src\thermo\PDSS_IonsFromNeutral.o build\src\thermo\PDSS_SSVol.o build\src\thermo\PDSS_Water.o build\src\thermo\Phase.o build\src\thermo\PhaseCombo_Interaction.o build\src\thermo\PureFluidPhase.o build\src\thermo\RedlichKisterVPSSTP.o build\src\thermo\RedlichKwongMFTP.o build\src\thermo\SemiconductorPhase.o build\src\thermo\SingleSpeciesTP.o build\src\thermo\Species.o build\src\thermo\SpeciesThermoFactory.o build\src\thermo\SpeciesThermoInterpType.o build\src\thermo\StoichSubstance.o build\src\thermo\SurfPhase.o build\src\thermo\ThermoFactory.o build\src\thermo\ThermoPhase.o build\src\thermo\VPSSMgr.o build\src\thermo\VPSSMgrFactory.o build\src\thermo\VPSSMgr_ConstVol.o build\src\thermo\VPSSMgr_General.o build\src\thermo\VPSSMgr_IdealGas.o build\src\thermo\VPSSMgr_Water_ConstVol.o build\src\thermo\VPSSMgr_Water_HKFT.o build\src\thermo\VPStandardStateTP.o build\src\thermo\WaterProps.o build\src\thermo\WaterPropsIAPWS.o build\src\thermo\WaterPropsIAPWSphi.o build\src\thermo\WaterSSTP.o build\src\tpx\CarbonDioxide.o build\src\tpx\HFC134a.o build\src\tpx\Heptane.o build\src\tpx\Hydrogen.o build\src\tpx\Methane.o build\src\tpx\Nitrogen.o build\src\tpx\Oxygen.o build\src\tpx\RedlichKwong.o build\src\tpx\Sub.o build\src\tpx\Water.o build\src\tpx\lk.o build\src\tpx\utils.o build\src\equil\BasisOptimize.o build\src\equil\ChemEquil.o build\src\equil\MultiPhase.o build\src\equil\MultiPhaseEquil.o build\src\equil\vcs_Gibbs.o build\src\equil\vcs_MultiPhaseEquil.o build\src\equil\vcs_SpeciesProperties.o build\src\equil\vcs_TP.o build\src\equil\vcs_VolPhase.o build\src\equil\vcs_elem.o build\src\equil\vcs_elem_rearrange.o build\src\equil\vcs_inest.o build\src\equil\vcs_nondim.o build\src\equil\vcs_phaseStability.o build\src\equil\vcs_prep.o build\src\equil\vcs_prob.o build\src\equil\vcs_rearrange.o build\src\equil\vcs_report.o build\src\equil\vcs_rxnadj.o build\src\equil\vcs_setMolesLinProg.o build\src\equil\vcs_solve.o build\src\equil\vcs_solve_TP.o build\src\equil\vcs_solve_phaseStability.o build\src\equil\vcs_species_thermo.o build\src\equil\vcs_util.o build\src\numerics\BandMatrix.o build\src\numerics\CVodesIntegrator.o build\src\numerics\DAE_solvers.o build\src\numerics\DenseMatrix.o build\src\numerics\Func1.o build\src\numerics\FuncEval.o build\src\numerics\IDA_Solver.o build\src\numerics\ODE_integrators.o build\src\numerics\ResidJacEval.o build\src\numerics\RootFind.o build\src\numerics\SquareMatrix.o build\src\numerics\funcs.o build\src\numerics\polyfit.o build\src\kinetics\AqueousKinetics.o build\src\kinetics\BulkKinetics.o build\src\kinetics\C12H26_25_373_27_TJKinetics.o build\src\kinetics\C12H26_NOX_27_452_20_TJKinetics.o build\src\kinetics\C2H4_18_320_11_AFKinetics.o build\src\kinetics\C3H8_22_173_12_FCKinetics.o build\src\kinetics\C7H16_25_210_27_FCKinetics.o build\src\kinetics\CH4_22_320_18_TJKinetics.o build\src\kinetics\CustomKinetics.o build\src\kinetics\Falloff.o build\src\kinetics\FalloffFactory.o build\src\kinetics\GasKinetics.o build\src\kinetics\Group.o build\src\kinetics\HYCHEM_27_272_12_AFKinetics.o build\src\kinetics\HYCHEM_NOX_29_548_17_AFKinetics.o build\src\kinetics\ImplicitSurfChem.o build\src\kinetics\InterfaceKinetics.o build\src\kinetics\Kinetics.o build\src\kinetics\KineticsFactory.o build\src\kinetics\Reaction.o build\src\kinetics\ReactionPath.o build\src\kinetics\RxnRates.o build\src\kinetics\importKinetics.o build\src\kinetics\solveSP.o build\src\kinetics\c12h262537327tj.o build\src\kinetics\c12h262745220tj.o build\src\kinetics\c2h41832011af.o build\src\kinetics\c3h82217312fc.o build\src\kinetics\c7h162521027fc.o build\src\kinetics\ch42232018tj.o build\src\kinetics\hychem2727212af.o build\src\kinetics\hychemnox2954817af.o build\src\kinetics\sankaran13.o build\src\transport\AVBPTransport.o build\src\transport\DustyGasTransport.o build\src\transport\GasTransport.o build\src\transport\HighPressureGasTransport.o build\src\transport\LTPspecies.o build\src\transport\LiquidTranInteraction.o build\src\transport\LiquidTransport.o build\src\transport\LiquidTransportData.o build\src\transport\LiquidTransportParams.o build\src\transport\MMCollisionInt.o build\src\transport\MixTransport.o build\src\transport\MultiTransport.o build\src\transport\SimpleTransport.o build\src\transport\SolidTransport.o build\src\transport\SolidTransportData.o build\src\transport\TransportBase.o build\src\transport\TransportData.o build\src\transport\TransportFactory.o build\src\transport\TransportParams.o build\src\transport\WaterTransport.o build\src\oneD\Domain1D.o build\src\oneD\MultiJac.o build\src\oneD\MultiNewton.o build\src\oneD\OneDim.o build\src\oneD\Sim1D.o build\src\oneD\StFlow.o build\src\oneD\boundaries1D.o build\src\oneD\refine.o build\src\zeroD\ConstPressureReactor.o build\src\zeroD\FlowDevice.o build\src\zeroD\FlowReactor.o build\src\zeroD\IdealGasConstPressureReactor.o build\src\zeroD\IdealGasReactor.o build\src\zeroD\Reactor.o build\src\zeroD\ReactorBase.o build\src\zeroD\ReactorFactory.o build\src\zeroD\ReactorNet.o build\src\zeroD\ReactorSurface.o build\src\zeroD\Wall.o build\src\clib\ct.o build\src\clib\ctfunc.o build\src\clib\ctmultiphase.o build\src\clib\ctonedim.o build\src\clib\ctreactor.o build\src\clib\ctrpath.o build\src\clib\ctsurf.o build\src\clib\ctxml.o -Lbuild\lib -Lbuild\src\L -Lsrc\L -LL:\LIB_WINDOWS\DLFCN-WIN32\lib -Wl,--out-implib,build\lib\libcantera_shared.a -Wl,--output-def,build\lib\cantera_shared.def
And after that I got the following error message :
=====
b"build\\src\\kinetics\\CustomKinetics.o: In function `Cantera::CustomKinetics::CustomKinetics(Cantera::ThermoPhase*)':\r\nL:\\LIB_WINDOWS\\CANTERA\\cantera-avbp-2.3/src/kinetics/CustomKinetics.cpp:23: undefined reference to `dlopen'\r\nL:\\LIB_WINDOWS\\CANTERA\\cantera-avbp-2.3/src/kinetics/CustomKinetics.cpp:26: undefined reference to `dlsym'\r\nbuild\\src\\kinetics\\CustomKinetics.o: In function `Cantera::CustomKinetics::close_dl()':\r\nL:\\LIB_WINDOWS\\CANTERA\\cantera-avbp-2.3/src/kinetics/CustomKinetics.cpp:53: undefined reference to `dlclose'\r\nL:\\LIB_WINDOWS\\CANTERA\\cantera-avbp-2.3/src/kinetics/CustomKinetics.cpp:53: undefined reference to `dlclose'\r\ncollect2.exe: error: ld returned 1 exit status\r\n"
=====
scons: *** [build\lib\cantera_shared.dll] Error 1
scons: building terminated because of errors.
The include and lib directories of the DLFCN-WIN32 libraries are well put in argument with -L option. Did I forget a compilation option?
Thank you in advance for your help,
Rock

Building Intel IPP with MingW

I'm trying to use Intel IPP with MingW(mingw-w64\x86_64-8.1.0) using NetBeans 12.2 and also tried with Eclipse 2021-06 (4.20.0) in Win10. Specified the include("C:/Program Files (x86)/Intel/oneAPI/ipp/2021.3.0/include") and dll's("C:/Program Files (x86)/Intel/oneAPI/ipp/2021.3.0/redist/ia32") path in the project settings.
For the below sample code,
#include <iostream>
#include <ipp.h>
using namespace std;
int main(int argc, char** argv)
{
const IppLibraryVersion *lib;
IppStatus status;
Ipp64u cpuFeatures, enabledFeatures;
Ipp8u *gray= NULL;
IppiSize size;
IplImage* img = NULL; // new IplImage structure img
/* Init IPP library */
ippInit(); /* Initialize Intel(R) IPP library */
lib = ippGetLibVersion();/* Get Intel(R) IPP library version info */
printf("%s %s\n", lib->Name, lib->Version);
return 0;
}
I'm getting error,
Error: 'IplImage' was not declared in this scope;
Also, on commenting the line :IplImage* img = NULL; I get the following error,
g++ -o dist/Debug/MinGW-Windows/samplecppapplication
build/Debug/MinGW-Windows/main.o -L"C:/Program\ Files
(x86)/Intel/oneAPI/ipp/2021.3.0/redist/ia32" -lippcc -lippccg9
-lippcch9 -lippccp8 -lippccs8 -lippccw7 -lippch -lippchg9 -lippchh9 -lippchp8 -lippchs8 -lippchw7 -lippcore -lippcv -lippcvg9 -lippcvh9 -lippcvp8 -lippcvs8 -lippcvw7 -lippdc -lippdcg9 -lippdch9 -lippdcp8 -lippdcs8 -lippdcw7 -lippe -lippeg9 -lippeh9 -lippep8 -lippes8 -lippew7 -lippi -lippig9 -lippih9 -lippip8 -lippis8 -lippiw7 -lipps -lippsg9 -lippsh9 -lippsp8 -lippss8 -lippsw7 -lippvm -lippvmg9 -lippvmh9 -lippvmp8 -lippvms8 -lippvmw7 c:/MuTest/MinGW/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -lippcc
c:/MuTest/MinGW/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -lippccg9
c:/MuTest/MinGW/bin/../lib/gcc/i686-w64-mingw32/10.2.0/../../../../i686-w64-mingw32/bin/ld.exe:
cannot find -lippcch9 .... ...
Can you please help in fixing this and get to work using IPP ?
I tried the ipp sample with g++ compiler which comes with mingw-w64\x86_64-8.1.0 in windows10 command prompt(initialize oneapi environment before compiling the code) and it worked fine (after commenting the line :IplImage* img = NULL). I've included libraries from intel64 folder in ipp directory which comes with oneapi, as i'm using 64 bit windows machine.
g++ test.cpp -o ipptest -I "C:\Program Files (x86)\Intel\oneAPI\ipp\2021.3.0/include" -L "C:\Program Files (x86)\Intel\oneAPI\ipp\2021.3.0\redist\intel64" -lippcore

R package with Rcpp

I tried to add a small C++ function (called reduceString) into an R package of mine using Rcpp but I failed to configurate the package so that it compiles fine. The package can be found here.
devtools::install_github("RemiMattheyDoeret/SimBitWrapper")
Here is part of the error message
Error: package or namespace load failed for ‘SimBitWrapper’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/SimBitWrapper/libs/SimBitWrapper.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/SimBitWrapper/libs/SimBitWrapper.so, 6): Symbol not found: __Z12reduceStringv
Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/SimBitWrapper/libs/SimBitWrapper.so
Expected in: flat namespace
in /Library/Frameworks/R.framework/Versions/3.5/Resources/library/SimBitWrapper/libs/SimBitWrapper.so
I have tried to modify again and again the NAMESPACE and DESCRIPTION files as well as src/RcppExports.cpp and R/RcppExports.r files but I just fail to fix the problem. Here are those files as well as the reduceString.cpp file
NAMESPACE
useDynLib(SimBitWrapper, .registration=TRUE)
exportPattern("^[^\\.]")
importFrom(Rcpp, evalCpp)
DESCRIPTION
Package: SimBitWrapper
Title: R wrapper for SimBit
Version: 5.1.0
Authors#R:
person(given = "Remi",
family = "Matthey-Doret",
role = c("aut", "cre"),
email = "remi.b.md#gmail.com",
comment = c(ORCID = "0000-0001-5614-5629"))
Description: The package is a wrapper for SimBit (SimBit is a simulation platform for evolutionary genetic studies). Please see the SimBit manual (at https://github.com/RemiMattheyDoret/SimBit) for description of how to use this SimBitWrapper package.
License: MIT
Encoding: UTF-8
LazyData: true
Depends: R (>= 2.15)
Imports: data.table, processx, Rcpp
LinkingTo: Rcpp
Suggests:
URL: https://github.com/RemiMattheyDoret
src/RcppExports.cpp
#include <Rcpp.h>
using namespace Rcpp;
// reduceString
std::string reduceString();
RcppExport SEXP _SimBitWrapper_reduceString() {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = Rcpp::wrap(reduceString());
return rcpp_result_gen;
END_RCPP
}
static const R_CallMethodDef CallEntries[] = {
{"_SimBitWrapper_reduceString", (DL_FUNC) &_SimBitWrapper_reduceString, 0},
{NULL, NULL, 0}
};
RcppExport void R_init_SimBitWrapper(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}
R/RcppExports.r
reduceString <- function(x) {
.Call(`_SimBitWrapper_reduceString`,x)
}
reduceString.cpp
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
std::string reduceString(CharacterVector& x)
{
// I cut off this part that does not need to be printed here
}
Thanks for posting a link to a repo.
It worked for me as soon as I re-recreated RcppExports.{cpp,R} using my (current) version of Rcpp and a call to compileAttributes(). What version of Rcpp do you have?
The log below uses my wrappers from littler but that is immaterial. The R CMD ... commands would have worked the same way.
Log
edd#rob:/tmp/SimBitWrapper(master)$ build.r
* checking for file ‘./DESCRIPTION’ ... OK
* preparing ‘SimBitWrapper’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘SimBitWrapper_5.1.0.tar.gz’
edd#rob:/tmp/SimBitWrapper(master)$ install2.r -l /tmp/lib SimBitWrapper_5.1.0.tar.gz
* installing *source* package ‘SimBitWrapper’ ...
** using staged installation
** libs
ccache g++ -I"/usr/share/R/include" -DNDEBUG -I'/usr/local/lib/R/site-library/Rcpp/include' -fpic -g -O3 -Wall -pipe -pedantic -c RcppExports.cpp -o RcppExports.o
ccache g++ -I"/usr/share/R/include" -DNDEBUG -I'/usr/local/lib/R/site-library/Rcpp/include' -fpic -g -O3 -Wall -pipe -pedantic -c reduceString.cpp -o reduceString.o
reduceString.cpp: In function ‘std::string reduceString(Rcpp::CharacterVector&)’:
reduceString.cpp:10:27: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘R_xlen_t’ {aka ‘long int’} [-Wsign-compare]
10 | for (size_t i = 0 ; i < x.size() ; ++i)
| ~~^~~~~~~~~~
ccache g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o SimBitWrapper.so RcppExports.o reduceString.o -L/usr/lib/R/lib -lR
installing to /tmp/lib/00LOCK-SimBitWrapper/00new/SimBitWrapper/libs
** R
** byte-compile and prepare package for lazy loading
** help
No man pages found in package ‘SimBitWrapper’
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (SimBitWrapper)
edd#rob:/tmp/SimBitWrapper(master)$
Diff
edd#rob:/tmp/SimBitWrapper(master)$ git diff
diff --git a/R/RcppExports.R b/R/RcppExports.R
index 19a82b4..62f890a 100644
--- a/R/RcppExports.R
+++ b/R/RcppExports.R
## -2,6 +2,6 ##
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
reduceString <- function(x) {
- .Call(`_SimBitWrapper_reduceString`,x)
+ .Call(`_SimBitWrapper_reduceString`, x)
}
diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp
index 90dda3b..0b91977 100644
--- a/src/RcppExports.cpp
+++ b/src/RcppExports.cpp
## -6,18 +6,19 ##
using namespace Rcpp;
// reduceString
-std::string reduceString();
-RcppExport SEXP _SimBitWrapper_reduceString() {
+std::string reduceString(CharacterVector& x);
+RcppExport SEXP _SimBitWrapper_reduceString(SEXP xSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
- rcpp_result_gen = Rcpp::wrap(reduceString());
+ Rcpp::traits::input_parameter< CharacterVector& >::type x(xSEXP);
+ rcpp_result_gen = Rcpp::wrap(reduceString(x));
return rcpp_result_gen;
END_RCPP
}
static const R_CallMethodDef CallEntries[] = {
- {"_SimBitWrapper_reduceString", (DL_FUNC) &_SimBitWrapper_reduceString, 0},
+ {"_SimBitWrapper_reduceString", (DL_FUNC) &_SimBitWrapper_reduceString, 1},
{NULL, NULL, 0}
};
edd#rob:/tmp/SimBitWrapper(master)$
PS: You have a second copy of your package in your repo. I just the top-level. Also, you committed the .DS_Store files from your mac which are of no use to R or a repo.

How to compile Apache Avro C++ example

Probably a newbie mistake, but can anyone please tell me what I'm doing wrong here?
Any help is much appreciated.
I wrote this simple Makefile:
CC=g++
INC=-I/usr/local/avro-cpp-1.7.2 -I/usr/local/boost_1_53_0
cpx : generated.cc
$(CC) -o cpx generated.cc $(INC)
Which generates these the errors:
g++ -o cpx generated.cc -I/usr/local/avro-cpp-1.7.2 -I/usr/local/boost_1_53_0
/tmp/ccYymUVo.o: In function `main':
generated.cc:(.text+0x84): undefined reference to `avro::memoryOutputStream(unsigned long)'
generated.cc:(.text+0xb0): undefined reference to `avro::binaryEncoder()'
generated.cc:(.text+0x11e): undefined reference to `avro::memoryInputStream(avro::OutputStream const&)'
generated.cc:(.text+0x150): undefined reference to `avro::binaryDecoder()'
collect2: ld returned 1 exit status
make: *** [cpx] Error 1
Here's the source as supplied in the Avro examples directory:
#############################
# cpx.hh
#############################
#ifndef CPX_HH_1278398428__H_
#define CPX_HH_1278398428__H_
#include "boost/any.hpp"
#include "avro/Specific.hh"
#include "avro/Encoder.hh"
#include "avro/Decoder.hh"
namespace c {
struct cpx {
double re;
double im;
};
}
namespace avro {
template<> struct codec_traits<c::cpx> {
static void encode(Encoder& e, const c::cpx& v) {
avro::encode(e, v.re);
avro::encode(e, v.im);
}
static void decode(Decoder& d, c::cpx& v) {
avro::decode(d, v.re);
avro::decode(d, v.im);
}
};
}
#endif
and
#############################
# generated.cc
#############################
#include "cpx.hh"
#include "avro/Encoder.hh"
#include "avro/Decoder.hh"
int
main()
{
std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();
avro::EncoderPtr e = avro::binaryEncoder();
e->init(*out);
c::cpx c1;
c1.re = 1.0;
c1.im = 2.13;
avro::encode(*e, c1);
std::auto_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
avro::DecoderPtr d = avro::binaryDecoder();
d->init(*in);
c::cpx c2;
avro::decode(*d, c2);
std::cout << '(' << c2.re << ", " << c2.im << ')' << std::endl;
return 0;
}
Thanks.
1)
in your output, you don't link against the avrocpp library, although your comments about the LD_LIBRARY_PATH suggest that you got the link to work, but the example program failed to find the library when executing. Your compile line needs the linker option: -l avrocpp
2)
If the avrocpp library .so is not installed in a path that your runtime linker is configured to search, you can add the library path into the binary itself with the linker option -rpath.
Example 1: Assuming your avrocpp library is installed in /usr/local/lib (i.e. /usr/local/lib/libavrocpp.so), and your runtime linker doesn't look in /usr/local/lib, add the rpath by adding this option to your compiler command line:
-Wl,-rpath,/usr/local/lib
Example 2: Assuming your avrocpp library is installed in /usr/local/avro-cpp-1.7.2/lib (i.e. /usr/local/avro-cpp-1.7.2/lib/libavrocpp.so), add the rpath by adding this option to your compiler command line:
-Wl,-rpath,/usr/local/avro-cpp-1.7.2/lib
Try using avrogencpp with options -i < schema_file > -o < header_file >
Download and compile the Avro c++ sources https://stackoverflow.com/questions/40889705/how-to-compile-apache-avro-c-on-windows (this will generate the "avrogencpp.exe")
Download avro-tools http://avro.apache.org/releases.html#Download, and (with java installed)
run:
java -jar avro-tools-1.8.1.jar idl file.avdl > file.json
Edit the generated json file and delete the following
If you have any lines preceding the required structs at the beginning, delete them. (I had "protocol": "file", "namespace" : "some_optional_namespace", "types" :)
messages entry (at the bottom)
If you have multiple structs defined in the same json file, surround them all with "[ ]" (you should have commas between the different structs and make sure the last struct as not proceeded with a ","
Run
avrogencpp.exe -p - -n some_optional_namespace -U --input file.json --output file.hh