This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 9 months ago.
I'm trying to use the library octomap and have installed according to the instructions in their GitHub. However, when I try to build and run this simple code with VSCode build task (with g++) I get the error: undefined reference to `octomap::OcTree::OcTree(double)' and other undefined references to Octomap related code. VSCode recognizes that the library is installed (it suggests it when I type #include <...> ) and gives me more information about the octomap functions when I hover over them.
#include <iostream>
#include <octomap/octomap.h>
#include <octomap/OcTree.h>
using namespace std;
int main()
{
octomap::OcTree tree(0.1);
cout << "Hello, World!! \n";
return 0;
}
Octomap header files are in /usr/local/lib/octomap/octomap/include/octomap from what I can tell. I haven't coded with C++ a lot, so this might be just a newbie mistake that I'm missing. I've tried several approaches but still can't get it to work. What am I missing here?
Thanks in advance.
your problem is the program wasn't linked with octomap library
use cmake and include some lines like:
find_package(octomap REQUIRED)
include_directories(${OCTOMAP_INCLUDE_DIRS})
target_link_libraries(${OCTOMAP_LIBRARIES})
or from command line with g++ <source files> -loctomap -loctomath
refer : http://wiki.ros.org/octomap
Related
This question already has answers here:
the procedure entry point __gxx_personality_v0 could not be located
(5 answers)
Closed 4 years ago.
I am writing a simple small program in c++ to test vectors. The following code works well and output hello to the cmd.
The steps I follow are:
g++ filename.cpp to compile
.\a.exe to run
#include <iostream>
#include <vector>
using namespace std;
int main()
{
cout<<"hello";
return 0;
}
However, when I declare a vector, the hello does not show and the program seem to not working at all.
#include <iostream>
#include <vector>
using namespace std;
vector<int> a;
int main()
{
cout<<"hello";
return 0;
}
I do not get any error message while compiling. But I do get a certain message about no entry point when I run outside the cmd.
The procedure entry point _ZNKSt9baisc_ioslcSt11char_traitslcEEcvbEv
could not be located in the dynamic link library
I searched on google and stack overflow but could not find a solution to my problem.
For anyone who would read this later on, I had something called gtk installed and defined in the environment path variables and it seems like it was colliding with MinGW. Everything runs smooth by writing:
g++ ex1.cpp -static-libgcc -static -static-libstdc++
The problem is likely caused by the fact that the DLL containing the function the program is trying to access (_ZNKSt9baisc_ioslcSt11char_traitslcEEcvbEv here) is not found by Windows when it tries to execute your program.
There are a few solutions for this :
Static linking with the C++ library (--static-libstdc++) (this will directly link the C++ library into your executable (this may make your program bigger))
Putting the libstdc++ dll in your program folder (you should be able to find it somewhere in the compiler install folder)
Adding the path to the libstdc++ dll to the global PATH variable (If you want to know more about adding to the PATH, see here) so that the dll will be found for any executable running on your computer
Doing any of these should fix your problem.
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 4 years ago.
I am trying to create a C++ library that utilizes a third party library. My custom library compiles fine. However, when I try to test it out with a console application, the console application gives me errors from building. My setup is below:
Platform - Visual Studio Community 2017
//MyLib.h
#include <ThirdPartyLib.h>
namespace MyLib
{
class MyLibClass
{
public:
static void SomeFunction();
};
}
//MyLib.cpp
#include MyLib.h
void MyLib::MyLibClass::SomeFunction()
{
ThirdPartyLib::ThirdPartyFunction();
}
//MyConsoleApplication.cpp
#include "..\MyLib\MyLib.h"
#pragma comment(lib,"..\\Debug\\Mylib.lib")
int main()
{
MyLib::SomeFunction();
return 0;
}
My custom library is able to compile fine. When I try to compile the console application, I get a bunch of errors about the third party library like the one below.
LNK2019: unresolved external symbol 'public virtual _thiscall ThirdPartyLib::Foo::~Foo(void)' referenced in function 'private void _thiscall MyLib::MyLibClass::SomeFunction(void)'
I have given my console application the location of where it can find the third party library as well. Can anyone help?
You haven't included ThirdParyLib.lib in you program, have you? What you are getting are linker errors complaining that it cannot find the functions definitions of the functions in ThirdPartyLib.h header file.
Try this :
#pragma comment(lib,"..\\Debug\\ThirdPartyLib.lib")
Please note that ThirdPartyLib.lib is placed in the debug directory as per above example.
This question already has answers here:
undefined reference to `WinMain#16'
(7 answers)
Closed 6 years ago.
I am taking a course in c++ and I've copied the code and done exactly the same as the tutor in the course did in the lecture, however when I do so I get a long error "...undefined reference to `WinMain'" and I don't know what to do.
I am using Eclipse Neon on Windows 10 (and Cygwin, I don't know if it's relevant) and this is my code:
`
#include <iostream>
#include <SDL.h>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
`
The code works and runs without the "#include ", but when I add this line of code the error pops up when I run it (so I guess that's where the problem is). When the tutor in the course run this code it works and prints out the text correctly.
Can someone please tell me how I get rid of this error and get this simple program to run?
https://wiki.libsdl.org/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22
I get "Undefined reference to 'WinMain#16'"
Under Visual C++, you need to link with SDL2main.lib. Under the gcc
build environments including Dev-C++, you need to link with the output
of "sdl-config --libs", which is usually: -lmingw32 -lSDL2main -lSDL2
-mwindows
This question already has answers here:
fatal error: iostream.h no such file or directory [duplicate]
(3 answers)
Closed 6 years ago.
I am using Windows 8.1 and Dev C++ and I have the following code:
#include<iostream.h>
main()
{
cout<<"welcome to devc++";
system("pause");
}
The syntax is correct, but I get an error that says:
[Error] iostream.h: No such file or directory
I have tried to change to location of this .cpp folder, watched video tutorials, but I could not point out why I am getting this error and how to remove it.
You need to use #include<iostream> instead of #include<iostream.h>. The later one has been deprecated now; which is why you face the error. More details here.
Besides, main() being a function, should have a return type. So, you should write int main() and not just main().
Just do,
#include <iostream>
instead of
#include <iostream.h>
because, as C++ progressed from specific implementation to standard one,.h were deprecated from he library.
In addition to changing to
#include <iostream>
You can also add
using namespace std;
before main if you want to use cout without having to use std::cout.
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 6 years ago.
I was trying to install opencv with devc++ on my windows system. I installed opencv and then added a new compiler in devc++.
I added the following command in calling the new compiler section
-L"C:\OpenCV\lib" -lcxcore210 -lcv210 -lcvaux210 -lhighgui210 -lml210
I added the follwing command for linker command line
-lcxcore210 -lcv210 -lcvaux210 -lhighgui210 -lml210
I added the corresponding opencv binaries,libraries and includes too and added opencv/bin to environment variables.
However when i try to run follwing opencv code,
#include <iostream>
#include <conio.h>
using namespace std;
#include "cv.h"
#include "highgui.h"
using namespace cv;
int main()
{
cv::Mat img;
getch();
}
It gives the following error.
[Linker error]
C:\Users\user\AppData\Local\Temp\ccGQvgqG.o:filename.cpp:(.text$_ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x3f):
undefined reference to `cv::fastFree(void*)'
Please, do not use OpenCV 2.1.0.
Use OpenCV 2.4.13 or 3+.
As you can read in the documentation:
Prebuilt libraries [...] only works if you are coding with the latest Microsoft Visual Studio IDE.
If you want to use other compiler than Visual C++, you must build OpenCV libraries yourself. A good start is this tutorial. Take care, because they are "long-obsolete and contain inaccurate information".