link a shared library to another - cmake

I am using Cmake as below:
**build.sh**
cmake -S . -B $BUILD_DIR_PREFIX$BUILD_TYPE \
-DCMAKE_C_COMPILER=$C_COMPILER \
-DCMAKE_CXX_COMPILER=$CXX_COMPILER \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-GNinja \
-DCMAKE_CXX_STANDARD_LIBRARIES="-lcurl -lssl -lmylib" \
$SANITIZER \
${CMAKE_PARAMS[#]}
I have created a shared library mylib.so in path /home/sama/mylib.so
how can I link my shared library as curl or ssl?
I have done export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sama/ before but still i get error /usr/bin/ld: cannot find -lmylib

Related

CPPFLAGS set from configure.ac are ignored in Makefile.am

I am trying to build TerraGear with self-made AutoTools files (configure script). TerraGear is split into several subprojects. For each, I create a different set of configure.ac and Makefile.am files, but they are all almost the same.
Consider the following two files:
configure.ac
AC_PREREQ([2.69])
AC_INIT([TerraGear libterragear], [2.1.0], [])
AC_CONFIG_SRCDIR([airport.cxx])
AC_CONFIG_FILES([Makefile])
AM_INIT_AUTOMAKE([foreign])
AC_PROG_CXX
PKG_CHECK_MODULES([ZLIB], [zlib])
PKG_CHECK_MODULES([GDAL], [gdal])
AC_ARG_WITH([simgear-dir], [AS_HELP_STRING(
[--with-simgear-dir=prefix],
[installation prefix of SimGear])],
[
SIMGEAR_CPPFLAGS="-I${withval}/include"
SIMGEAR_LIBRARY="-L${withval}/lib"
]
)
AC_MSG_NOTICE([simgear cppflags : ${SIMGEAR_CPPFLAGS}])
AC_OUTPUT
Makefile.am
bin_PROGRAMS = genapts850
genapts850_SOURCES = airport.cxx \
apt_math.cxx \
closedpoly.cxx \
debug.cxx \
elevations.cxx \
helipad.cxx \
lights.cxx \
linearfeature.cxx \
linked_objects.cxx \
main.cxx \
object.cxx \
output.cxx \
parser.cxx \
runway.cxx \
rwy_simple.cxx \
rwy_gen.cxx \
scheduler.cxx \
taxiway.cxx
genapts850_LDADD = -L$(top_srcdir)/../../Lib/terragear \
$(SIMGEAR_LIBRARY) \
-lSimGearCore \
-lSimGearScene \
-lterragear \
$(ZLIB_LIBRARY) \
$(GDAL_LIBRARY)
genapts850_CXXFLAGS = -I$(top_srcdir)/../../Lib \
-I$(top_srcdir)/../../Lib/terragear \
$(SIMGEAR_CPPFLAGS) \
$(ZLIB_CFLAGS) \
$(GDAL_CFLAGS)/gdal
I run autoreconf:
autoreconf -vfi
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf --force
autoreconf: configure.ac: not using Autoheader
autoreconf: running: automake --add-missing --copy --force-missing
autoreconf: Leaving directory `.'
then run the configure script:
./configure --with-simgear-dir=/path/to/simgear/installation/prefix
[...]
configure: simgear cppflags : -I/path/to/simgear/installation/prefix/include
[...]
then I run make:
make
g++ -DPACKAGE_NAME=\"TerraGear\ libterragear\" -DPACKAGE_TARNAME=\"terragear-libterragear\" -DPACKAGE_VERSION=\"2.1.0\" -DPACKAGE_STRING=\"TerraGear\ libterragear\ 2.1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"terragear-libterragear\" -DVERSION=\"2.1.0\" -I. -I./../../Lib -I./../../Lib/terragear -Ig++ -DPACKAGE_NAME=\"TerraGear\ libterragear\" -DPACKAGE_TARNAME=\"terragear-libterragear\" -DPACKAGE_VERSION=\"2.1.0\" -DPACKAGE_STRING=\"TerraGear\ libterragear\ 2.1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"terragear-libterragear\" -DVERSION=\"2.1.0\" -I. -I./../../Lib -I./../../Lib/terragear -I/path/to/simgear/installation/prefix/include/gdal -g -O2 -MT genapts850-airport.o -MD -MP -MF .deps/genapts850-airport.Tpo -c -o genapts850-airport.o `test -f 'airport.cxx' || echo './'`airport.cxx
airport.cxx:6:10: fatal error: simgear/compiler.h: Datei oder Verzeichnis nicht gefunden
6 | #include <simgear/compiler.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:471: genapts850-airport.o] Fehler 1
(simgear/compiler.h resides inside /path/to/simgear/installation/prefix/include)
What am I doing wrong ? I'm banging my head into the screen for three hours now without being able to figure out the problem. Please help …
Not all shell variables defined in configure are forwarded to output files. Generally speaking, you need to use AC_SUBST() to tell Autoconf that a shell variable should be an output variable:
AC_SUBST([SIMGEAR_CPPFLAGS])
AC_SUBST([SIMGEAR_LIBRARY])

LLVM ERROR: Cannot select: intrinsic %llvm.objc.clang.arc.use

I'm getting the next error with llc when trying to to link some IR files:
LLVM ERROR: Cannot select: intrinsic %llvm.objc.clang.arc.use
I discovered that if I disabled clang optimization (O0) during compilation the error doesn't pop up, but I don't want to do that
I attach a sample of how to reproduce it, just cd the 'issue' folder and run the 'issue.sh' to reproduce the error. You must have Xcode (12.x preferred) tu run it
https://drive.google.com/file/d/1j0TvMZI2A7QxRbv_Q7aydtlNYaiTPYBm/view?usp=sharing
This is what the issue.sh contains, that is a reduced version of my real implementation:
echo "clang..."
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c \
-target arm64-apple-ios12.0 \
-fobjc-arc -fmodules \
-S -Os -flto=thin \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.1.sdk \
-fembed-bitcode \
-c ${PWD}/GTMSessionFetcher.m \
-o ${PWD}/GTMSessionFetcher.ll
echo "llc..."
${PWD}/llc \
GTMSessionFetcher.ll \
-stats -filetype=obj \
-code-model=small \
-enable-machine-outliner=never \
--mtriple=arm64-apple-ios12.0 \
-o ${PWD}/GTMSessionFetcher.o
As I mentioned before, if you change -Os for -O0, the error disappears, but I do need the size optimization.
The objective-c file that I included is a file from a pod from a Google library
https://github.com/google/gtm-session-fetcher
I found a similar question, but it doesn't have any answer yet
LLVM Error Cannot select intrinsic %llvm.coro.begin
I thought it was bug, but it wasn't
As Akira pointed me in LLVM bug report I was able to fix it by adding an intermediate optimizer OPT step with -objc-arc-contract flag:
clang
...
<path to your LLVM tools>/OPT \
<Your IR file> \
-objc-arc-contract \
-o <Output file>
llc
...

(Cmake, Trilinos)clang: error: unsupported option '-fopenmp'

platform:macOS 11.1
when I tried to configure Trilinos, I met a problem and I can not handle it.
The following command is used to compile Trilinos:
#!/bin/bash
rm -rf CMakeCache.txt
rm -rf CMakeFiles
rm -rf CMakeCache.txt
cmake \
-D CMAKE_INSTALL_PREFIX:PATH=/Users/weiqiangguo/Downloads/Trilinos/build \
-D CMAKE_BUILD_TYPE=Release \
-D BUILD_SHARED_LIBS:BOOL=ON \
\
-D TPL_ENABLE_MPI:BOOL=ON \
-D TPL_ENABLE_BLAS:BOOL=ON \
-D TPL_ENABLE_LAPACK:BOOL=ON \
-D TPL_ENABLE_Pthread:BOOL=ON \
-D TPL_ENABLE_HWLOC:BOOL=ON \
-D TPL_ENABLE_HDF5:BOOL=ON \
-D TPL_ENABLE_SCALAPACK:BOOL=ON \
-D TPL_ENABLE_SuperLU:BOOL=ON \
-D TPL_ENABLE_SuperLUDist:BOOL=ON \
-D TPL_ENABLE_METIS:BOOL=ON \
-D TPL_ENABLE_ParMETIS:BOOL=ON \
\
-D ML_ENABLE_SuperLU:BOOL=OFF \
\
-D CMAKE_C_COMPILER:STRING="mpicc" \
-D CMAKE_CXX_COMPILER:FILEPATH=/usr/local/bin/mpicxx \
-D CMAKE_Fortran_COMPILER:STRING="mpif90" \
-D CMAKE_CXX_FLAGS:STRING="-O3 -g -fopenmp" \
\
-D TPL_SCALAPACK_LIBRARIES='/usr/local/lib/libscalapack.dylib' \
\
-D Teuchos_ENABLE_COMPLEX=ON \
\
-D Trilinos_ENABLE_ALL_PACKAGES:BOOL=OFF \
-D Trilinos_ENABLE_ALL_OPTIONAL_PACKAGES:BOOL=OFF \
-D Trilinos_ENABLE_ML:BOOL=ON \
-D Trilinos_ENABLE_Belos:BOOL=ON \
-D Trilinos_ENABLE_Epetra:BOOL=ON \
-D Trilinos_ENABLE_EpetraExt:BOOL=ON \
-D Trilinos_ENABLE_Ifpack:BOOL=ON \
-D Trilinos_ENABLE_Amesos:BOOL=ON \
-D Trilinos_ENABLE_Anasazi:BOOL=ON \
-D Trilinos_ENABLE_NOX:BOOL=ON \
-D Trilinos_ENABLE_Teko:BOOL=ON \
-D Trilinos_ENABLE_Galeri:BOOL=ON \
-D Trilinos_ENABLE_OpenMP:BOOL=OFF \
-D Trilinos_ENABLE_PyTrilinos:BOOL=ON \
\
-D MPI_BASE_DIR:FILEPATH="/usr/local/Cellar/open-mpi" \
-D PYTHON_EXECUTABLE:FILEPATH="/usr/bin/python3" \
-D SuperLU_LIBRARY_DIRS:FILEPATH="/usr/local/lib" \
-D SuperLU_INCLUDE_DIRS:FILEPATH="/usr/local/include" \
-D SuperLUDist_LIBRARY_DIRS:FILEPATH="/usr/local/lib" \
-D SuperLUDist_INCLUDE_DIRS:FILEPATH="/usr/local/include" \
../
The error information is shown below:
Probing the environment ...
-- USE_XSDK_DEFAULTS='FALSE'
-- BUILD_SHARED_LIBS='ON'
-- CMAKE_BUILD_TYPE='Release'
-- MPI_BASE_DIR='/usr/local/Cellar/open-mpi'
-- MPI_BIN_DIR='/usr/local/Cellar/open-mpi/bin'
-- MPI_USE_COMPILER_WRAPPERS='ON'
-- Leaving current CMAKE_C_COMPILER=mpicc since it is already set!
-- Leaving current CMAKE_CXX_COMPILER=/usr/local/bin/mpicxx since it is already set!
-- Leaving current CMAKE_Fortran_COMPILER=mpif90 since it is already set!
-- MPI_EXEC='/usr/local/bin/mpiexec'
-- The C compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/local/bin/mpicc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- CMAKE_C_COMPILER_ID='AppleClang'
-- CMAKE_C_COMPILER_VERSION='12.0.0.12000032'
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /usr/local/bin/mpicxx
-- Check for working CXX compiler: /usr/local/bin/mpicxx - broken
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.20/Modules/CMakeTestCXXCompiler.cmake:59 (message):
The C++ compiler
"/usr/local/bin/mpicxx"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /Users/weiqiangguo/Downloads/Trilinos/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make -f Makefile cmTC_690b0/fast && /Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/cmTC_690b0.dir/build.make CMakeFiles/cmTC_690b0.dir/build
Building CXX object CMakeFiles/cmTC_690b0.dir/testCXXCompiler.cxx.o
/usr/local/bin/mpicxx -O3 -g -fopenmp -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk -std=gnu++14 -MD -MT CMakeFiles/cmTC_690b0.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_690b0.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_690b0.dir/testCXXCompiler.cxx.o -c /Users/weiqiangguo/Downloads/Trilinos/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
clang: error: unsupported option '-fopenmp'
make[1]: *** [CMakeFiles/cmTC_690b0.dir/testCXXCompiler.cxx.o] Error 1
make: *** [cmTC_690b0/fast] Error 2
CMake will not be able to correctly generate this project.
I really don't know how to fix it. I also tried to set gcc complier as homebrew gcc instead of clang.
Could anyone help me with this?
Xcode toolchains have no support for OpenMP.
There is no technical reason other than that they want you to use the Apple specific APIs instead (which are obviously not equivalent).
To use OpenMP, you can use LLVM Clang/libc++/libopenmp which you should be able to install through Homebrew:
brew install --with-toolchain llvm
or build from source yourself.

Building LLVM with cmake. Does -D_GLIBCXX_USE_CXX11_ABI=0 get overridden?

I try to build LLVM.
This is the way I try …
mkdir -p src/llvm-$(LLVM_VERSION).src/build
cd src/llvm-$(LLVM_VERSION).src/build && \
$(CMAKE) -GNinja \
-DCMAKE_INSTALL_PREFIX=$(BUNDLE) \
-DCMAKE_CXX_FLAGS="-D_GLIBCXX_USE_CXX11_ABI=0 -std=c++11 -static-libgcc -static-libstdc++ -l:libstdc++.a" \
-DLLVM_TARGETS_TO_BUILD="X86;NVPTX" \
-DLLVM_PARALLEL_COMPILE_JOBS=$(BUILD_JOBS) \
-DLLVM_PARALLEL_LINK_JOBS=2 \
-DLLVM_USE_CRT_RELEASE=MD \
-DLLVM_USE_CRT_DEBUG=MDd \
-DLLVM_STATIC=ON \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_BUILD_LLVM_C_DYLIB=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_UNWIND_TABLES=OFF \
-DLLVM_ENABLE_RTTI=ON \
.. && \
$(CMAKE) --build . && \
$(CMAKE) --build . --target install
You can see -D_GLIBCXX_USE_CXX11_ABI=0 in -DCMAKE_CXX_FLAGS. After LLVM finished compiling, libLLVM*.a still contain abi:cxx11 symbols.
llvm-config reveals, llvm build process completely ignored "-D_GLIBCXX_USE_CXX11_ABI=0" flag.
> ./bundle/bin/llvm-config --cxxflags
-I/home/leonard/Documents/Develop/build_as_deps/bundle/include -std=c++11 -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
Do you have an idea how to build llvm in a way that disables abi:cxx11 symbols and prevents "-D_GLIBCXX_USE_CXX11_ABI=0" to be overridden?
It looks like you're confusing the cmake options (which are specified with via -D) with C/C++ compiler macro (which are also specified via -D, but to compiler). cmake happily ignored your -D_GLIBCXX_USE_CXX11_ABI, because it's not a cmake option (and you should see a warning about this, that the value is unused by the build system).
Since you need to add extra macro definition, you'd need to change CMAKE_CXX_FLAGS cmake variable.

Compiling tensorflow: undefined reference to `clSetUserEventStatus#OPENCL_1.1'

PS: Question is at the end, the following is just background information that might help.
I'm trying to compile tensorflow, but getting this error:
bazel-out/host/bin/_solib_local/_U#local_Uconfig_Usycl_S_Ssycl_Csyclrt___Uexternal_Slocal_Uconfig_Usycl_Ssycl_Slib/libComputeCpp.so:
undefined reference to `clSetUserEventStatus#OPENCL_1.1'
By using "strace" tool, i've isolated the exact statement that's failing to be:
(
cd /home/rh/.cache/bazel/_bazel_rh/81919f16ea125cb9f08993f06569f022/execroot/tensorflow && \
exec env - PATH=/home/rh/.nvm/versions/node/v6.9.5/bin:/home/rh/perl5/bin:/home/rh/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/rh/bin:/usr/local/java/jdk1.8.0_74/bin:/home/rh/.local/bin:/home/rh/myscripts \
/usr/bin/clang++-3.6 \
-o \
bazel-out/host/bin/tensorflow/python/gen_functional_ops_py_wrappers_cc \
-Lbazel-out/host/bin/_solib_local/_U#local_Uconfig_Usycl_S_Ssycl_Csyclrt___Uexternal_Slocal_Uconfig_Usycl_Ssycl_Slib \
-Wl,-rpath,$ORIGIN/../../_solib_local/_U#local_Uconfig_Usycl_S_Ssycl_Csyclrt___Uexternal_Slocal_Uconfig_Usycl_Ssycl_Slib \
-pthread \
-Wl,-no-as-needed \
-B/usr/bin/ \
-Wl,-no-as-needed \
-Wl,--build-id=md5 \
-Wl,--hash-style=gnu \
-Wl,-S \
-Wl,#bazel-out/host/bin/tensorflow/python/gen_functional_ops_py_wrappers_cc-2.params \
-Wl,--no-undefined
)
strace also confirms that this command IS reading /usr/local/computecpp/lib/libComputeCpp.so, which contains the aforementioned clSetUserEventStatus symbol.
I verified that libComputeCpp.so contains clSetUserEventStatus by checking the output of the nm command:
nm /usr/local/computecpp/lib/libComputeCpp.so | grep clSetUserEventStatus
>> U clSetUserEventStatus##OPENCL_1.1
So here is my question: clang (and/or its linker) is reading the file that contains the symbol that it's complaining about... why is it "missing something" and complaining that it's undefined?
How can I get this compile to work?