I write this command:
gcc drr.c -o drr -pthread -lcdsl -L./../synch_implementations -I./../synch_implementations
And I can't understand why I get this response:
usr/bin/ld: ./../synch_implementations/libcdsl.a(cdsl_queue_list.o): relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIC
usr/bin/ld: ./../synch_implementations/libcdsl.a(cdsl_deque_list.o): relocation R_X86_64_32S against symbol `cdsl_deque_list_lock_based_pthread_push_tail' can not be used when making a PIE object; recompile with -fPIC
usr/bin/ld: ./../synch_implementations/libcdsl.a(cdsl_lock.o): relocation R_X86_64_32S against symbol `cdsl_pthread_lock_request' can not be used when making a PIE object; recompile with -fPIC
usr/bin/ld: final link failed: Nonrepresentable section on output
ollect2: error: ld returned 1 exit status
Can anyone help me understand what is wrong?
Notes:
1)I use ubuntu (via VirtualBox).
2)I am very inexperienced, so probably this is not a very bright question.
Solution:
When you compile ./../synch_implementations/libcdsl.a you need to add an extra "-fPIC" flag to produce position-independent-code (see comments above).
Note:
The PIC flag is in general needed when producing library object code since it creates objects relative to a global offset table (GOT) which subsequently allows to link library objects with your code.
Related
Currently I am trying to run my Simulink model, built with Matlab 2019b, on a server of my university, which runs on Linux CentOS 7.3.1611. If I run the model in either 'normal', or 'accelerator' mode it is successful. However, if I try to run the model in 'rapid accelerator mode' the compiler returns an error during building. The errors all contain the element of not finding the standard library:
undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>
I have searched on MATLAB Answers and stackoverflow for solutions, but none have worked for me so far. I have also asked the IT service of my university for help but they could not help me out.
One of the solutions hinted towards the compiler not being able to find the correct libraries and that the library path should be added/updated here on stack overflow. However, if I print the Library path in matlab then it seems allright:
Library path:
<matlab_root>/cefclient/sys/os/glnxa64:<matlab_root>/sys/opengl/lib/glnxa64:<matlab_root>/sys/os/glnxa64:<matlab_root>/bin/glnxa64:<matlab_root>/extern/lib/glnxa64:<matlab_root>/runtime/glnxa64:<matlab_root>/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:
<matlab_root>/sys/java/jre/glnxa64/jre/lib/amd64/server:<compiler_root>/root/usr/lib64:<compiler_root>/root/usr/lib:<compiler_root>/root/usr/lib64/dyninst
Another problem could be the compiler. At first I used a gcc 8.x compiler, but later found out that a 6.3 version is required, so that is what I am using now
Lastly I found a that a problem could be that "(...) it probably indicates that you are trying to link together object files that were compiled with different values for the _GLIBCXX_USE_CXX11_ABI macro." (from stack overflow)
The last option seems the most likely to me, however, I have not been able to solve this. I tried for instance:
set_param(model,'AccelMakeCommand','make_rtw CPP_OPTS="-D_GLIBCXX_USE_CXX11_ABI=0"')
and
set_param(model,'MakeCommand','make_rtw CPP_OPTS="-D_GLIBCXX_USE_CXX11_ABI=0"')
However, this did not help.
If anyone has a tip that could help me out, that would be great. I have added parts of the console output and the error message were it goes wrong down below for extra info.
Kind regards,
Nathan
Console output messages:
( A lot of other stuff)
### Processing Template Makefile: <matlab_root>/rtw/c/raccel/raccel_unix.tmf
### <model_folder>/slprj/raccel/MyModel/MyModel.mk which is generated from <matlab_root>/rtw/c/raccel/raccel_unix.tmf is up to date
### Building MyModel: <matlab_root>/bin/glnxa64/gmake -f MyModel.mk RSIM_SOLVER_SELECTION=2 PCMATLABROOT="<matlab_root>" EXTMODE_STATIC_ALLOC=0 EXTMODE_STATIC_ALLOC_SIZE=1000000 EXTMODE_TRANSPORT=0 TMW_EXTMODE_TESTING=0 COMBINE_OUTPUT_UPDATE_FCNS=0 INCLUDE_MDL_TERMINATE_FCN=1 MULTI_INSTANCE_CODE=0 MODELREF_TARGET_TYPE=NONE ISPROTECTINGMODEL=NOTPROTECTING OPTS="-DTGT
an error.
Error message:
( A lot of stuff)
g++ -Wl,-rpath,<matlab_root>/sys/os/glnxa64
-L<matlab_root>/sys/os/glnxa64 -o MyModel
MyModel_c233cdf9_1.o MyModel_c233cdf9_1_create.o
MyModel_c233cdf9_1_setParameters.o
MyModel_c233cdf9_1_asserts.o
MyModel_c233cdf9_1_deriv.o
MyModel_c233cdf9_1_checkDynamics.o
MyModel_c233cdf9_1_output.o
MyModel_c233cdf9_1_assembly.o
MyModel_c233cdf9_1_computeConstraintError.o
MyModel_c233cdf9_1_mode_zero_crossings.o
MyModel_c233cdf9_1_geometries.o
MyModel_c233cdf9_1_gateway.o pm_printf.o rt_logging.o
rt_backsubrr_dbl.o rt_forwardsubrr_dbl.o rt_lu_real.o rt_matrixlib_dbl.o
MyModel.o MyModel_capi.o
MyModel_data.o MyModel_tgtconn.o rtGetInf.o
rtGetNaN.o rt_nonfinite.o rt_logging_mmi.o rtw_modelmap_utils.o
raccel_main_new.o raccel_sup.o raccel_mat.o simulink_solver_api.o
raccel_utils.o common_utils.o ext_svr.o updown.o ext_work.o
rtiostream_interface.o rtiostream_tcpip.o rtiostream_utils.o \
<matlab_root>/toolbox/physmod/sm/ssci/lib/glnxa64/sm_ssci_std.a
<matlab_root>/toolbox/physmod/sm/core/lib/glnxa64/sm_std.a
<matlab_root>/toolbox/physmod/pm_math/lib/glnxa64/pm_math_std.a
<matlab_root>/toolbox/physmod/simscape/engine/sli/lib/glnxa64/ssc_sli_std.a
<matlab_root>/toolbox/physmod/simscape/engine/core/lib/glnxa64/ssc_core_std.a
<matlab_root>/toolbox/physmod/network_engine/lib/glnxa64/ne_std.a
<matlab_root>/toolbox/physmod/common/math/core/lib/glnxa64/mc_std.a
<matlab_root>/toolbox/physmod/common/external/library/lib/glnxa64/ex_std.a
<matlab_root>/toolbox/physmod/common/foundation/core/lib/glnxa64/pm_std.a
<matlab_root>/bin/glnxa64/libmwcoder_target_services.so
<matlab_root>/bin/glnxa64/libmwcoder_ParamTuningTgtAppSvc.so
-L"<matlab_root>/bin/glnxa64" -lmwipp -lut -lmx -lmex
-lmat -lmwmathutil -lmwslexec_simbridge -lmwsl_fileio
-lmwsigstream -lmwsl_AsyncioQueue -lmwsl_services
-lmwsdi_raccel -lmwi18n -lmwsl_simtarget_instrumentation
-lfixedpoint -lmwslexec_simlog -lm -lpthread -ldl
<matlab_root>/bin/glnxa64/libQt5WebKit.so.5: undefined reference to
`std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::_S_copy(char*, char const*, unsigned
long)#GLIBCXX_3.4.21'
<matlab_root>/bin/glnxa64/libmwboost_locale.so.1.65.1: undefined
reference to `std::__cxx11::numpunct<char>::id#GLIBCXX_3.4.21'
<matlab_root>/bin/glnxa64/libmwboost_serialization.so.1.65.1:
undefined reference to `typeinfo for
std::__codecvt_utf8_base<wchar_t>#GLIBCXX_3.4.21'
<matlab_root>/bin/glnxa64/libut.so: undefined reference to
`std::__cxx11::basic_string<char, std::char_traits<char>,
std::allocator<char> >::assign(char const*)#GLIBCXX_3.4.21'
<matlab_root>/bin/glnxa64/libut.so: undefined reference to
`std::logic_error::logic_error(char const*)#GLIBCXX_3.4.21'
<matlab_root>/bin/glnxa64/libmwcoder_target_services.so: undefined
reference to `typeinfo for std::_V2::error_category#GLIBCXX_3.4.21'
<matlab_root>/bin/glnxa64/libmwboost_locale.so.1.65.1: undefined
reference to `typeinfo for std::__cxx11::moneypunct_byname<char,
false>#GLIBCXX_3.4.21'
( A lot of stuff)
collect2: error: ld returned 1 exit status
gmake: *** [MyModel] Error 1
Error(s) encountered while building "MyModel" - Show complete
stack trace
}
this is a bit of a long shot but:
I'm following this guide: https://www.tutorialspoint.com/postgresql/postgresql_c_cpp.htm
But when running ./configure I get the following error:
(previous checking lines omitted for brevity)
checking for main in -lpq... yes
checking for PQexec in -lpq... yes
checking for correct C++ linkage of basic libpq functions...
sed: character class syntax is [[:space:]], not [:space:]
configure: error:
Linking a call to libpq failed in C++, even though it succeeded in C. If your
C and C++ compilers are very different beasts, this may mean that we do not have
the right options for linking with it after all.
Read the config.log file for more detailed information. Look for the last error
message, which may be several pages up from the end of the file.
And the configure.log file looks like this:
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by libpqxx configure 4.0, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ ./configure
## --------- ##
## Platform. ##
## --------- ##
(some lines omitted)
configure:3039: g++ -V >&5
g++: error: unrecognized command line option '-V'
g++: fatal error: no input files
compilation terminated.
configure:3050: $? = 1
configure:3039: g++ -qversion >&5
g++: error: unrecognized command line option '-qversion'; did you mean '--version'?
g++: fatal error: no input files
compilation terminated.
(some lines omitted)
configure:7629: gcc -E conftest.c
conftest.c:11:10: fatal error: ac_nonexistent.h: No such file or directory
#include <ac_nonexistent.h>
^~~~~~~~~~~~~~~~~~
compilation terminated.
(some lines omitted)
configure:8319: gcc -c -g -O2 -fno-rtti -fno-exceptions conftest.c >&5
cc1: warning: command line option '-fno-rtti' is valid for C++/ObjC++ but not for C
(some lines omitted)
configure:16424: g++ -o conftest -g -O2 -L/usr/lib/x86_64-linux-gnu conftest.cpp >&5
/tmp/ccfFBf4K.o: In function `main':
/home/peter/libpqxx-4.0/conftest.cpp:44: undefined reference to `PQexec'
collect2: error: ld returned 1 exit status
(some liens omitted)
I don't believe I have any packages missing. I have the newest version of g++, psql and libpqxx installed.
I have updated and upgraded all packages on my system.
I have crawled the web for solutions to this error, but I have no clue what is wrong.
Do you have an idea where I can go from here?
There hasn't been a tarball release of libpqxx at the old spot in a long time, so the tutorial you used with its wget command to download the tarball is very outdated.
The issue you encountered looks related to this issue and appears to have been fixed in this commit:
commit 85e9336740475be25ed19924cca0961f7d844c4b
Author: Jeroen Vermeulen <jtvjtv#gmail.com>
Date: Thu Jun 1 11:39:08 2017 +0700
Fix #13: not linking to libpq.
This was that annoying interaction between autoconf, m4, GNU sed syntax,
and the shell which broke the "remove redundant -lpq options" code in
the configure script.
Solution: forget about GNU sed's "[[:space:]]" syntax, and just look for
a literal space. There aren't going to be any tabs, newlines,
non-breaking spaces, etc. there in even a moderately sane world.
I'm compiling some C++ functionality into Matlab by using Mex compilation to produce a .mexa64 binary.
Honestly I don't know much about the guts of the symbols created in the .mexa64 binary and how it allows Matlab to call C++, but I'm starting with a simple question related to the error I eventually get when the command mex calls ld.
The ld error is:
/usr/bin/ld.real: duplicate version tag `MEX'
The question is, what does this ld error "duplicate version tag" mean? Other appreciated perspectives are: what does it mean in relation to the Matlab compilation I'm trying to do specifically; and where can I find comprehensive ld error message documentation?
This latter point, the comprehensive ld documentation, I've found particularly hard to find. The manual page for ld didn't seem to be helpful for this.
requested to post the mex config file:
<config Name="g++" ShortName="g++" Manufacturer="GNU" Version="" Language="C++" Priority="A" Location="$GCC_DIR">
<Details CompilerExecutable="$CXX" CompilerDefines="$DEFINES" CompilerFlags="$CXXFLAGS" OptimizationFlags="$CXXOPTIMFLAGS" DebugFlags="$CXXDEBUGFLAGS" IncludeFlags="$INCLUDE" LinkerLibraries="$LINKLIBS" LinkerOptimizationFlags="$LDOPTIMFLAGS" LinkerDebugFlags="$LDDEBUGFLAGS" CompilerDefineFormatter="-D%s" LinkerLibrarySwitchFormatter="-l%s" LinkerPathFormatter="-L%s"/>
<vars CMDLINE1="$CXX -c $DEFINES $INCLUDE $CXXFLAGS $OPTIM $SRC -o $OBJ" CMDLINE2="$LDXX $LDFLAGS $LDTYPE $LINKOPTIM $LINKEXPORT $OBJS $CXXLIBS $LINKLIBS -o $EXE" CMDLINE3="rm -f $OBJ" CXX="$GCC" DEFINES="-D_GNU_SOURCE $MATLABMEX" MATLABMEX="-DMATLAB_MEX_FILE " CXXFLAGS="-ansi -fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11" INCLUDE="-I"$MATLABROOT/extern/include" -I"$MATLABROOT/simulink/include"" CXXOPTIMFLAGS="-O -DNDEBUG" CXXDEBUGFLAGS="-g" LDXX="$CXX" LDFLAGS="-pthread -Wl,--no-undefined " LDTYPE="-shared" LINKEXPORT="-Wl,--version-script,"$MATLABROOT/extern/lib/$ARCH/mexFunction.map"" LINKLIBS="-Wl,-rpath-link,$MATLABROOT/bin/$ARCH -L"$MATLABROOT/bin/$ARCH" -lmx -lmex -lmat -lm -lstdc++" LDOPTIMFLAGS="-O" LDDEBUGFLAGS="-g" OBJEXT=".o" LDEXT=".mexa64"> </vars>
<client>
<engine LINKLIBS="$LINKLIBS -leng" LINKEXPORT="" LDEXT="" LDTYPE=""/>
<mbuild DEFINES="-D_GNU_SOURCE $MATLABMEX -DUNIX -DX11 -DGLNXA64 -DGCC" CXXFLAGS="-ansi -pthread -std=c++11" INCLUDE="$INCLUDE -I"$MATLABROOT/extern/include/cpp"" LDFLAGS="-pthread -Wl,-rpath-link,$MATLABROOT/bin/$ARCH" LINKEXPORT="" LINKLIBS="-L"$MATLABROOT/runtime/$ARCH" -lm -lmwmclmcrrt" LDEXT="" MATLABMEX="" LDTYPE=""/>
</client>
<locationFinder>
<GCC>
<cmdReturns name="which g++"/>
</GCC>
<CPPLIB_DIR>
<cmdReturns name="g++ -print-file-name=libstdc++.so" diagnostic="GCC appears to be installed, but supporting C++ libraries were not found. You must first install the gcc-c++ packge, or similiar, to complete this action."/>
</CPPLIB_DIR>
</locationFinder>
</config>
I have a code by name mexCodeCuda.cu which uses dynamic parallelism. In the matlab interface, when I try to execute the following commands, I get the following error :
system('nvcc --compile mexCodeCuda.cu -o mexCodeCuda.o --compiler-options -fPIC -m64 -rdc=true -gencode arch=compute_35,code=sm_35 -O3 -lineinfo -use_fast_math -lcudadevrt -I/cm/shared/apps/MATLAB/extern/include')
system('nvcc -arch=sm_35 -dlink mexCodeCuda.o -o dlink.o')
eval('mex mexCodeCuda.o dlink.o -L'CUDA_LIB_PATH '-lcudart')
It gives the following error :
Error using mex
/usr/bin/ld: dlink.o: relocation R_X86_64_32S against `__nv_module_id' can
not be used when making a shared object; recompile with -fPIC
dlink.o: could not read symbols: Bad value
collect2: error: ld returned 1 exit status
Can anyone help me ?
Thanks in advance...
A few changes:
Add -fPIC to the second nvcc command (using --compiler-options, just as you did with the first nvcc).
Specify the cudadevrt runtime option on the mex command (-lcudadevrt), just as you have with the first nvcc call.
And you may need to add -fPIC to the mex linking via LDCXXFLAGS or LDFLAGS. Not sure.
I inherited a project (lucky me!) which relies on a static library. Trying to build the static lib, I get this error:
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC
It is followed by these two lines, which I do understand, but this appears to be a separate problem (missing file.)
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool: can't locate file for: -lFlurryWithLocation
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool: file: -lFlurryWithLocation is not an object file (not allowed in a library)
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/libtool failed with exit code 1
Am I wrong, and it's all related? Will the 1st line error go away if I fix the missing file part?
Either way, what does the -dynamic not specified part of message mean?
Thanks!
Olie, your original hunch was correct. There is no relationship between the two messages. The first message '-dynamic not specified the following flags are invalid: -ObjC' is just a warning. The -objC option is not needed for building a static library.