Undefined reference to `OGRRegisterAll' - c++

I am trying to write a gdal program to read shapefiles but I don't seem to be able to get past registering the drivers. Here is the code, I'm not sure why the functions in the header files are not available my source file even after including it.
#include "/usr/include/gdal/ogrsf_frmts.h"
int main()
{
GDALAllRegister();
}
If I run this: g++ demo.cpp, I get the following error:
demo.cpp: In function int main():
demo.cpp:6:21: error: GDALAllRegister was not declared in this scope
GDALAllRegister();
^
If I try the c version, I'm getting this:
#include "/usr/include/gdal/ogr_api.h"
int main()
{
OGRRegisterAll();
return 0;
}
gcc create.c
/tmp/cc3YB8sO.o: In function main:
create.c:(.text+0x11): undefined reference to OGRRegisterAll
collect2: error: ld returned 1 exit status
UPDATE
I am using Ubuntu 15.04 64bit
I installed all the packages using the apt:
sudo apt-get install gdal-bin libgdal-dev build-essential
I also have the ubuntugis ppa added and I have qgis 2.10 installed which is from the qgis repo and not from the ubuntugis ppa.

Thank you all for the help, the issue was the linker was not able to find the gdal library.
i did this for the C code
gcc create.c -lgdal

Related

Why can't I compile the Boost.Serialization demo?

I am running Ubuntu 16.04. I'm trying to get Boost.Serialization set up, and I'm running into trouble compiling the first demo from the tutorial (titled A Very Simple Case). I have followed the Boost Getting Started page for installing Boost and building Serialization, doing the following:
download the code from SourceForge (I have tried different versions including 1.67.0 and 1.55.0)
cd boost_1_55_0
./bootstrap.sh --prefix=/usr/local --with-libraries=serialization
sudo ./b2 install
check that /usr/local/include and /usr/local/lib include the relevant Boost files
and then I compile demo.cpp using
g++ -o demo demo.cpp -I /usr/local/include/boost -l boost_serialization
and get the following error:
/tmp/cc9a7HRg.o: In function boost::archive::text_iarchive::text_iarchive(std::istream&, unsigned int)':
demo.cpp:(.text._ZN5boost7archive13text_iarchiveC2ERSij[_ZN5boost7archive13text_iarchiveC5ERSij]+0x36): undefined reference toboost::archive::detail::shared_ptr_helper::shared_ptr_helper()'
/tmp/cc9a7HRg.o: In function boost::archive::text_iarchive::~text_iarchive()':
demo.cpp:(.text._ZN5boost7archive13text_iarchiveD2Ev[_ZN5boost7archive13text_iarchiveD5Ev]+0x24): undefined reference toboost::archive::detail::shared_ptr_helper::~shared_ptr_helper()'
collect2: error: ld returned 1 exit status
The line causing the error is
boost::archive::text_iarchive ia(ifs);
It is worth mentioning that the output line
boost::archive::text_oarchive oa(ofs);
was causing a similar error before the most recent re-install. Also, if I comment out all of the input (including the line causing the error), the program compiles fine, but causes a segmentation fault upon running. I have included cout << "done" << endl; at the end of main, but it is not reached.
Does anybody know what might be causing this error? Sorry if this seems like a silly question. I am very new to C++ development. Thank you in advance!
sudo apt-get install libboost-all-dev
worked for me.
This command is taken from the same source as lboyd's solution:
https://www.technical-recipes.com/2012/getting-started-with-the-boost-libraries-in-ubuntu-linux/
then I compile with
g++ serialization.cpp -lboost_serialization -lboost_system
For anybody else running into this issue, I managed to fix it by manually uninstalling everything I had installed from source (deleting the relevant Boost files from /usr/locale/include/ and /usr/local/lib/ as well as the root Boost directory) and installing using apt-get as described here.

unidentified reference to glutInit

I tried to compile a basic OpenGL program, simply just a blank window.
I'm using CodeLite with the g++ compiler on Linux Mint 18.1 (Ubuntu 16.04 LTS).
The code so far is:
#include <stdio.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
int main(int argc, char **argv)
{
glutInit(&argc, argv);
printf("hello world\n");
return 0;
}
At first my compiler (G++ in CodeLite) gave the error
/home/USER/Projects/CodeLite/Graphical/main.cpp:7: undefined reference to `glutInit'
I downloaded all the up to date GLEW and GLUT includes from their respective websites and unpacked them to /usr/include/GL, I edited the project settings linker like this.
Now it gives the error message:
/usr/bin/ld: cannot find -lglut
Makefile:4: recipe for target 'All' failed
What can I do to fix this?
You should install the libraries from the package manager instead: libglew-dev, freeglut3-dev, libgl1-mesa-dev and libglu1-mesa-dev. The includes and binary files will be placed in the appropriate location.
If the linker cannot find the .so files, locate them with dpkg -L freeglut3-dev and add this directory in the linker command line
g++ -L/path/to/libglut.so *.o -o programname

OpenCV 3.1 Upgrade Leads to Linker Errors on Linux

I've recently upgraded from OpenCV 2.4.11 to OpenCV 3.1 by following this guide. This sudo make install seems to have worked successfully and when I run pkg-config --modversion opencv, I get the appropriate version (3.1.0).
But for some reason, I am now running into linker errors, and even simple programs are unable to compile, for example:
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char* argv[])
{
Mat im1 = imread(argv[1]);
return 0;
}
returns the errors:
main.cpp:-1: error: undefined reference to cv::imread(cv::String const&, int)
main.cpp:-1: error: undefined reference to `cv::String::allocate(unsigned long)'
main.cpp:-1: error: undefined reference to `cv::String::deallocate()'
:-1: error: collect2: error: ld returned 1 exit status
Could this be due to conflicts with the previous installation? Before I go through and start manually deleting files in /usr/local/ [lib | include | bin], I thought I'd ask here first. Any suggestions?
Your linker path is probably wrong. Make sure the opencv you want is the first one on your linker path, or it may link against the wrong one. Deleting opencv2 would probably solve the problem... consider using a package manager in future so you don't have messes like this to contend with all the time.
I went ahead and took the nuclear option (sudo rm followed by sudo make install), and everything compiles now. I'm not proud of this, nor do I necessarily advocate it, but if anyone else reaches this point of desperation, you may find this kill log helpful:
sudo rm -r /usr/share/opencv
sudo rm -r /usr/share/OpenCV/
sudo rm -r /usr/local/include/opencv
sudo rm -r /usr/local/bin/opencv*
sudo rm -r /usr/local/share/OpenCV/
sudo rm -r /usr/local/lib/libopencv_*
sudo rm /usr/local/lib/pkgconfig/opencv.pc
sudo rm /usr/local/lib/python2.7/dist-packages/cv2.so

How to set corresponding GCC flags and environment variables in Eclipse CDT

Hi i have been trying to make a c++ program of mine to work on Linux GCC
I have used a Text to speech lib called Festival 2.1
<code>
#include<iostream>
#include<stdlib.h>
#include<festival/festival.h>
using namespace std;
int main()
{
int heap_size=210000;
int load_init_files=1;
festival_initialize(load_init_files,heap_size);
festival_say_text("Hi dude, how are you ?");
festival_wait_for_spooler();
return 0;
}
</code>
This is my program.
g++ test.cpp -l Festival -I/usr/include/festival -I/usr/lib/speech_tools/include -leststring -lestools -lestbase
Using this i am able to compile successfully and exec could be created.
But, how do i set env variables etc in Eclipse CDT(ubuntu 11.10) to work using this code ..
Now i am getting the error
/home/gp/WORKSPACE-CDT/LBOT/Debug/../src/test.cpp:21: undefined reference to festival_initialize(int, int)'
/home/gp/WORKSPACE-CDT/LBOT/Debug/../src/test.cpp:22: undefined reference toEST_String::EST_String(char const*)'
/home/gp/WORKSPACE-CDT/LBOT/Debug/../src/test.cpp:22: undefined reference to festival_say_text(EST_String const&)'
/home/gp/WORKSPACE-CDT/LBOT/Debug/../src/test.cpp:23: undefined reference tofestival_wait_for_spooler()'
./src/test.o: In function EST_Chunk::operator--()':
/usr/include/speech_tools/EST_Chunk.h:140: undefined reference toEST_Chunk::~EST_Chunk()'
/usr/include/speech_tools/EST_Chunk.h:140: undefined reference to `EST_Chunk::operator delete(void*)'
collect2: ld returned 1 exit status
make: * [LBOT] Error 1
i found the solution to this.
So if anyone gets the same problem running Festival tts, it can help :)
basically the environment flags and variables can be set in eclipse through project properties and changing the toolchain settings
STEPS:
UBUNTU 11.10
GCC 4.x pre-installed
Elipse CDT was installed using terminal command
pthreads configured in eclipse using: project->preferences->c/c++ build/settings->GCC linker-> library vars add "pthreads"
Festival installed using: sudo apt-get install festival
Festival dev installed using: sudo apt-get install festival-dev festvox-don build-essential g++
Unresolved inclusion error: goto eclipse, project->preferences->c/c++ build/settings and add festival,speech_tools path to c,c++,linker directories
#include<stdio.h>
#include<festival.h>
int main(int argc,char **argv)
{
int heap_size=210000;
int load_init_files=1;
festival_initialize(load_init_files,heap_size);
festival_say_text("it is lunch time");
festival_wait_for_spooler();
return 0;
}
TERMINAL
sudo g++ main.cpp -l Festival -I/usr/include/festival -I/usr/lib/speech_tools/include -l eststring -l estools -l estbase -o nat.out
ECLIPSE
project->preferences->c/c++ build/settings->GCC linker-> library vars add 'Festival'
project->preferences->c/c++ build/settings->GCC linker-> library vars add 'eststring'
project->preferences->c/c++ build/settings->GCC linker-> library vars add 'estools'
project->preferences->c/c++ build/settings->GCC linker-> library vars add 'estbase'

Compiling error: cannot find -lGLU and -lGL in kubuntu linux

I have some problems with compiling "hello world" application in kubuntu linux 11.10. This is project file:
// opengltext.pro
SOURCES += \
main.cpp
QT += opengl
And one cpp file:
// main.cpp
#include <QApplication>
int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
return app.exec();
}
i have got the following errors:
:-1: error: cannot find -lGLU
:-1: error: cannot find -lGL
:-1: error: collect2: ld returned 1 exit status
I try find in google the solution of this problem. But didn't find.
i try to install:
sudo apt-get install libglw1-mesa-dev
but this error is still taking place
What's the problem?
You need the following 2 packages:
xlibmesa-gl-dev
xlibmesa-glu-dev
-- edit --
Thanks for correction #ephemient, these were obsolete names, right names are:
libgl1-mesa-dev
libglu1-mesa-dev
In addition to the the answer about installing the right libraries (sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev) you may need to add:
unix:LIBS += -L/usr/lib/x86_64-linux-gnu/mesa/
to your .pro file, I know I needed to. Of course that path may be different if your using 32bit software or other system dependant reasons.