How to use STL on ARM Cortex-M chips? - c++

I am using STM32 dev board with MCU G++ Compiler & Linker: arm-none-eabi-g++. However, it seems not compatible with STL:
#include <list>
int main (void)
{
std::list<int> list;
list.push_back(1);
list.sort();
return 0;
}
The linker error messages:
abort.c:(.text.abort+0xa): undefined reference to `_exit'
fstatr.c:(.text._fstat_r+0x10): undefined reference to `_fstat'
signalr.c:(.text._kill_r+0x10): undefined reference to `_kill'
signalr.c:(.text._getpid_r+0x0): undefined reference to `_getpid'
writer.c:(.text._write_r+0x12): undefined reference to `_write'
closer.c:(.text._close_r+0xc): undefined reference to `_close'
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
lseekr.c:(.text._lseek_r+0x12): undefined reference to `_lseek'
readr.c:(.text._read_r+0x12): undefined reference to `_read'
The C++ STL seems dependent on operating systems. Since the micro-controller has no such things, those essential parts are missing while linking ELF.
The problem is how can I use STL on STM32 L4-series chips?

This problem can be solved by adding -specs=nosys.specs to the G++ linker. This links in a separate library with implementations for all required system functions.
See also: http://pabigot.github.io/bspacm/newlib.html

The C Standardlibrary needs some basic functions (called stubs) to work properly. Normally the OS provides these functions.
-specs= nosys.specs provides very dumb versions of these functions. In your compiler path under /share/doc/gcc-arm-none-eabi/pdf there should be a pdf libc.pdf there you will find some information how to implement those stubs yourself (chapter Systemcalls).

Related

How to link library scalapack and blacs while compilation

When compiling a fortran code, I set
FCL = mpiifort -qmkl=sequential
LLIBS += -L$(MKLROOT)/lib/intel64 -lmkl_scalapack_lp64 -lmkl_blacs_intelmpi_lp64
but when compiling code, it always links to libmkl_scalapack_lp64.so, not libmkl_scalapack_lp64.a. Then error appears,
ifort: command line warning #10006: ignoring unknown option '-qmkl=sequential'
mpi.o: In function `m_max_d_':
mpi.f90:(.text+0x4b52): undefined reference to `dcopy_'
umco.o: In function `umco_mp_umco_calc_trafo_':
umco.f90:(.text+0x8c30): undefined reference to `dgetrf_'
umco.f90:(.text+0x8c69): undefined reference to `dgetri_'
umco.f90:(.text+0x8dde): undefined reference to `dgetri_'
umco.f90:(.text+0x9911): undefined reference to `dgeev_'
umco.f90:(.text+0x9aa4): undefined reference to `dgeev_'
mathtools.f90:(.text+0x3d08): undefined reference to `zgesdd_'
In function `w90_utility_mp_utility_zgemm_new_':
utility.F90:(.text+0x3712): undefined reference to `zgemm_'
/home/app/intel/compilers_and_libraries_2020.0.166/linux/mkl/lib/intel64/libmkl_scalapack_lp64.so: undefined reference to `ssteqr_'
/home/app/intel/compilers_and_libraries_2020.0.166/linux/mkl/lib/intel64/libmkl_scalapack_lp64.so: undefined reference to `dlahqr_'
What is the correct way to link these two libraries?
It depends very much on what you are doing and compiler versions, amongst other things. As such you don't provide sufficient detail for us to answer the question. But the recommended way is to use the Intel link line advisor, which will help you find the answer by filling in all the required details into a web form. You can find this at https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html#gs.tephcr

Programming with Kinect on Ubuntu Linux

First time asking a question here so please bear with me if I'm not entirely coherent.
I've been attempting to learn how to use the OpenNI, libfreenect, and SensorKinect libraries to create some code for the kinect. However, the issue I'm running into is that I cannot seem to get the kinect setup properly so that I may actually test code and understand how everything works. The issue that has been the most problematic has been when I try to compile I receive a plethora of undefined reference errors and the compiler quits.
/tmp/ccnXAyOZ.o: In function `main':
KinectDraw.cpp:(.text+0x9a): undefined reference to `xnEnumerationErrorsAllocate'
KinectDraw.cpp:(.text+0xb6): undefined reference to `xnGetStatusString'
KinectDraw.cpp:(.text+0xfa): undefined reference to `xnInitFromXmlFileEx'
KinectDraw.cpp:(.text+0x12a): undefined reference to `xnEnumerationErrorsToString'
KinectDraw.cpp:(.text+0x148): undefined reference to `xnEnumerationErrorsFree'
KinectDraw.cpp:(.text+0x169): undefined reference to `xnGetStatusString'
KinectDraw.cpp:(.text+0x18a): undefined reference to `xnEnumerationErrorsFree'
KinectDraw.cpp:(.text+0x1a4): undefined reference to `xnEnumerationErrorsFree'
KinectDraw.cpp:(.text+0x1bf): undefined reference to `xnFindExistingRefNodeByType'
KinectDraw.cpp:(.text+0x1db): undefined reference to `xnGetStatusString'
KinectDraw.cpp:(.text+0x202): undefined reference to `xnAllocateDepthMetaData'
KinectDraw.cpp:(.text+0x227): undefined reference to `xnWaitOneUpdateAll'
KinectDraw.cpp:(.text+0x243): undefined reference to `xnGetStatusString'
KinectDraw.cpp:(.text+0x273): undefined reference to `xnGetDepthMetaData'
KinectDraw.cpp:(.text+0x2fe): undefined reference to `xnOSWasKeyboardHit'
KinectDraw.cpp:(.text+0x31a): undefined reference to `xnFreeDepthMetaData'
KinectDraw.cpp:(.text+0x329): undefined reference to `xnProductionNodeRelease'
KinectDraw.cpp:(.text+0x338): undefined reference to `xnProductionNodeRelease'
KinectDraw.cpp:(.text+0x347): undefined reference to `xnContextRelease'
/tmp/ccnXAyOZ.o: In function `xn::NodeWrapper::SetHandle(XnInternalNodeData*)':
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x39): undefined reference to `xnGetRefContextFromNodeHandle'
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x54): undefined reference to `xnContextUnregisterFromShutdown'
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x60): undefined reference to `xnContextRelease'
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x6f): undefined reference to `xnProductionNodeRelease'
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x82): undefined reference to `xnProductionNodeAddRef'
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0x91): undefined reference to `xnGetRefContextFromNodeHandle'
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0xb2): undefined reference to `xnContextRegisterForShutdown'
KinectDraw.cpp:(.text._ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData[_ZN2xn11NodeWrapper9SetHandleEP18XnInternalNodeData]+0xc1): undefined reference to `xnContextRelease'
collect2: error: ld returned 1 exit status
The command being that receives the error is g++ KinectDraw.cpp -I /usr/include/ni -I ~/KinectLibs/OpenNI/Include. I have used https://www.kdab.com/setting-up-kinect-for-programming-in-linux-part-1/ to setup the kinect. If anyone has any insight into my issue or even just a good place to start reading to figure it out I would be very appreciative. Thank you for your time and assistance!
UPDATE: Thanks to lxrec's comment, I'm fairly certain that she/he and my initial assumption were correct in that I am not linking the libraries correctly. I haven't found any documentation for Linux implementations of code that include the directories used in compiling so if anyone has insight into this I would be appreciative.
UPDATE: So I've still yet to resolve the issue (I cannot figure out how to compile the code), however thinking that my installation of OpenNI or libfreenect was bad I have resinstalled them. That however did not solve my problem. Thank you to anyone who can provide insight!
UPDATE: Below is the code that I'm having issues compiling. I haven't even tried to add anything into it yet...
#include <XnCppWrapper.h>
#include <XnStatusCodes.h>
#include <XnOS.h>
#include <math.h>
#include <XnOpenNI.h>
#include <iostream>
using namespace xn;
using namespace std;
int main()
{
cout<<"This is a test\n";
return 0;
}
OpenNI source-code should include the libs files (.so files) in its lib directory ($SOURCE_DIR/Platform/Linux/Redist/OpenNI-Bin-Dev-Linux-x64-v1.5.7.10-$YOUR_VERSION/lib). All of these files (for me there 5 files: libnimCodecs.so, libnimMockNodes.so, libnimRecorder.so, libOpenNI.jni.so and libOpenNI.so) are being copied to /usr/lib after you run the install.sh (please follow the OpenNI build/installation instructions)
Your example code needs a -lOpenNI arg to complete the compile process. So you should compile your code like this: g++ your_code.cpp -I/usr/include/ni -lOpenNI
This might already an old question, hopefully your prob are already solved, and this answer can help someone next time.

Undefined reference to "std::tr1::__detail::__prime_list" in G++4.8

I am trying to build some code with G++4.8. Operating system is FreeBSD 9.2 64-bit.
These are the errors I get:
/usr/local/lib/gcc48/include/c++/tr1/hashtable_policy.h:384: undefined reference to `std::tr1::__detail::__prime_list'
/usr/local/lib/gcc48/include/c++/bits/stl_list.h:1570: undefined reference to `std::__detail::_List_node_base::_M_unhook()'
/usr/local/lib/gcc48/include/c++/bits/stl_list.h:1562: undefined reference to `std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
I read somewhere that those functions are in libstdc++. Reading this I've added that lib at my project, but I still get those errors. I should add libstdg++ instead? Or it's something else? I don't get it.
I've got the same errors when I linked the program using cc instead of gcc because of a misconfiguration of the Makefile program.

Having trouble including boost binary_oarchive.hpp

I have boost installed and I am trying to use boost oarchive in my C++ program
I have binary_oarchive included at the top
#include <boost/archive/binary_oarchive.hpp>
But I guess a multitude of undefined reference errors such as these.
/tmp/ccqt0MAu.o: In function `boost::archive::detail::common_oarchive<boost::archive::binary_oarchive>::~common_oarchive()':
/usr/include/boost/archive/detail/common_oarchive.hpp:35: undefined reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
/tmp/ccqt0MAu.o: In function `boost::archive::binary_oarchive_impl<boost::archive::binary_oarchive, char, std::char_traits<char> >::~binary_oarchive_impl()':
/usr/include/boost/archive/binary_oarchive_impl.hpp:34: undefined reference to `boost::archive::basic_binary_oprimitive<boost::archive::binary_oarchive, char, std::char_traits<char> >::~basic_binary_oprimitive()'
I was wondering what we I could be missing.
These are linker errors and indicate that you aren't linking to the boost serialization library. The command to do this varies based on your platform, but it could be -lboost_serialization.

fortran compile error with real *8

I am trying to compile a fortran code which was last compiled in early 90's on Windows machine using Lahey Fortran . Now, I am compiling with gfortran on ubuntu 64x.
I am getting following error
$ gfortran 3RINGS.FOR
/tmp/ccjCDh8B.o:3RINGS.FOR:(.text+0xc10): undefined reference to _mmbsk0_'
/tmp/ccjCDh8B.o:3RINGS.FOR:(.text+0xc3d): undefined reference tommbsk1'
/tmp/ccjCDh8B.o:3RINGS.FOR:(.text+0xc6a): undefined reference to _mmbsi0_'
/tmp/ccjCDh8B.o:3RINGS.FOR:(.text+0xc97): undefined reference tommbsi1'
/tmp/ccjCDh8B.o:3RINGS.FOR:(.text+0xcc4): undefined reference to _mmbsk0_'
/tmp/ccjCDh8B.o:3RINGS.FOR:(.text+0xcf1): undefined reference tommbsk1'
/tmp/ccjCDh8B.o:3RINGS.FOR:(.text+0xd1e): undefined reference to _mmbsi0_'
/tmp/ccjCDh8B.o:3RINGS.FOR:(.text+0xd4b): undefined reference tommbsi1'
/tmp/ccjCDh8B.o:3RINGS.FOR:(.text+0x1182): undefined reference to _mmbsk0_'
/tmp/ccjCDh8B.o:3RINGS.FOR:(.text+0x11a5): undefined reference tommbsi0'
collect2: ld returned 1 exit status
The error is regarding following variable declaration in code
REAL*8 MMBSK0,MMBSK1,MMBSI0,MMBSI1
I will appreciate any suggestion to solve this problem and compile this code.
I will be happy to upload the entire code (263 lines) if anybody need that.
(Unrelated to your problem - note that REAL*8 is an extension to standard Fortran. The correct syntax is REAL(8), where the meaning of "8" depends on your compiler.)
The compiler thinks those MM... names declare functions, rather than variables. It usually deduces that a name references a function based on the way the name is used later in the code.
I'd guess that there's more to your program than the single source file - perhaps other source files that you need to compile and link in with your main program.