Undefined reference to `kill' - c++

I developed an application for an ARM7 embedded system in C. Now I want to compile and link it with C++ in order to use some C++ features. To do this, I am using mipsel-elf-g++ instead of mipsel-elf-gcc. I can compile my code with mipsel-elf-g++ successfully, but in linking step I get the errors:
/opt/mipsel/lib/gcc/mipsel-elf/3.4.6/../../../../mipsel-elf/lib/libc.a(lib_a-abort.o): In function```abort':
/cygdrive/d/Files/cross/mips/newlib-1.15.0/newlib/libc/stdlib/abort.c:63: undefined reference to_exit'`
/opt/mipsel/lib/gcc/mipsel-elf/3.4.6/../../../../mipsel-elf/lib/libc.a(lib_a-signalr.o): In function```_kill_r':
/cygdrive/d/Files/cross/mips/newlib-1.15.0/newlib/libc/reent/signalr.c:61: undefined reference tokill'`
collect2: ld returned 1 exit status
I searched about this issue and found that I should implement my own _exit and kill functions, so I added this codes to my project:
void _exit(int code)
{
while(1);
}
int _DEFUN (kill, (pid, sig), int pid _AND int sig)
{
if(pid == __MYPID)
_exit(sig);
return 0;
}
By adding these two functions, the undefined reference to `_exit' error is fixed, but the undefined reference to ``kill' error still exists.
What should I do to fix this issue?

Try wrapping the kill function in extern "C" { … }. And, for clarity, I suggest not using the _DEFUN macro.

I know this is an old question, but I ran against the same problem and found a solution. Add these options to your linker:
-specs=nano.specs -specs=nosys.specs -lnosys

I'm not sure, but the first thing, that I see is, that the parameter "kill" has no type...
But the only undefined reference errors I ever got were linking errors... so are there any libraries you forgot to link to?

Related

How do I interpret and resolve "dyld: Symbol not found ..." [duplicate]

After compiling, I am trying to run libuv sample program:
#include <stdio.h>
#include <uv.h>
int main() {
uv_loop_t *loop = uv_loop_new();
printf("Now quitting.\n");
uv_run(loop, UV_RUN_DEFAULT);
return 0;
}
But, when try to run, I get the following error:
**/tmp/ccHTpspB.o: In function `main':
main.c:(.text+0x9): undefined reference to `uv_loop_new'
main.c:(.text+0x28): undefined reference to `uv_run'
collect2: error: ld returned 1 exit status**
Where did I go wrong ?
PS: It doesn't work with #include "uv.h"
You need to link the libuv.a with your compiled code and the linker doesn't know where to find the compiled libuv.
To give you a better answer I would need to see you compile command but in the meantime I would strongly recommend this video where Ryan builds a sample libuv project.
The actual code he uses is a little out of date as the API has changed but I think you will find the start where he puts a project together very enlightening.
http://vimeo.com/24713213
In ubuntu I have used following command with success:
gcc sample.c -luv

Compiling Octave MXE nsi-installer with --enable-64

I am trying to compile an Octave nsi-installer for Windows with --enable-64 for large array support.
Attempt 1: Using a Linux Mint virtual machine on Windows 10:
./configure shows everything seems to be OK, and after running make, quite a lot completes. However, several minutes into "[build] default-octave", it crashes out. Looking at the log, when trying to link liboctave/.libs/liboctave-3.dll, it says:
libgnu/.libs/libgnu.a(lock.o): In function glthread_recursive_lock_init_multithreaded':
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/glthread/lock.c:289: undefined reference to__imp_pthread_mutexattr_init'
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/glthread/lock.c:292: undefined reference to __imp_pthread_mutexattr_settype'
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/glthread/lock.c:298: undefined reference to__imp_pthread_mutex_init'
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/glthread/lock.c:304: undefined reference to __imp_pthread_mutexattr_destroy'
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/glthread/lock.c:301: undefined reference to__imp_pthread_mutexattr_destroy'
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/glthread/lock.c:295: undefined reference to __imp_pthread_mutexattr_destroy'
libgnu/.libs/libgnu.a(strsignal.o): In functioninit':
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/strsignal.c:143: undefined reference to __imp_pthread_key_create'
libgnu/.libs/libgnu.a(strsignal.o): In functionfree_key_mem':
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/strsignal.c:170: undefined reference to __imp_pthread_setspecific'
libgnu/.libs/libgnu.a(strsignal.o): In functionstrsignal':
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/strsignal.c:101: undefined reference to __imp_pthread_once'
libgnu/.libs/libgnu.a(strsignal.o): In functiongetbuffer':
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/strsignal.c:186: undefined reference to __imp_pthread_getspecific'
/home/mike/temp/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libgnu/strsignal.c:195: undefined reference to__imp_pthread_setspecific'
collect2: error: ld returned 1 exit status
So, the problem is all these undefined references to '__imp_pthread_' functions in lock.c.
When I look at lock.c at those lines, the code shows:
err = pthread_mutexattr_init (&attributes);
So my main question is, why in linking is '__imp_' added to the front of the function?
If I 'nm libpthread.so', I see stuff like:
pthread_mutexattr_init.o:
0000000000000000 T __pthread_mutexattr_init
0000000000000000 T pthread_mutexattr_init
So the functions are in there, but the link doesn't see them because the '__imp_' is attached? I don't understand...
The log shows that '-pthread' is used rather than '-lpthread', which I think is what is recommended. When I look at the top of the log, it shows:
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... no
Attempt 2: Using a CentOS linux system:
Similar to above, ./configure works but a little ways into "[build] default-octave", it crashes out. Looking at the log, it says:
/u/glaucus-r1/mpjohnso/octave/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/liboctave/array/dim-vector.h: In instantiation of 'dim_vector::dim_vector(octave_idx_type, octave_idx_type, Ints ...) [with Ints = {int}; octave_idx_type = long long int]':
/u/glaucus-r1/mpjohnso/octave/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/libinterp/octave-value/ov-typeinfo.h:203:85: required from here
/u/glaucus-r1/mpjohnso/octave/mxe-octave-3fc30cd416ac/tmp-default-octave/octave-4.1.0+/liboctave/array/dim-vector.h:215:5: error: unable to deduce std::initializer_list<_Tp>&&' from '{r, c, lengths#0}'
for (const auto l: {r, c, lengths...})
^
So, there seems to be some problem with how the '{r, c, lengths...}' line is interpreted... My first try used GCC 4.4.7, but the same thing happened once upgrading to GCC 6.2.0.
Any thoughts for either?

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.

Library using libclang: linker reporting undefined reference to method

as a project of my own, I'm writing a refactoring library (so it can by used by other applications) using libclang for code analysis.
The problem is when i try to compile my program to a static library everything is okey, but when i try to link my library (using some clang code) with some demo application (just main function calling my code) the linker is reporting:
./librefactor.a(renamer.o):(.data.rel.ro+0x60): undefined reference to 'clang::ASTConsumer::HandleInterestingDecl(clang::DeclGroupRef)'
./librefactor.a(renamer.o):(.data.rel.ro+0x80): undefined reference to `clang::ASTConsumer::HandleTopLevelDeclInObjCContainer(clang::DeclGroupRef)'
./librefactor.a(renamer.o):(.data.rel.ro+0x88): undefined reference to `clang::ASTConsumer::HandleImplicitImportDecl(clang::ImportDecl*)'
collect2: error: ld returned 1 exit status
Here is a makefile I build my library with: library makefile
Here is a makefile I build an example with: library example
I commented out some parts of the code to make the error as short as possible but they are some similiar errors (undefined reference) from other part of clang i use in my project.
Problem is I don't understand why linker can't find definitions of these functions/methods. They are not pure virtual in base class so I don't need to defined them. As I see it the linker is trying to find the definition of these in my part of the code istead in clang binaries. Could somebody please explain me where I'm wrong here and explain/repair it?

Strange output when compiling c++ code. Any Ideas?

When i compile my code i get a set of errors that appear to related to the output files as in the .o file. I'm not sure why these sorts of errors would occur. Any Ideas?
/tmp/ccjPLJVV.o: In function `PubSub::~PubSub()':
Video_process.cpp:(.text._ZN6PubSubD2Ev[_ZN6PubSubD5Ev]+0x12): undefined reference to `vtable for PubSub'
/tmp/ccjPLJVV.o: In function `main':
Video_process.cpp:(.text.startup+0x34): undefined reference to `vtable for PubSub'
Video_process.cpp:(.text.startup+0xeb): undefined reference to `PubSub::run()'
/tmp/ccjPLJVV.o:(.rodata._ZTI13Video_process[typeinfo for Video_process]+0x10): undefined reference to `typeinfo for PubSub'
collect2: ld returned 1 exit status
This is essentially the output i'm getting when I attempt to compile.
It appears you have unimplemented virtual methods.
class PubSub
{
//virtual destructors, although pure
//MUST have an implementation
virtual ~PubSub() = 0 { }
/*virtual?*/ void Run(); // <--- have you implemented this one?
};
Maybe you've implemented the method, but you have not linked it. If you're using GCC, -o flag is your friend; all your class .o files must be specified when compiling the main.cpp.
this is an error message from the linker, not the compiler. The linker cannot find some symbols which are declared, but not defined, in some files it tries to link together to make (most likely) an executable. The solution is to provide the definitions, i.e. the (compiled) code with those definitions. That code may already exist and you just have to "link against it" (tell the linker to search for symbols there) or may not, in which case you have to provide it...
for example, add the file defining the implementations of class PubSub to the linker/compiler command line should help ...