Undefined reference when using "Hello world" of Irrlicht library [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm trying to compile the very first code given by Irrlicht library website.
As said in the title, I get an undefined reference. I'm using 8.2 netbeans IDE.
This is what I've done so far :
Installed Irrlicht library from the Linux repository (I'm using Ubuntu 18.04).
Using these command lines : sudo apt-get install libirrlicht1.8 libirrlicht1.8-dbg libirrlicht-dev libirrlicht-doc
In the "project properties", I've added the include directory, as well as the include headers (e.g all the files contained in /usr/include/irrlicht. Also, in the "Additional Options" (the linker part, I guess ?) , I've seen online that I should add -lIrrlicht command line, and it still got me the undefined reference.
I've tried also the following command line : -L /usr/include/irrlicht -lIrrlicht, still got me the undefined reference.
I know that the compiler finds the library, as it does not make a compilation error saying that it doesn't know "irrlicht.h", so the problem is coming from the linker. What command line does the linker expects ?
Note : I'm not able to make any update. Talking about irrlicht, it seems that I have 363 packages outdated. Could the problem be from there ?
Edit : Here is the minimum code, as requested. There is no point showing it, as the error comes from the linker command line :
#include <cstdlib>
#include <iostream>
#include <irrlicht.h>
using namespace std;
using namespace irr;
using namespace core;
int main(int argc, char** argv) {
IrrlichtDevice *device=createDevice(video::EDT_SOFTWARE,dimension2d<u32>(640,480),16,false,false,false,0);
return 0;
}

I had a similar problem with another library. I fixed it by changing the path in the linker?
according to https://de.wikibooks.org/wiki/Irrlicht_-_from_Noob_to_Pro:_C%2B%2B_f%C3%BCr_Irrlicht_einrichten
you have to link lIrrlicht like:
LIBS += -L/.../Irrlicht/irrlicht-1.7.1/lib/Linux
LIBS += -lIrrlicht
instead of -L /usr/include/irrlicht -lIrrlicht (for unix).
Did you try that?

Related

C++ - Undefined reference to octomap::OcTree::OcTree(double)' [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 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

Mingw and c++ vectors [duplicate]

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.

Netbeans C++ Application won't build [duplicate]

This question already has an answer here:
How to add a library include path for NetBeans and gcc on Windows?
(1 answer)
Closed 8 years ago.
I recently installed the MiniGW compiler so that I can start learning C++. But when I go to create a new project and have it include main, I get two error messages from the start(after the project has been created) Cannot Find Include File <cstdlib> and Unable to resolve identifier std and when I try and 'Clean and Build' the project, the clean is successful and the build is not. I have done a google search and ran across this post Netbeans 7.2 shows "Unable to resolve identifier" , although build is successful , but I'm not sure my problem is exactly the same since my project won't build (or maybe it is, I don't know), and I'm also not sure I understand the accepted answer. Can this be multiple problems or just one? I want to get this fixed so I can learn!
/*
* File: main.cpp
* Author: Zf
*
* Created on December 16, 2014, 1:50 PM
*/
#include <cstdlib>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
return 0;
}
Edit: Lines 7 and 8 are where the error messages are.
Have you Tool Collection set properly ?
for example
<cstdlib> is found in C:\minGW\lib\gcc\mingw32\4.8.1\include\c++
Sounds like you need to tell the compiler where to find cstdlib. See this: How to add a library include path for NetBeans and gcc on Windows?
Cstdlib contains C functions, they are not wrapped in a namespace. Remove the using namespace std; line

Eclipse CDT does not resolve variables initialized in #include files

The problem occurs when trying to use CDT for editing files in OpenFOAM, a popular computational fluid dynamics software package. I am using Eclipse Kepler SR2 Build id: 20140224-0627 and CDT 8.3.0.201402142303 The following is a simplified version of the problem.
Given the following hello.cpp
#include <iostream>
#include <string>
int main(){
#include "hello.H"
std::cout << hello << std::endl;
}
and the following hello.H
std::string hello("Hello world!");
Indexing can't resolve hello in hello.cpp. However, if I change hello.H to hello.inc it does work. This isn't a feasible solution for OpenFOAM. How could I make the indexing and autocomplete work with the given structure?
Note: I did try Eclipse Luna too, and the same happened.
Edit: I think this might be a bug. After more experimenting, the following happened. When I named the hello.H to hello.inc, the hello in hello.cpp was recognized. However, when I rebuild index it wasn't. Then I resaved hello.inc without functional changes, and behold, it was recognized again. However, if I turned off automatic indexing it no longer got resolved after rebuilding the index.
Edit 2: After further research on the problem, I found the following duplicates, without the random behavior:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=418085
and to my shame:
#include inside function body doesn't work (CDT/Eclipse C++)
Thus this question can be closed as a duplicate. To those interested, CDT indexer is not actually designed to do this, as this is bad coding style. The main message to me was that I should use some other IDE with OpenFoam.

Visual Studio 2013 Professional linker errors [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I really want to use Visual Studio Professional's debugger to take a look at a segmentation fault I encountered in my program. However, the IDE would not compile even a simple program such as this:
// test_aug.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Test" ;
return 0;
}
It keeps throwing the error "error LNK1104: cannot open file 'gdi32.lib'.
The thing is I don't want to fix this one linking error just to keep getting more for different libraries (I have also seen it for different libraries).
Can someone please tell me how to fix this error in general so I will not encounter it anymore, and can move on to ACTUALLY DEBUGGING.
If the linker cannot find that library check for its existence and/or set the path to find it into additional library directories.
The linking phase won't go on without solving that error first.
Other two thoughts:
gd123.lib sounds wrong, I believe you wanted to use gdi32.lib. Make sure the name is right
make sure that is included into the Windows SDK (express editions don't include it)