Undefined Reference when Compiling Kobuki ROS examples from source - c++

I have been trying to compile the kobuki_keyop example in ROS Indigo from source on Ubuntu 14.04, I basically wrote a simple cpp file like the following:
#include "/opt/ros/indigo/include/kobuki_keyop/include/keyop_core/keyop_core.hpp"
using namespace keyop_core;
int main()
{
KeyOpCore keyy;
}
then I compiled with the following:
g++ test.cpp -L/opt/ros/indigo/lib/kobuki_keyop -o test
but it keeps giving me the same old holy grail of cpp errors:
/tmp/ccsh6f87.o: In function `main':
test.cpp:(.text+0x25): undefined reference to `keyop_core::KeyOpCore::KeyOpCore()'
test.cpp:(.text+0x34): undefined reference to `keyop_core::KeyOpCore::~KeyOpCore()'
Update:
as was pointed out by #Danh, there are solutions in the following link:
What is an undefined reference/unresolved external symbol error and how do I fix it?
however, my question is ROS related, I did not write the header files that might cause the problem, and I can't poke around all of the interlinked ones hoping to find a needle in the haystack, I was just hoping someone with background in ROS who had a similar problem might pick this up and point me to their solution.
Thank You.

Related

Undefined reference to linker error when using namespaces in headers in c++ [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 1 year ago.
I've read through all similar "Undefined reference to" threads I could find but couldn't find a solution. Most of the other threads also involved classes which I don't plan to use for this. The program compiles executes normally if I define the function within the header instead of using an external .cc file. I feel like I'm missing something simple here.
This is the simplest test I could put together that recreates the issue I'm having.
Compiler: g++ (Debian 8.3.0-6) 8.3.0
hntest.h
namespace hntest
{
void pewpew();
}
hntest.cc
#include <iostream>
#include "hntest.h"
namespace hntest
{
void pewpew()
{
std::cout << "pew pew pew!!!" << std::endl;
}
}
hntestmain.cc
#include "hntest.h"
int main(int argc, char* argv[])
{
hntest::pewpew();
}
I'm attempting to compile with:
g++ -lstdc++ hntestmain.cc -o hntestmain
And I get the following linker error:
hntestmain.cc:(.text+0x10): undefined reference to `hntest::pewpew()'
collect2: error: ld returned 1 exit status
I have tried reading through the code of a couple popular C++ libraries as well as some of my own older C (not ++) code and makefiles but haven't been able to find my error. I'm admittedly both and amateur an a bit rusty.
What am I missing?
You are not actually compiling the cpp file that has the definition of pewpew.
Try:
g++ -lstdc++ hntestmain.cc hntest.cc -o hntestmain
The compiler needs to know about all the source files. The header file is dealt with during pre-process and knows to look in the same folder. You can imagine that if you have more files, say 10, 100 or 10000, this would become impossible to manage by using command line. That is why people created build systems like make, cmake and bazel.
For much greater detail see the answer here which is specific for your case of linker error.

Resolving undefined dependencies in C++

Hey guys I'm really new to C++ so please be patient. I think I have a really easy problem to solve for you. I need to compile a C++ file in a virtual machine for university.
My Input:
g++ decrypt_me.cpp
I get the following errors:
undefined reference to `SHA1_Init'
undefined reference to `SHA1_Update'
undefined reference to `SHA1_Final'
I know this has something to do with putting -lssl with it, but non of my trys worked so far.
Thank you in advance!

Trying to run separated classes in vs code in c++ [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 months ago.
I am new to vs code, after previously using atom a little bit. I am working on c++ with a program that has some classes in separated files. I have already installed the c/c++ extension, but I am facing a problem. When I try to run the program with all it's files included, it shows me the following error:
main.cpp:(.text+0x1f): undefined reference to `Car::sayHello()'
collect2: error: ld returned 1 exit status.
the code is pretty basic.
#include <iostream>
#include "Car.h"
using namespace std;
int main(){
Car c;
c.sayHello();
cout << "Hello world";
return 0;
}
From what I remember from atom, selecting all the files and running them would solve the problem, which I think is the same as running the following command in the terminal:
g++ Car.cpp Car.h main.cpp -o Classes
I have tried these in vs code and the problem seems to appear again. Help is much appreciated.
So if somebody else might have the same problem as me in the future. The problem was that I had declared the constructor and the destructor in the header file, but I hadn't defined them in the .cpp file, after doing that the program seems to be running well. Also as Fred mentioned Car.h is redundant to be mentioned in compilation process, but anyways the program will compile successfully, even if it is used.
So I had the same problem but I figured it out thanks to this link. Follow the instructions and test it out and it should work. There are also other ways to solve this problem based on your preference that are shown on this website. I did notice, however, that once you add multiple folders to your workspace, compiling whatever main.exe file you want becomes difficult since you use the arg ${workspaceFolder}\\*.cpp to compile all the .cpp files in your workspace folder. One way to solve that is to create multiple workspaces, but if anyone knows a more efficient way to do this, please let me know.
you can install fleeox in VS code that will help

RcppGSL Windows installation trouble

I'm trying to install RcppGSL as presented in
Linking GSL library to RcppGSL on Windows machine
after copping the library as presented in the link above to C:/local323
and moving all the files in x64 up one directory into into LIB_GSL/lib as presented in the link. I used the following code.
library(Rcpp)
Sys.setenv("LIB_GSL" = "C:/local323") # this is where the library is located
Sys.setenv("PKG_LIBS"="-L(LIB_GSL)/lib -lgsl -lgslcblas")
install.packages("RcppGSL")
I added the line
Sys.setenv("PKG_LIBS"="-L(LIB_GSL)/lib -lgsl -lgslcblas")
after getting the following error(and I still got the same error) after doing some research and thought there might be a linking problem(just guessing).
The error I received was
RcppExports.o:RcppExports.cpp:(.text+0x916): undefined reference to `gsl_matrix_alloc'
RcppExports.o:RcppExports.cpp:(.text+0x945): undefined reference to `gsl_matrix_set'
RcppExports.o:RcppExports.cpp:(.text+0x993): undefined reference to `gsl_vector_calloc'
fastLm.o:fastLm.cpp:(.text+0x122): undefined reference to `gsl_vector_calloc'
fastLm.o:fastLm.cpp:(.text+0x131): undefined reference to `gsl_matrix_alloc'
fastLm.o:fastLm.cpp:(.text+0x142): undefined reference to `gsl_multifit_linear_alloc'
fastLm.o:fastLm.cpp:(.text+0x16d): undefined reference to `gsl_multifit_linear'
fastLm.o:fastLm.cpp:(.text+0x175): undefined reference to `gsl_multifit_linear_free'
fastLm.o:fastLm.cpp:(.text+0x24f): undefined reference to `gsl_matrix_diagonal'
setErrorHandler.o:setErrorHandler.cpp:(.text+0x104): undefined reference to `gsl_set_error_handler_off'
setErrorHandler.o:setErrorHandler.cpp:(.text+0x133): undefined reference to `gsl_set_error_handler'
any help is greatly appreciated!
Very best,
Steve
I would try this on the command-line, ie in cmd.exe -- not from R.
That way you should see the compilation and linking steps which may help when something go south.
"It builds at CRAN ..." so with the right files in the right location, and the proper env var set it should for you too.
Well I do not know why the following worked but I'm able to use RcppGSL
I followed the procedure from the link I posted exactly. Then instead of using
install.packages("RcppGSL")
I downloaded the zip file from CRAN and installed the package via the R GUI with the option to install from a zip. These should be identical I know, but using install.packages("RcppGSL").
Also
Sys.setenv("LIB_GSL" = "C:/local323")
is required anytime I try to compile an Rcpp file that uses the library.
I'm not sure why, but I can use the library at least.
Dirk thank you for your help. I will go over the tutorial on R-extensions to see if I can figure out what is going on.

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.