I've installed ffmpeg using vcpkg install ffmpeg
When I include the dependency in my cmake project, like so:
find_path(AVCODEC_INCLUDE_DIR libavcodec/avcodec.h)
find_library(AVCODEC_LIBRARY avcodec)
find_path(AVFORMAT_INCLUDE_DIR libavformat/avformat.h)
find_library(AVFORMAT_LIBRARY avformat)
find_path(AVUTIL_INCLUDE_DIR libavutil/avutil.h)
find_library(AVUTIL_LIBRARY avutil)
find_path(AVDEVICE_INCLUDE_DIR libavdevice/avdevice.h)
find_library(AVDEVICE_LIBRARY avdevice)
target_link_libraries(${TARGET_NAME} PRIVATE
${AVCODEC_LIBRARY} ${AVFORMAT_LIBRARY} ${AVUTIL_LIBRARY} ${AVDEVICE_LIBRARY}
)
My windows build works fine, however, on linux, I get the error:
[29/29] Linking CXX shared library libjni.so
2021-11-14T12:38:02.510164800Z FAILED: libjni.so
2021-11-14T12:38:02.510171600Z : && /usr/bin/g++-11 -fPIC -O3 -DNDEBUG -shared -Wl,-soname,libjni.so -o libjni.so CMakeFiles/jni.dir/src/jni.cpp.o CMakeFiles/jni.dir/src/core/audio.cpp.o CMakeFiles/jni.dir/src/core/files.cpp.o CMakeFiles/jni.dir/src/core/fs/file_utils.cpp.o CMakeFiles/jni.dir/src/core/spectrogram.cpp.o CMakeFiles/jni.dir/src/core/utils.cpp.o -L/usr/lib/gcc/x86_64-linux-gnu/10 -Wl,-rpath,/root/build/Release/_deps/fmt-build /root/vcpkg/installed/x64-linux/lib/libfftw3f.a _deps/fmt-build/libfmt.so.8.0.1 _deps/xxhash-build/libxxhash.a /root/vcpkg/installed/x64-linux/lib/libavcodec.a /root/vcpkg/installed/x64-linux/lib/libavformat.a /root/vcpkg/installed/x64-linux/lib/libavutil.a /root/vcpkg/installed/x64-linux/lib/libavdevice.a _deps/kistream_proto_cpp-build/libgenerated_srcs.a -lm -Wl,--as-needed /root/vcpkg/installed/x64-linux/lib/libprotobuf.a -lpthread && :
2021-11-14T12:38:02.510185200Z /usr/bin/ld: /root/vcpkg/installed/x64-linux/lib/libavcodec.a(h264_intrapred_10bit.o): warning: relocation against `ff_pw_512' in read-only section `.text'
2021-11-14T12:38:02.510187600Z /usr/bin/ld: /root/vcpkg/installed/x64-linux/lib/libavcodec.a(vc1dsp_mmx.o): relocation R_X86_64_PC32 against symbol `ff_pw_9' can not be used when making a shared object; recompile with -fPIC
I think, your issue is related to Position Independent Code. It can be resolved if you compile by giving -fPIC option in vcpkg.
You can look at this github issue of vcpkg repo. They gave an example that how can add compiler option to vcpkg`s port CMake file.
Related
I'm writing a dynamic library that's loaded at runtime as a plugin. At runtime, the library fails to load with the following message:
dlerror:/path/to/so: undefined symbol: fstat
The dynamic library consists of a bunch of static libraries linked together, including libsodium. I've tracked down libsodium as the only place that fstat() is used in the library.
As I understand it, fstat() should be part of libc, and should not require additional libraries to be installed. What am I missing?
EDIT1:
I've found some additional information about how linking to fstat() is different than most functions, but I'm not sure exactly how it applies to my situation. I am compiling/linking libsodium with the provided makefiles for their distribution, and the dynamic library is being compiled with the compiler driver as recommended in that answer.
EDIT2: here's the linker command, generated by CMake:
/usr/bin/c++ -fPIC -O3 -DNDEBUG -rdynamic -nodefaultlibs -undefined_warning -fPIC -fvisibility=hidden -shared -Wl,-soname,lin.xpl -o src/xplane_plugin/lin.xpl src/path/to/object/file1.cpp.o src/path/to/object/file2.cpp.o src/plugin/libplugin.a /usr/local/lib/libpng16.a -lz src/plenty/of/dependencies.a lib/glew/libglew.a src/another/library.a /usr/local/lib/libsodium.a /usr/lib/x86_64-linux-gnu/libcurl.so lib/json11/libjson11.a -lpthread deps/some/library.a /usr/local/lib/libzip.a -lbz2 -llzma -lssl -lcrypto -lstdc++fs -lz
I am developing an application in Linux, which requires static library of curl.Only http and https support is required.I have tried many ways like -Wl,-Bstatic -libcurl , linking to libcurl.a etc. Most alarming is that, I haven't seen anybody who has been successful in doing so, in linux.Only thing I found was in Windows,
Linking project with statically build curl
But in linux , almost all answers are like following.
Static linking libcurl using c.
Is it so? Whether it is impossible to make standalone library of curl in linux ?
Following are my build options and results
-Wl,-Bstatic -pthread -lcrypto -Wl,-Bdynamic -ldl -lcurl
No error !!!!!
-Wl,-Bstatic -pthread -lcrypto -ldl -lcurl
errors ... cannot find -lgcc_s
-static -pthread -lcrypto -ldl -lcurl
lot of errors starting with undefined reference "idn_free"
4.-static -pthread -lcrypto -ldl -ldn -lcurl
no change.... lot of errors starting with undefined reference "idn_free"
-static /usr/lib/i386-linux-gnu/libpthread.a /usr/lib/i386-linux-gnu/libcrypto.a /usr/lib/i386-linux-gnu/libdl.a /usr/lib/i386-linux-gnu/libidn.a /usr/lib/i386-linux-gnu/libcurl.a
no change.... lot of errors starting with undefined reference "idn_free"
I'm trying to run the following makefile for JNI in Eclipse on Ubuntu 14.04
CLASS_PATH = ../bin
vpath %.class $(CLASS_PATH)
all : libSend.so
libSend.so : Send.o
gcc -fPIC -shared -o $# $<
Send.o : Send.c Send.h
gcc -fPIC -I"/usr/lib/jvm/java-8-openjdk-amd64/include" -I"/usr/lib/jvm/java-8-openjdk-amd64/include/linux" -c $< -o $#
Send.h : Send.class
javah -classpath $(CLASS_PATH) $*
clean :
rm Send.h Send.o libSend.so
When I try to build this makefile. I'm getting the follwing error:
make all
javah -classpath ../bin Send
gcc -fPIC -shared -o libSend.so Send.o
/usr/bin/ld: Send.o: relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
Send.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [libSend.so] Error 1
Please help me to resolve this issue.
My code worked when I followed #AndrewHenle's suggestion:
make clean; make all
Thank you #AndrewHenle.
I need some help with a linker error I get during installation of an Rcpp package on a linux system where I don't have admin rights. In a nutshell, I get this error:
relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
I have a file solve.cpp that uses external library interp2d, which in turn has a GSL dependency. I specify my dependencies via [[Rcpp::depends(RcppArmadillo,RcppGSL)]] and in the DESCRIPTION. My Makevars is like the one from the RcppGSL package, with the addition of the linterp2d flag:
PKG_CPPFLAGS = -W $(GSL_CFLAGS) $(LOCAL_INCLUDE)
PKG_LIBS += $(GSL_LIBS) $(LOCAL_LIBS) -linterp2d $(RCPP_LDFLAGS)
where I define the environement variables
export LOCAL_INCLUDE="-I/data/uctpfos/local/include/"
export LOCAL_LIBS="-L/data/uctpfos/local/lib/"
on the system.
I do R CMD INSTALL bkPackage and see:
g++ -I/cm/shared/apps/R/3.0.1/lib64/R/include -DNDEBUG -W -I/cm/shared/apps/gsl/1.15/include -I/data/uctpfos/local/include -fPIC -I/usr/local/include -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/Rcpp/include" -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/RcppArmadillo/include" -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/RcppGSL/include" -fpic -O3 -fPIC -c RcppExports.cpp -o RcppExports.o
g++ -I/cm/shared/apps/R/3.0.1/lib64/R/include -DNDEBUG -W -I/cm/shared/apps/gsl/1.15/include -I/data/uctpfos/local/include -fPIC -I/usr/local/include -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/Rcpp/include" -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/RcppArmadillo/include" -I"/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/RcppGSL/include" -fpic -O3 -fPIC -c solve.cpp -o solve.o
The problems appears after that in the linking step:
g++ -shared -L/usr/local/lib64 -o bkPackage.so RcppExports.o solve.o -L/cm/shared/apps/gsl/1.15/lib -lgsl -lgslcblas -lm -L/data/uctpfos/local/lib -linterp2d -L/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/Rcpp/lib -lRcpp -Wl,-rpath,/data/uctpfos/R/x86_64-unknown-linux-gnu-library/3.0/Rcpp/lib
The error follows as:
/usr/bin/ld: /data/uctpfos/local/lib/libinterp2d.a(interp2d_spline.c.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/data/uctpfos/local/lib/libinterp2d.a: could not read symbols: Bad value
As you can see I compiled this with -fPIC, so that can't be it.
It's complaining that libinterp2d.a was not compiled with -fPIC; are you sure that was also compiled with -fPIC on?
Also, it seems you both have -fpic and -fPIC in your flags; you probably just want -fPIC. I think R actually ensures that's on by default.
I'm trying to install GHC with -fPIC support in Fedora.
I've grabbed a source tarball since it seems no binary one has this.
In Build.mk i've changed the quick build type to
ifeq "$(BuildFlavour)" "quick"
SRC_HC_OPTS = -H64m -O0 -fasm -fPIC
GhcStage1HcOpts = -O -fasm -fPIC
GhcStage2HcOpts = -O0 -fasm -fPIC
GhcLibHcOpts = -O -fasm -fPIC
SplitObjs = NO
HADDOCK_DOCS = NO
BUILD_DOCBOOK_HTML = NO
BUILD_DOCBOOK_PS = NO
BUILD_DOCBOOK_PDF = NO
endif
unfortunately, when compiling i still get the ld error
ghc -fglasgow-exts --make -shared -oHs2lib.a /tmp/Hs2lib924498/Hs2lib.hs dllmain.o -static -fno-warn-deprecated-flags -O2 -package ghc -package Hs2lib -i/home/phyx/Documents/Haskell/Hs2lib -optl-Wl,-s -funfolding-use-threshold=16 -optc-O3 -optc-ffast-math
Linking a.out ...
/usr/bin/ld: /tmp/Hs2lib924498/Hs2lib.o: relocation R_X86_64_32 against `ghczmprim_GHCziUnit_Z0T_closure' can not be used when making a shared object; recompile with -fPIC
/tmp/Hs2lib924498/Hs2lib.o: could not read symbols: Bad value
So it seems that GHC-prim still isn't compiled with -FPIC
I've also told cabal to build any packages with -fPIC and shared.
Anyone have any ideas?
EDIT:
Thanks to dcouts I've been able to make some progress. But now i'm at the point where I thnk libffi isn't compiled with -fPIC. I've edited the makefile(.in) for it but so far, no luck.
The new command is:
ghc -fPIC -shared dllmain.o Hs2lib.o /usr/local/lib/ghc-7.0.3/libHSrts.a -o Hs2lib.so
where dllmain.c and Hs2lib.hs have both been compiled using -fPIC.
The error I get is:
/usr/bin/ld: /usr/local/lib/ghc-7.0.3/libHSffi.a(closures.o): relocation R_X86_64_32
against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/ghc-7.0.3/libHSffi.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
After you see this error, do the following:
cd /tmp/Hs2lib924498/
ghc -fglasgow-exts --make -shared -oHs2lib.a /tmp/Hs2lib924498/Hs2lib.hs dllmain.o -static -fno-warn-deprecated-flags -fPIC -O2 -package ghc -package Hs2lib -i/home/phyx/Documents/Haskell/Hs2lib -optl-Wl,-s -funfolding-use-threshold=16 -optc-O3 -optc-ffast-math
Note I added -fPIC to the failed ghc command.
Once the command succeeds, continue the compilation from within the tmp directory without cleaning already compiled files. It should skip them and continue where it ended.
There's an FAQ entry on this topic on the Haskell Stack page.
It basically says the problem is environment related and sometimes non-deterministic.
The issue may be related to the use of hardening flags in some cases, specifically those related to producing position independent executables (PIE).
There's also a work around suggestion for Arch Linux:
On Arch Linux, installing the ncurses5-compat-libs package from AUR resolves this issue.