GRPC cross compile for android using NDK toolchain - c++

I am fairly new to this. So, I am trying to cross compile GRPC (https://github.com/grpc/grpc) for android using cmake and NDK toolchain to generate shared libraries, using the below:
cmake -DCMAKE_TOOLCHAIN_FILE=$And_PATH/android.toolchain.cmake -DCMAKE_CROSSCOMPILING=true -DANDROID_ABI=arm64-v8a -DCMAKE_INSTALL_PREFIX=/cross_grpc -DANDROID_PLATFORM=android-26 -DANDROID_STL=c++_shared CFLAGS="std=c11" CXXFLAGS="std=c++14" cmake -B . -S /grpc
With the above i am able to build and static libraries get generated, but if i add -DBUILD_SHARED_LIBS=ON , i am getting below errors
ld: error: undefined symbol: BIO_ctrl
referenced by bio_ssl.cc:191 (/grpc/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc:191)
ld: error: undefined symbol: BIO_clear_retry_flags
referenced by bio_ssl.cc:65 (/grpc/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc:65)
ld: error: undefined symbol: BIO_set_retry_write
referenced by bio_ssl.cc:71 (/grpc/third_party/boringssl-with-bazel/src/ssl/bio_ssl.cc:71)
I have not pasted all the errors as it's a long list of undefined symbol errors.

Related

Boost ld: final link failed: Bad value: relocation R_X86_64_PC32 against undefined hidden symbol

I'm Trying to Link boost library with our code, I'm Getting the Following error
ld: /boost/lib/laxno/libboost_thread.a(thread.o): relocation R_X86_64_PC32 against undefined hidden symbol `_ZTCN5boost10wrapexceptINS_21thread_resource_errorEEE0_NS_16exception_detail10clone_implINS3_19error_info_injectorIS1_EEEE' can not be used when making a shared object
ld: final link failed: Bad value
I have built the boost with the GCC 7.4.0 with the following command
./b2 cxxflags="-fPIC -std=c++14" cflags="-fPIC" -j4
Getting the following error if I exclude the "-fPIC" flag while building the boost libs:
/boost/lib/laxno/libboost_thread.a(thread.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/boost/lib/laxno/libboost_thread.a: could not read symbols: Bad value
Using the boost libs and boost .so files from the boost install location instead of build location fixed the issue.

linking Boost library to Xcode project

I'm trying to create a project that uses the Boost library. I'm on OS X 10.9.5 (I should update that) and using Xcode 6.2. I installed boost with homebrew brew install boost and it's located in /usr/local/Cellar/boost/1.59.0. I added the path the the /usr/local/Cellar/boost/1.59.0/include to the header search path in Xcode and it seems to recognize it because the autocomplete hinting works.
In the boost documentation it mentions that some of the Boost libraries must be built before they can be used. I assume homebrew took care of that because I have a bunch of .a and .dylib files in /usr/local/Cellar/boost/1.59.0/lib
I'm still new to C++ and the Xcode build process but it seems I still need to link the compiled libraries to my project. I tried adding the path /usr/local/Cellar/boost/1.59.0/lib to my project's library search paths but I'm not sure if that is correct.
Here is the error I get when I try to build my project.
Undefined symbols for architecture x86_64:
"boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::create_directory(boost::filesystem::path const&) in main.o
"boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
boost::filesystem::exists(boost::filesystem::path const&) in main.o
"boost::system::system_category()", referenced from:
___cxx_global_var_init2 in main.o
"boost::system::generic_category()", referenced from:
___cxx_global_var_init in main.o
___cxx_global_var_init1 in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Is there something else I need to configure to get this to work?
Adding the path is correct but you also need to specify the libraries you need. On the commandline you would use -l for that in Xcode you can add them to Other Linker Flags.
The libraries you need are boost_filesystem and boost_system.

Issue compiling Go program when linking to a compiled version of zeromq on Mac

I've compiled ZeroMQ on Mac OSX 10.9.5 in order to then link to a simple Go program using github.com/pebbe/zmq4, but I'm getting this error I don't understand or know exactly how to remedy.
# github.com/pebbe/zmq4
ld: warning: ignoring file /usr/local/lib/libzmq.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libzmq.dylib
Undefined symbols for architecture i386:
"_zmq_bind", referenced from:
__cgo_59814aec404b_C2func_zmq_bind in zmq4.cgo2.o
__cgo_59814aec404b_Cfunc_zmq_bind in zmq4.cgo2.o
(maybe you meant: __cgo_59814aec404b_Cfunc_zmq_bind, __cgo_59814aec404b_C2func_zmq_bind )
"_zmq_close", referenced from:
__cgo_59814aec404b_C2func_zmq_close in zmq4.cgo2.o
__cgo_59814aec404b_Cfunc_zmq_close in zmq4.cgo2.o
(maybe you meant: __cgo_59814aec404b_C2func_zmq_close,
...
"_zmq_z85_encode", referenced from:
__cgo_59814aec404b_Cfunc_zmq_z85_encode in zmq4.cgo2.o
(maybe you meant: __cgo_59814aec404b_Cfunc_zmq_z85_encode)
ld: symbol(s) not found for architecture i386
collect2: error: ld returned 1 exit status
I think it makes sense that the dylib is made for x86_64 (the Mac) but why Go is trying to link with i386? How do I control that and make it link differently? or even if it's correct?
If you build libzmq yourself, configure with --disable-shared --enable-static keys. If you use homebrew, uninstall zmq and build the library manually. If you need "fat" universal static library use this script:
https://github.com/drewcrawford/libzmq-ios

Linking OpenCL libraries while compiling C++ code with icpc

I am trying to compile a C++ program (that uses OpenCL functions) using Intel ICPC compiler: icpc mycode.cpp. I am getting the following error:
Undefined symbols for architecture x86_64:
"_clBuildProgram", referenced from:
_main in icpc4lnp65.o
..
..
"_clSetKernelArg", referenced from:
_main in icpc4lnp65.o
ld: symbol(s) not found for architecture x86_64
For g++ I saw that -framework OpenCL argument does the job of linking OpenCL libraries, but I am unable to figure out how to do the linking of OpenCL libraries using ICPC and there is not much documentation on using ICPC with OpenCL.

how to compile C++ - libsndfile on iOS

ld: warning: ignoring file /Users/vibhavarirajadnya/MyDev/iOS-Projects/Music/POC/ReadWaveFile/ReadWaveFile/libsndfile.a, file was built for archive which is not the architecture being linked (i386): /Users/vibhavarirajadnya/MyDev/iOS-Projects/Music/POC/ReadWaveFile/ReadWaveFile/libsndfile.a
Undefined symbols for architecture i386:
"_sf_close", referenced from:
SndfileHandle::SNDFILE_ref::~SNDFILE_ref() in ReadWaveFile.o
"_sf_open", referenced from:
SndfileHandle::SndfileHandle(char const*, int, int, int, int) in ReadWaveFile.o
"_sf_strerror", referenced from:
SndfileHandle::strError() const in ReadWaveFile.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I tried compiling libsndfile file in 3 ways:
1. ./configure then make and make install through command prompt.
2. http://ofdsp.blogspot.in/2011/07/installing-libsndfile-with-xcode.html
3. http://en.efreedom.net/Question/1-11576168/Cross-Compile-Libsndfile-Arm-Raspberry-Pi
With the first option I am getting the error mentioned above. With the second, I am getting some 69 errors most of them related to FLAC. With the third option I am getting the same as 1. It also gives a msg in the command prompt:
Installation directories :
Library directory : ................... /Users/vibhavarirajadnya/Arm/lib
Program directory : ................... /Users/vibhavarirajadnya/Arm/bin
Pkgconfig directory : ................. /Users/vibhavarirajadnya/Arm/lib/pkgconfig
HTML docs directory : ................. /Users/vibhavarirajadnya/Arm/share/doc/libsndfile1-dev/html
But when I check in Finder, there is no such directory.
Can somebody tell me a step by step method to compile libsndfile and its dependencies for Mac iOSX?