I devellop a piece of c++ software on my OpenSUSE, which I like to test on another OpenSUSE system.
I copied the executable file on the other system, but when I am starting it I receive an error:
"error while loading shared libraries: libboost_system.so.1.61.0:
cannot open shared object file: No such file or directory"
How can I compile an independent executable without dependencies?
Eclipse does this:
17:24:41 **** Incremental Build of configuration Debug for project boostServer ****
make all
Building file: ../src/boostCom.cpp
Invoking: Cross G++ Compiler
g++ -I/opt/boost -I/usr/local/lib -O0 -g3 -Wall -c -fmessage-length=0 -isystem /opt/boost -MMD -MP -MF"src/boostCom.d" -MT"src/boostCom.o" -o "src/boostCom.o" "../src/boostCom.cpp"
Finished building: ../src/boostCom.cpp
Building file: ../src/main.cpp
Invoking: Cross G++ Compiler
g++ -I/opt/boost -I/usr/local/lib -O0 -g3 -Wall -c -fmessage-length=0 -isystem /opt/boost -MMD -MP -MF"src/main.d" -MT"src/main.o" -o "src/main.o" "../src/main.cpp"
Finished building: ../src/main.cpp
Building target: boostServer
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "boostServer" ./src/boostCom.o ./src/boostServer.o ./src/main.o -lboost_system -lboost_serialization -lboost_thread -lboost_date_time -lpthread
Finished building target: boostServer
Greets Ulf
You need to make sure you have the boost libraries installed on your system, and that the path to them is included in you LD_LIBRARY_PATH variable.
For example, if the libboost_system.so file (or symlink) is to be found at /usr/local/boost-1.56.0/lib64 on your system, then you would run the command.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/boost-1.56.0/lib64`
To find out exactly which libraries you need, you can run the command:
ldd my_binary
The output will tell you exactly which libraries are required, and which of those can't currently be resolved.
Related
I was building some Cython extensions, and have to link it against a static library (it has CUDA code in them, so have to be static):
running build_ext
building 'k3lib' extension
gcc -pthread -B /home/kelvin/anaconda3/envs/torch/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/kelvin/repos/tools/include -I/home/kelvin/anaconda3/envs/torch/include/python3.8 -c main.cpp -o build/temp.linux-x86_64-3.8/main.o -O3 -march=native
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
g++ -pthread -shared -B /home/kelvin/anaconda3/envs/torch/compiler_compat -L/home/kelvin/anaconda3/envs/torch/lib -Wl,-rpath=/home/kelvin/anaconda3/envs/torch/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.8/main.o /home/kelvin/repos/tools/include/libk2.a -L/home/kelvin/repos/tools/include -lk2 -o build/lib.linux-x86_64-3.8/k3lib.cpython-38-x86_64-linux-gnu.so -static -Wl,-Bstatic -flinker-output=exec
However, Cython's g++ compile command includes the options -shared -fPIC by default. I tried a number of options at the end of the command via this setup file (the static library is at $(LOCAL_INCLUDE)/libk2.a):
includes = [os.getenv("LOCAL_INCLUDE")]
ext_modules = [
Extension("k3lib", sources=["main.pyx"],
libraries=["k2"], include_dirs=includes, library_dirs=includes, language="c++",
extra_compile_args=["-O3", "-march=native"], extra_objects=[f"{includes[0]}/libk2.a"],
extra_link_args=['-static', '-Wl,-Bstatic', '-flinker-output=exec'])
]
#extra_objects=[f"{includes[0]}/libk2.a"]
#extra_link_args=['-static']
setup(name="k3lib", ext_modules=cythonize(ext_modules, language_level="3"))
Still, g++ thinks that I want to build a shared library, and thus the error message. Is there a way to override the -shared option? I'm planning to go into Cython's files and edit them myself, but was wondering is there a simpler way?
Context: I was following this question on SO but can't replicate their success.
I have an Eclipse C++ project which initially has first.cpp. Then second.cpp is added and should be linked to the original file. Using Eclipse building tool, I got this output:
make all
Building file: ../src/first.cpp
Invoking: GCC C++ Compiler
g++ -I/home/workspace/first/src -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/first.d" -MT"src/first.o" -o "src/first.o" "../src/first.cpp"
Finished building: ../src/first.cpp
Building file: ../src/second.cpp
Invoking: GCC C++ Compiler
g++ -I/home/workspace/first/src -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/second.d" -MT"src/second.o" -o "src/second.o" "../src/second.cpp"
Finished building: ../src/second.cpp
Building target: first
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "first" ./src/first.o ./src/second.o
Finished building target: first
How can I get Eclipse to compile this way?
g++ first.cpp second.cpp -o first
Thank you so much.
============================================================================
I am asking how to make a single binary from multiple source files, not building multiple binaries with multiple source files.
Try using CMake
As per my understanding of your question, you would need to add your source files into CMakeList.txt and then run it. You can make use of this tutorial in doing so.
I'm currently working on an R package which uses C++ code and includes external libraries (dlib, boost and an optimization library developed in the group). We're using Rcpp to integrate R and C++, but the problem is the package always fails to compile, and none of the similar questions I've found out there have worked for me.
The report generated by R CMD check is:
* installing *source* package 'IRTppExperimental' ...
** libs
*** arch - i386
c:/Rtools/mingw_32/bin/g++ -std=c++0x -I"C:/PROGRA~1/R/R-33~1.1/include" -DNDEBUG -I"C:/Users/Camilo/Documents/R/win-library/3.3/Rcpp/include" -I"d:/Compiler/gcc-4.9.3/local330/include" -I../src/include -O2 -Wall -mtune=core2 -c RcppExports.cpp -o RcppExports.o
c:/Rtools/mingw_32/bin/g++ -std=c++0x -I"C:/PROGRA~1/R/R-33~1.1/include" -DNDEBUG -I"C:/Users/Camilo/Documents/R/win-library/3.3/Rcpp/include" -I"d:/Compiler/gcc-4.9.3/local330/include" -I../src/include -O2 -Wall -mtune=core2 -c rcpp_hello_world.cpp -o rcpp_hello_world.o
c:/Rtools/mingw_32/bin/g++ -std=c++0x -I"C:/PROGRA~1/R/R-33~1.1/include" -DNDEBUG -I"C:/Users/Camilo/Documents/R/win-library/3.3/Rcpp/include" -I"d:/Compiler/gcc-4.9.3/local330/include" -I../src/include -O2 -Wall -mtune=core2 -c test_multi.cpp -o test_multi.o
c:/Rtools/mingw_32/bin/g++ -shared -s -static-libgcc -o IRTppExperimental.dll tmp.def RcppExports.o rcpp_hello_world.o test_multi.o -LC:/PROGRA~1/R/R-33~1.1/bin/i386 -lRlapack -LC:/PROGRA~1/R/R-33~1.1/bin/i386 -lRblas IRTppExperimental.dll -L../src/include -Ld:/Compiler/gcc-4.9.3/local330/lib/i386 -Ld:/Compiler/gcc-4.9.3/local330/lib -LC:/PROGRA~1/R/R-33~1.1/bin/i386 -lR
g++.exe: error: IRTppExperimental.dll: No such file or directory
no DLL was created
ERROR: compilation failed for package 'IRTppExperimental'
* removing 'C:/Users/Camilo/Documents/UNAL/MIRT/Tests/Temps/IRTppExperimental.Rcheck/IRTppExperimental'
And the Makevars/Makevars.win files are as follows:
INCFOLDER = ../src/include
PKG_LIBS += $(LAPACK_LIBS) $(BLAS_LIBS) $(FPICFLAGS) $(SHLIB)
PKG_LIBS += -L$(INCFOLDER)
PKG_CXXFLAGS+=-I$(INCFOLDER)
CXXFLAGS+="-fno-stack-protector"
CXX_STD = CXX11
Lastly, the NAMESPACE file reads:
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp,sourceCpp)
useDynLib(IRTppExperimental)
All the c++ source files are inside the src folder, including the external libraries. The package was created using the Rcpp.package.skeleton function, and used the compileAtributes function to create the RcppExports source files.
EDIT: As pointed out by Coatless, here is github link of the project: https://github.com/SICSresearch/IRTpp/tree/Uni-Multi-Merging
I am working on simple program of grayscaling using Opencl. When i compile, it gives me the following error.
make all
Building file: ../Test1.cpp
Invoking: GCC C++ Compiler 4.9.3 [armeb-linux-gnueabihf]
armeb-linux-gnueabihf-g++ -I/opt/AMDAPPSDK-3.0-0-Beta/include/ -I/opt/AMDAPPSDK-3.0-0-Beta/include/CL -I/opt/AMDAPPSDK-3.0-0-Beta/include/GL -I/opt/AMDAPPSDK-3.0-0-Beta/include/SDKUtil -I/usr/local/include -O0 -g3 -Wall -c -fmessage-length=0 -o -MM -MMD -MP -MF"Test1.d" -MT"Test1.d" -o "Test1.o" "../Test1.cpp"
cc1plus: fatal error: Test1.d: No such file or directory
compilation terminated.
make: *** [Test1.o] Error 1
Compiler command with options:-
armeb-linux-gnueabihf-g++ -I/opt/AMDAPPSDK-3.0-0-Beta/include/ -I/opt/AMDAPPSDK-3.0-0-Beta/include/CL -I/opt/AMDAPPSDK-3.0-0-Beta/include/GL -I/opt/AMDAPPSDK-3.0-0-Beta/include/SDKUtil -I/usr/local/include -O0 -g3 -Wall -c -fmessage-length=0 -o -MM
The actual command that is executed seems to have the output option -o twice. This option is supposed to be followed by a filename.
Please remove the output option -o from your command because eclipse seems to automatically add it.
when I build my cpp project in cpp...this is the oupput.
**** Build of configuration Debug for project rtbCookieServer ****
make all
Building file: ../src/rtbCookieServer.cpp
Invoking: GCC C++ Compiler
g++ -I/home/cpp/mongo-cxx-driver-v2.0/mongo -I/home/cpp/mongo-cxx-driver-v2.0 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/rtbCookieServer.d" -MT"src/rtbCookieServer.d" -o"src/rtbCookieServer.o" "../src/rtbCookieServer.cpp"
Finished building: ../src/rtbCookieServer.cpp
Building target: rtbCookieServer
Invoking: GCC C++ Linker
g++ -L/home/cpp/mongo-cxx-driver-v2.0 -lfcgi++ -lboost_system -lcgicc -lmongoclient -o"rtbCookieServer" ./src/rtbCookieServer.o
Finished building target: rtbCookieServer
W=hen I run the code..the is the error message I get.
/home/workspace/rtbCookieServer/Debug/rtbCookieServer: error while loading shared libraries: libmongoclient.so: cannot open shared object file: No such file or directory
The file is in home/cpp/mongo-cxx-driver-v2.0 so why cant if find it????
Thanks
Better than using LD_LIBRARY_PATH is to specify the runtime library search
-Wl,-rpath /home/cpp/mongo-cxx-driver-v2.0
For more information about why not using LD_LIBRARY_PATH look e.g. here.
Try the command
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/cpp/mongo-cxx-driver-v2.0
first, and try again.
The loader doesn't know the path to the library, so it has to be told where to look.