extreme newbie - hello world error - c++

Using B. Stroustrup's Programming text and the 'hello world' program about pg 50 gives errors. I have issues with the "std_lib_facilities.h" include file.
After running (as root) 'gcc hworld1.cpp' the output is -
In file included from /usr/include/c++/4.4/ext/hash_map:60,
from std_lib_facilities.h:34,
from hworld1.cpp:1:
/usr/include/c++/4.4/backward/backward_warning.h:28: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated.
/tmp/ccpwXUYx.o: In function `main':
hworld1.cpp:(.text+0x14): undefined reference to `std::cout'
hworld1.cpp:(.text+0x19): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccpwXUYx.o: In function `__static_initialization_and_destruction_0(int, int)':
hworld1.cpp:(.text+0x41): undefined reference to `std::ios_base::Init::Init()'
hworld1.cpp:(.text+0x46): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccpwXUYx.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
any suggestions how to fix the file, perhaps commenting out the hash portion?
Excited to finally have time to start, but this seems like a little larger than a 1st troubleshooting task. I have tried just using iostream as the include. I'm running this on Ubuntu 11.04. Perhaps I need to update gcc or use g++. Not sure what might ease me past this one. I tried a few things with 'using ... std' with the ... as the appropriate name I cannot recall (oops). Anyone just know the right includes.
here is the code -
#include "std_lib_facilities.h"
int main()
{
cout<<"hiya people\n";
return 0;
}

You should use g++, because gcc is C compiler (not C++).

This should fix it.
#include <iostream>
int main()
{
std::cout <<"hello world!" << std::endl;
return 0;
}
That said but the book may want you to do it certain way for a reason. Those error are link time errors, after the code has been compiler it needs linking with other procompiled code along with the header file there should be a lib file. you need to add this as a compiler parameter.
EDIT: After further inspection it seems that the missing "link" is the standard library, which isn't surprising seeing as you are using gcc rather than g++ which will automatically link with the stdlib.

Use header file iostream and not the one you are using.
Also make sure you use g++ and not gcc. Since gcc is compiler for C and g++ is for C++

Related

libACE and clang/clang++, undefined reference to `ACE_Atomic_Op<ACE_Thread_Mutex, long>

I'm compiling an application using clang++ 3.8 , libACE 6.3.3 and including the -std=c++11
But i'm having issues with inclusion of ACE Atomic_OP
including such headers:
#include <ace/ACE.h>
#include <ace/Thread.h>
#include <ace/TSS_T.h>
#include <ace/Atomic_Op.h>
i've
../game/libgame.a(WorldSocketMgr.cpp.o): In function
ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator--()':
/usr/include/ace/Atomic_Op.inl:72: undefined reference to
ACE_Atomic_Op::decrement_fn_'
../game/libgame.a(WorldSocketMgr.cpp.o): In function
ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator++()':
/usr/include/ace/Atomic_Op.inl:50: undefined reference to
ACE_Atomic_Op::increment_fn_'
../game/libgame.a(WorldSession.cpp.o): In function
ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator=(long)':
/usr/include/ace/Atomic_Op.inl:166: undefined reference to
ACE_Atomic_Op::exchange_fn_'
../game/libgame.a(WorldSession.cpp.o): In function
ACE_Atomic_Op<ACE_Thread_Mutex, long>::operator-=(long)':
/usr/include/ace/Atomic_Op.inl:114: undefined reference to
ACE_Atomic_Op::exchange_add_fn_' clang:
error: linker command failed with exit code 1 (use -v to see
invocation)
How can i solve it?
UPDATE:
i've changed
ACE_Atomic_Op<ACE_Thread_Mutex, time_t> m_timeOutTime;
in
ACE_Atomic_Op<ACE_Thread_Mutex, int> m_timeOutTime;
and
ACE_Atomic_Op<ACE_Thread_Mutex, long> m_refs;
in
ACE_Atomic_Op<ACE_Thread_Mutex, int> m_refs;
it now compiles, but i'm not sure it's a safe solution.
Update
This was caused by a bug in ACE prior to version 6.4.3. It is now fixed.
Original Answer:
A little late response, but I hope it may help anyone who finds this post in the future.
It looks like ACE has a bug (or just did not update their code). Unfortunately, the only solution for now is to hack ACE's files.
You need to find edit either config-linux.h or config-macosx-snowleopard.h - based on what you use. Then you find this chunk of oode and delete it:
# ifdef __clang__
# undef ACE_HAS_GCC_ATOMIC_BUILTINS
# endif

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.

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.

Undefined reference to `kill'

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?

Boost undefined reference during compiling

I am getting a compile error trying to compile a simple tester program from the documentation.
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xa6): undefined reference to `_imp___ZN5boost6thread4joinEv'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xb4): undefined reference to `_imp___ZN5boost6threadD1Ev'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp:(.text+0xcf): undefined reference to `_imp___ZN5boost6threadD1Ev'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp: (.text$_ZN5boost11this_thread18interruptible_waitEy[boost::this_thread::interruptible_wait( unsigned long long)]+0x4a): undefined reference to `_imp___ZN5boost11this_thread18interruptible_waitEPvNS_6detail7timeoutE'
C:\DOCUME~1\A\LOCALS~1\Temp\ccRsXzHu.o:tester.cpp: (.text$_ZN5boost6threadC1IPFvvEEET_NS_10disable_ifINS_14is_convertibleIRS4_NS_6detail13thre ad_move_tIS4_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)]+0x23): undefined reference to `_imp___ZN5boost6thread12start_threadEv'
collect2: ld returned 1 exit status
I am using mingw 4.5 and g++ 4.5.2 on windows. Boost version v1.4.8.
I hope someone can help me solve this problem.
Thanks.
It looks like you aren't linking to the boost libraries.
Boost doesn't come with windows since it isn't a standard library. You've got to download the headers and libraries, then include the headers in your project and link to the libraries at compile time. Since you're using g++, this means adding a -l line to your compile command. The -l line must be used with each specific library you want to use also, you can't just specify the boost directory.
This page will help you get started on Windows and this page will help you get started on *nix platforms.
Once you've compiled boost, then in your example, you should compile your program with
g++ -o tester.exe -Lpath/to/boost/libraries/ -lboost_thread tester.c
Make sure you've got all your libraries linked properly.
Try putting this line first if your thread library is statically defined
#define BOOST_THREAD_USE_LIB
Also, check out this thread.