I'm trying to create go app, which uses some C++ code from sdk in shared library.
Added reference to target library with #cgo LDFLAGS:
#cgo LDFLAGS: -L/opt/cprocsp/lib/amd64 -lxades -v
and build go app with
go build -o main .
Compilation goes ok, but linking fails with error
/usr/bin/ld: $WORK/b001/_x003.o: undefined reference to symbol 'CryptReleaseContext'
/usr/bin/ld: //opt/cprocsp/lib/amd64/libcapi10.so.4: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Function CryptReleaseContext exists in /opt/cprocsp/lib/amd64/libxades.so.
With -v option I noticed linker arguments order
/usr/lib/gcc/x86_64-linux-gnu/8/collect2 ... $WORK/b001/_cgo_main.o $WORK/b001/_x001.o $WORK/b001/_x002.o $WORK/b001/_x003.o -lxades -lstdc++ ...
With Google I found that arguments order may be important, but I can't find a way to control them and stucking with it. How can I build app?
Example:
main.go
package main
import "log"
func main() {
data := "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Envelope xmlns=\"urn:envelope\">" +
"<Data>Hello, World!</Data>" +
"<Node xml:id=\"nodeID\">Hello, Node!</Node>" +
"</Envelope>"
signed := Sign(data)
log.Print(signed)
}
signer.go
package main
/*
#cgo LDFLAGS: -L/opt/cprocsp/lib/amd64 -lxades -v
#include <stdarg.h>
#include <stdlib.h>
#include "signer.h"
*/
import "C"
import "log"
import "unsafe"
func Sign(data string) (result string) {
log.Print("Signing message")
c_data := C.CString(data)
defer C.free(unsafe.Pointer(c_data))
c_result := C.CString(result)
defer C.free(unsafe.Pointer(c_result))
C.sign(c_data, c_result)
return C.GoString(c_result)
}
signer.h
void sign(char* src, char *dst);
signer.cpp
SDK's example code, that uses functions from /opt/cprocsp/lib/amd64/libxades.so
...
extern "C" {
void sign(char* src, char *dst){
BYTE *pbToBeSigned = (BYTE *) src;
DWORD cbToBeSigned = strlen(src);
static XADES_SIGN_MESSAGE_PARA signParams = { sizeof(signParams) };
initSignParams(&signParams);
PCRYPT_DATA_BLOB pSignedMessage = 0;
// Создаем подписанное сообщение
if (!XadesSign(&signParams, NULL, FALSE, pbToBeSigned, cbToBeSigned, &pSignedMessage)) {
cout << "XadesSign() failed" << endl;
return;
}
vector<unsigned char> message(pSignedMessage->cbData);
copy(pSignedMessage->pbData, pSignedMessage->pbData + pSignedMessage->cbData, message.begin());
char* result = reinterpret_cast<char*>(message.data());
strcpy(dst, result);
}
}
Update
#cgo LDFLAGS: -L/opt/cprocsp/lib/amd64 -Wl,-rpath,/opt/cprocsp/lib/amd64 -lxades -v
didn't help
answer was in second error:
#cgo LDFLAGS: -L/opt/cprocsp/lib/amd64 -lxades -lcapi10 -lcapi20 -v
first time when I'm trying to add lcapi10 - missed that new error tells about lcapi20, not 10
Related
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
Compiler failed with error Undefined symbols for architecture x86_64
macOS 10.15.6 Catalina
compiler
g++-11 --version
g++-11 (Homebrew GCC 11.2.0_3) 11.2.0
error :
Undefined symbols for architecture x86_64:
"__ZN4ssdb6Client7connectEPKci", referenced from:
_main in cciJLzzz.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
.cpp
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include "SSDB_client.h"
int main(int argc, char **argv){
const char *ip = (argc >= 2)? argv[1] : "127.0.0.1";
int port = (argc >= 3)? atoi(argv[2]) : 8888;
ssdb::Client *client = ssdb::Client::connect(ip, port);
if(client == NULL){
printf("fail to connect to server!\n");
}else{
printf("ssdb client\n");
}
delete client;
return 0;
}
is there a notation issue here ?
namespace ssdb, class client ..
if I replace this line :
ssdb::Client *client = ssdb::Client::connect(ip, port);
with :
ssdb::Client *client = 0;
the compiler works and I don't get this error ..
the above code is from ssdb docs :
ssdb docs
ssdb docs C++ client
I would like to connect to the ssdb server ..
EDIT :
For command requests
g++ -o hello-ssdb hello-ssdb.cpp libssdb-client.a
..in libssdb-client.a(SSDB_impl.o)
..in libssdb-client.a(link.o)
ld: symbol(s) not found for architecture x86_64
g++ -o hello-ssdb.cpp hello-ssdb libssdb-client.a
ld: can't link with a main executable file
Regarding libssdb-client.a
ar t libssdb-client.a
__.SYMDEF
SSDB_impl.o
bytes.o
link.o
link_addr.o
..
using ssdb for long time but with php client. fine in most cases, but there is something I have to iterate many many times .. and with C/C++ I should be able to save a lot of time ..
..
Workaround :
package main
import (
"fmt"
"os"
"ssdb"
)
func main() {
fmt.Println("We will use Golang .. \n")
ip := "127.0.0.1"
port := 8888
db, err := ssdb.Connect(ip, port)
if err != nil {
os.Exit(1)
}
defer db.Close()
var val interface{}
keys := []string{}
keys = append(keys, "c");
keys = append(keys, "d");
val, err = db.Do("multi_get", "a", "b", keys);
fmt.Printf("%s\n", val);
db.Set("a", "xxx")
val, err = db.Get("a")
fmt.Printf("%s\n", val)
fmt.Printf("----\n");
return
}
Note that in the documentation for ssdb, they include a libssdb.a that you need to link:
g++ -o hello-ssdb hello-ssdb.cpp libssdb.a
This would have the implementation of all the code for ssdb and is why you are seeing the problem you are seeeing.
I want to use this library in my c++/test.cpp file.
#include "omp/HandEvaluator.h"
#include <iostream>
using namespace omp;
int main()
{
HandEvaluator eval;
Hand h = Hand::empty(); // Final hand must include empty() exactly once!
h += Hand(51) + Hand(48) + Hand(0) + Hand(1) + Hand(2); // AdAs2s2h2c
std::cout << eval.evaluate(h) << std::endl; // 28684 = 7 * 4096 + 12
}
I downloaded the source code from github and placed into the OMPEval folder. After make the ompeval.a library appeared.
Here is the folder structure:
Now I try to build it:
projects/c++$ g++ -Wall -g -L /home/a/projects/c++/OMPEval/lib/ -l ompeval -I /home/a/projects/c++/OMPEval/ test.cpp -v
but the linker has error:
/usr/bin/ld: cannot find -lompeval
collect2: error: ld returned 1 exit status
Here is the whole build log:
I'm fairly new to C++ but this thing has me baffled by any logic. My code is as follows:
#include "stdlib.h"
#include "syslog.h"
#include "unistd.h"
#include "sys/stat.h"
#include "X11/Xlib.h"
#include "cstdio"
void process();
void startTracker();
Display *display;
Window rootWindow;
XEvent xevent;
I have the Xlib header included and if I click on member functions in Eclipse it navigates to the definitions.
int main(int argc, char *argv[])
{
// set logging up
openlog("unison", LOG_CONS|LOG_PID|LOG_NDELAY, LOG_LOCAL1);
syslog(LOG_NOTICE, "Starting Unison Handler");
pid_t pid, sid;
pid = fork();
// fork failed
if (pid < 0) {
exit(EXIT_FAILURE);
}
if (pid > 0) {
exit(EXIT_SUCCESS);
}
umask(0);
sid = setsid();
if (sid < 0) {
exit(EXIT_FAILURE);
}
if (chdir("/") < 0) {
exit(EXIT_FAILURE);
}
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
startTracker();
while (true) {
process();
}
closelog();
return(EXIT_SUCCESS);
}
Then I assign the variables for input selection
void startTracker() {
display = XOpenDisplay(0);
rootWindow = XRootWindow(display, 0);
XSelectInput(display, rootWindow, PointerMotionMask);
}
void process()
{
...but when i add the &event here...
XNextEvent(display, &xevent);
switch (xevent.type) {
case MotionNotify:
syslog(
LOG_NOTICE,
"Mouse position is %dx%d",
xevent.xmotion.x_root, xevent.xmotion.y_root
);
}
}
...the whole thing falls apart.
For some reason passing the xevent as reference throws off the entire Xlib header and gives me this:
00:16:15 **** Incremental Build of configuration Debug for project unisond ****
make all
Building file: ../unisond.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"unisond.d" -MT"unisond.d" -o "unisond.o" "../unisond.cpp"
Finished building: ../unisond.cpp
Building target: unisond
Invoking: GCC C++ Linker
g++ -o "unisond" ./unisond.o
./unisond.o: In function `startTracker()':
/home/ancarius/workspace/unisond/Debug/../unisond.cpp:97: undefined reference to `XOpenDisplay'
/home/ancarius/workspace/unisond/Debug/../unisond.cpp:98: undefined reference to `XRootWindow'
/home/ancarius/workspace/unisond/Debug/../unisond.cpp:99: undefined reference to `XSelectInput'
./unisond.o: In function `process()':
/home/ancarius/workspace/unisond/Debug/../unisond.cpp:105: undefined reference to `XNextEvent'
collect2: error: ld returned 1 exit status
make: *** [unisond] Error 1
00:16:15 Build Finished (took 159ms)
At the risk of getting downvoted could someone please explain what I've done wrong? I've tried everything I could think of but no luck.
It looks like you are missing the X11 library for linking.
add -lX11 to the g++ invocation.
This provides the steps required.
Right click on Project Folder> Properties> C/C++ Build > Settings > GCC C++ Linker > Libraries > add "X11"
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