I have been trying to build a library in solaris using gcc, and keep on hitting wrong ELF class: ELFCLASS64 error. I have googled and found out this is due to trying to link with a 32 bit file which compiling as a 64 bit library. But I have made sure that I build rakesh.o as a 64 bit using -m64 compiler option.
/rdcomb/run/pd/gcc/32-bit/4.4.1/bin/g++ -Wall -W -Wunreachable-code -Winline -Wshadow -Weffc++ -Wfloat-equal -Wunsafe-loop-optimizations -Wcast-qual -Wdisabled-optimization -shared -fPIC -m64 -c -DDEBUG -I../include -I/home/radha/ali/trunk/src/top//src/ -I../../../top/include -g -o Suni386/dll/rakesh.o rakesh.cpp
xmake: /home/radha/ali/trunk/src/tools/bin/Suni386/xlink -g -o Suni386/dll/rakesh -p../../../top/gtcpp/Suni386/dll -lgtcpp -lsocket -lnsl Suni386/dll/rakesh.o
ld: fatal: file Suni386/dll/rakesh.o: wrong ELF class: ELFCLASS64
ld: fatal: file processing errors. No output written to Suni386/dll/rakesh
collect2: ld returned 1 exit status
/rdcomb/run/pd/gcc/32-bit/4.4.1/bin/g++ -g -o Suni386/dll/rakesh -L../../../top/gtcpp/Suni386/dll Suni386/dll/rakesh.o -lgtcpp -lsocket -lnsl
xmake: /home/radha/ali/trunk/src/tools/bin/Suni386/xlink: error 1 (0x1)
What am I doing wrong here? Is it due to some compiler flag that using or missing?
You must provide the -m64 flag for the linker as well so it knows what type of binaries to expect.
Related
I am trying to compile a program mafTools on MacOSX using gnu make. I get the following error:
cd mafExtractor && make all
clang -std=c99 -stdlib=libstdc++ -O3 -c -O3 -Wall -Werror --pedantic -funroll-loops -DNDEBUG -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -I ../../sonLib/lib -I ../inc -I ../external src/mafExtractorAPI.c -o src/mafExtractorAPI.o.tmp -lm
This gives the error:
clang: error: -lm: 'linker' input unused [-Werror,-Wunused-command-line-argument]
make[1]: \*** [src/mafExtractorAPI.o] Error 1
make: \*** [mafExtractor.all] Error 2
I looked at similar errors but couldn't fix it. Any help will be much appreciated. Thanks!
This is the package: https://github.com/dentearl/mafTools/tree/master/mafExtractor
Everything else here compiled successfully.
This is the makefile:
https://github.com/dentearl/mafTools/blob/master/mafExtractor/Makefile
Thanks a bunch.
Your clang commaand includes the -c option which means you do not want to link and resolve external references, you just want to produce an unlinked object file.
Your -lm option says you want to link with the maths library.
Basically, the aforementioned options are incompatible - you cannot both link with the math library and not link.
TLDR; Remove -lm
I couldn't find a direct answer on Google, and since I haven't done stuff on Linux for a long time hoped to find help here. I am getting a linking error on Ubuntu when building a shared object. The linker tells me I should recompile with -fPIC even though I have set -fPIC for all source files. The output of make:
mkdir -p ../_Bin/Debug/HttpClientApi
g++ -fPIC -pedantic -Wall -Wextra -std=c++11 -c CentralServerClient.cpp -o ../_Bin/Debug/HttpClientApi/CentralServerClient.o
CentralServerClient.cpp:4:80: warning: unused parameter ‘pEventListener’ [-Wunused-parameter]
void CCentralServerClient::AddEventListener(ICentralServerClientEventListener* pEventListener)
^
CentralServerClient.cpp:29:83: warning: unused parameter ‘pEventListener’ [-Wunused-parameter]
void CCentralServerClient::RemoveEventListener(ICentralServerClientEventListener* pEventListener)
^
g++ -fPIC -pedantic -Wall -Wextra -std=c++11 -c HttpRequest.cpp -o ../_Bin/Debug/HttpClientApi/HttpRequest.o
g++ -fPIC -pedantic -Wall -Wextra -std=c++11 -c HttpResponse.cpp -o ../_Bin/Debug/HttpClientApi/HttpResponse.o
g++ -fPIC -pedantic -Wall -Wextra -std=c++11 -c IOService.cpp -o ../_Bin/Debug/HttpClientApi/IOService.o
g++ -Wl,-shared -Wl,-v -Wl,-g -o ../_Bin/Debug/HttpClientApi.so ../_Bin/Debug/HttpClientApi/CentralServerClient.o ../_Bin/Debug/HttpClientApi/HttpRequest.o ../_Bin/Debug/HttpClientApi/HttpResponse.o ../_Bin/Debug/HttpClientApi/IOService.o
collect2 version 4.9.2
/usr/bin/ld -plugin /usr/lib/gcc/x86_64-linux-gnu/4.9/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper -plugin-opt=-fresolution=/tmp/ccZ9RMHe.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/ --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o ../_Bin/Debug/HttpClientApi.so /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.9/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.9 -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.9/../../.. -shared -v -g ../_Bin/Debug/HttpClientApi/CentralServerClient.o ../_Bin/Debug/HttpClientApi/HttpRequest.o ../_Bin/Debug/HttpClientApi/HttpResponse.o ../_Bin/Debug/HttpClientApi/IOService.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.9/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crtn.o
GNU ld (GNU Binutils for Ubuntu) 2.25
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o: relocation R_X86_64_32S against `__libc_csu_fini' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:15: recipe for target '../_Bin/Debug/HttpClientApi.so' failed
make: *** [../_Bin/Debug/HttpClientApi.so] Error 1
gcc is gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13)
Any help is appreciated.
Instead of giving g++ -Wl,-shared you should give it -shared. The reason is that g++ need to know which crt1.o to use - one suitable for shared libraries (compiled with -fPIC, scrt1.o) or one which is not suitable.
When you give -shared to g++ it knows to use scrt1.o. But when you pass `-Wl,-shared', g++ doesn't know that you are building shared library - it 'thinks', you are building a normal executable (linker does know what is happening) and asks linker to link with crt1.o. Linker refuses and you have an error.
Based on this question i get error message...
collect2: fatal error: ld terminated with signal 6 [Abgebrochen]
compilation terminated.
/usr/bin/ld: ld: wcsrtombs.c:99: __wcsrtombs: Zusicherung »data.__outbuf[-1] == '\0'« nicht erfüllt.
...when trying to link a shared library but setting LC_ALL=C doesn't solve the problem in my case!
I'm on a german Linux Mint 17.3 (Cinnamon). My project gets build with CMake 2.8.4 (native repository). Compiler is g++ 5.3.1 (Ubuntu xenial repository).
Compile command for all sources looks like this:
/usr/bin/c++ -D_USE_MATH_DEFINES -Dfluag_EXPORTS -g -fPIC -I/home/youka/Schreibtisch/Projekte/FLuaG/build/src -I/usr/include/luajit-2.0 -I/usr/local/include -Wall -Wextra -pedantic -Wredundant-decls -Wunreachable-code -Wmissing-include-dirs -Wswitch-enum -Wno-missing-field-initializers -std=c++11 -mmmx -o CMakeFiles/fluag.dir/main/FLuaG.cpp.o -c /home/youka/Schreibtisch/Projekte/FLuaG/src/main/FLuaG.cpp
Link command which causes error:
/usr/bin/c++ -fPIC -g -shared -Wl,-soname,libfluag.so -o libfluag.so CMakeFiles/fluag.dir/lualibs/utf8.cpp.o CMakeFiles/fluag.dir/lualibs/mathx.cpp.o CMakeFiles/fluag.dir/lualibs/regex.cpp.o CMakeFiles/fluag.dir/lualibs/png.cpp.o CMakeFiles/fluag.dir/lualibs/geometry.cpp.o CMakeFiles/fluag.dir/lualibs/tablex.cpp.o CMakeFiles/fluag.dir/lualibs/filesystem.cpp.o CMakeFiles/fluag.dir/lualibs/tgl.cpp.o CMakeFiles/fluag.dir/lualibs/font.cpp.o CMakeFiles/fluag.dir/interfaces/vapoursynth.cpp.o CMakeFiles/fluag.dir/interfaces/public.cpp.o CMakeFiles/fluag.dir/main/FLuaG_image.cpp.o CMakeFiles/fluag.dir/main/FLuaG.cpp.o -Wl,-Bstatic -lluajit-5.1 -Wl,-Bdynamic -lGLEW /usr/local/lib/libglfw3.a -lGL -lpng -lz
Compiling this project with MinGW64 on Windows Vista works. Release or Debug build, with or without SIMD, etc. makes no difference.
The error message tells me that in file wcsrtombs.c (linked libgcc), line 99, memory comparison data.__outbuf[-1] == '\0' isn't ensured... which pretty confuses me.
After setting the system language to english, the error message suddenly made sense:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libluajit-5.1.a(ljamalg.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libluajit-5.1.a: error adding symbols: Bad value
The problem was -Wl,-Bstatic -lluajit-5.1. I linked to the .a file which was expected to be a static library by CMake. Changing to .so solved the problem.
I installed Google perftools (google-perftools 1.7-1ubuntu1), and add -lprofiler to PKG_LIBS in R, when compiling the C++ code.
library(RcppArmadillo)
library(Rcpp)
Sys.setenv("PKG_CXXFLAGS"="-fopenmp")
Sys.setenv("PKG_LIBS"="-fopenmp -lprofiler")
sourceCpp('my.cpp')
The output is:
/usr/bin/ld: cannot find -lprofiler
collect2: ld returned 1 exit status
make: *** [sourceCpp_17496.so] Error 1
g++ -I/usr/share/R/include -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I"/usr/local/lib/R/site-library/RcppArmadillo/include" -fopenmp -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c my.cpp -o my.o g++ -shared -Wl,-Bsymbolic-functions -Wl,-z,relro -o sourceCpp_17496.so my.o -llapack -lblas -lgfortran -lm -lquadmath -fopenmp -fopenmp -lprofiler -L/usr/lib/R/lib -lR
Error in sourceCpp("my.cpp") :
Error 1 occurred building shared library.
WARNING: The tools required to build C++ code for R were not found.
Please install GNU development tools including a C++ compiler.
Even if I run g++ in bash, I get the same error
$ g++ -shared -Wl,-Bsymbolic-functions -Wl,-z,relro -o sourceCpp_17496.so my.o -llapack -lblas -lgfortran -lm -lquadmath -fopenmp -fopenmp -lprofiler -L/usr/lib/R/lib -lR
/usr/bin/ld: cannot find -lprofiler
collect2: ld returned 1 exit status
I wonder why -lprofiler doesn't specify google perfotools? How can I solve the problem? Thanks!
My g++ is g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3.
Quick ones:
Do you actually have the package libgoogle-perftools-dev installed? Ie do you have shared and static libraries /usr/lib/libprofiler.* ? This is the mother of all development FAQs: you need package libfoo to run code against foo, and package libfoo-dev to compile against foo.
I have old working examples in the slides from my 'HPC with R' talks from a few years ago; those should all work as is.
when I open a terminal, switch to my project directory (which is in my home folder) and run the command "wmake" I get the error:
g++ -m32 -Dlinux -DWM_DP -Wall -Wextra -Wno-unused-parameter
-Wold-style-cast -O3 -DNoRepository -ftemplate-depth-100 -IphaseModel/lnInclude -ImultiphaseSystem/lnInclude -ImultiphaseFixedFluxPressure -IinterfacialModels/lnInclude -I/opt/openfoam221/src/transportModels -I/opt/openfoam221/src/transportModels/incompressible/lnInclude -I/opt/openfoam221/src/transportModels/interfaceProperties/lnInclude -I/opt/openfoam221/src/transportModels/incompressible/lnInclude -I/opt/openfoam221/src/transportModels/incompressible/singlePhaseTransportModel
-I/opt/openfoam221/src/turbulenceModels -I/opt/openfoam221/src/turbulenceModels/incompressible/LES/LESModel -I/opt/openfoam221/src/turbulenceModels/LES/LESdeltas/lnInclude -I/opt/openfoam221/src/finiteVolume/lnInclude -IlnInclude -I. -I/opt/openfoam221/src/OpenFOAM/lnInclude -I/opt/openfoam221/src/OSspecific/POSIX/lnInclude -fPIC -Xlinker --add-needed -Xlinker --no-as-needed Make/linuxGccDPOpt/multiphaseEulerFoam.o
-L/opt/openfoam221/platforms/linuxGccDPOpt/lib \
-lmultiphaseSystem -lcompressibleMultiPhaseModel -linterfaceProperties -lincompressibleTransportModels -lcompressibleMultiphaseEulerianInterfacialModels -lincompressibleLESModels -lincompressibleRASModels -lfiniteVolume -lOpenFOAM -ldl -lm -o /opt/openfoam221/platforms/linuxGccDPOpt/bin/multiphaseEulerFoam /usr/bin/ld: cannot open output file /opt/openfoam221/platforms/linuxGccDPOpt/bin/multiphaseEulerFoam: Permission denied collect2: ld returned 1 exit status make: * [/opt/openfoam221/platforms/linuxGccDPOpt/bin/multiphaseEulerFoam] Error 1
This error occured the first time today, yesterday everything compiled fine for me.
How can I fix this?