unidentified reference to glutInit - c++

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

Related

Explicit OpenCV include paths needed for simple compilation?

#include <opencv2/opencv.hpp>
int main(int argc, char *argv[])
{
return 0;
}
With a simple program, such as that #including OpenCV as above, I would have expected to compile on Ubuntu using $CXX main.cpp, but on Ubuntu 21.10 I get a "file not found" error until I provide the header path via $CXX -I /usr/include/opencv4/ hello.cpp.
Is this a bug, or is there a package I am missing? on Ubuntu 21.10 to avoid explicitly specifying the include path?

Chilkat sample, linkSample.cpp program, could not be compiled

I have downloaded "Chilkat C/C++ Library Downloads for Qt, CodeBlocks, MinGW, TDM-GCC, and MinGW-w64" version of Chilkat library in order to run above ftp c++ code.
#include <stdio.h>
#include "include/CkZip.h"
#include "include/CkFtp2.h"
#include "include/CkMailMan.h"
#include "include/CkXml.h"
#include "include/CkPrivateKey.h"
#include "include/CkRsa.h"
#include "include/CkHttp.h"
#include "include/CkMime.h"
#include "include/CkMht.h"
#include "include/CkSsh.h"
#include "include/CkSFtp.h"
void DoNothing(void)
{
// Instantiate the objects...
CkZip zip;
CkMailMan mailman;
CkFtp2 ftp2;
CkXml xml;
CkPrivateKey privKey;
CkRsa rsa;
CkHttp http;
CkMime mime;
CkMht mht;
CkSsh ssh;
CkSFtp sftp;
printf("Zip version: %s\n",zip.version());
}
int main(int argc, const char* argv[])
{
DoNothing();
return 0;
}
I have read the README fille and tried to run sample C++ sample linkSample.cpp.
for that reason I have read the linkSample.sh file which places in the Chilkat for Mingw folder.
I have worked in windows and loaded mingw and the path of g++ added to the cmd.
When I directly run the .sh folder command to the cmd I have received following error!
C:\Users\emma\Desktop\chilkat-9.5.0-x86_64-8.1.0-posix-seh-rt_v6-rev0>g++ -Wl,--enable-auto-import linkSample.cpp -o"linkSample.exe" -L. -lchilkat-9.5.0 -L/c/MinGW/lib -lcrypt32 -lws2_32 -ldnsapi
C:\Users\emma\AppData\Local\Temp\cciL4ofa.o:linkSample.cpp:(.text+0x10): undefined reference to `CkZip::CkZip()'
C:\Users\emma\AppData\Local\Temp\cciL4ofa.o:linkSample.cpp:(.text+0x1d): undefined reference to `CkMailMan::CkMailMan()'
C:\Users\emma\AppData\Local\Temp\cciL4ofa.o:linkSample.cpp:(.text+0x2a): undefined reference to `CkFtp2::CkFtp2()'
Could you guide me about compileing and running sample chilkat cpp program?
Thanks
I have change the workspace to linux and Also downloaded Chilkat "C/C++ Libraries for Linux" and copy the linkSample.cpp code to inside of it and run the following code:
g++ linkSample.cpp -Llib -lchilkat-9.5.0 -o linkSample -ldl
and the bin file have been appeared without error message. BUt, when I have tried to run executable bin file the following error message appears:
./linkSample: error while loading shared libraries: libchilkat-9.5.0.so: cannot open shared object file: No such file or directory
I want to keep my workspace in windows but I have just tried to see what happend in linux, and finally it does not work properly.
Any suggestion do you have?
Thanks

C++ Include path on x86_64-w64-mingw32-g++ with OpenGL

I am trying to get an OpenGL program working on both linux and windows.
Here's my code [file=main.cc]:
#include <iostream>
#include "GL/glew.h"
using namespace std;
int main(int argc, char *argv[]){
cout << "Hello World\n";
return 0;
}
Simple enough. I'm on Linux and using
g++ main.cc -lGL -lGLEW -lSDL2
to compile my program. It works perfectly fine and if I run ./a.out I get a Hello World on my screen.
Then I try to compile it on Linux for Windows using the command
x86_64-w64-mingw32-g++ main.cc -lGL -LGLEW -LSDL2
Then however i get the error:
main.cc:3:21: fatal error: GL/glew.h: No such file or directory
#include "GL/glew.h"
^
compilation terminated.
I've already tried adding the -I/inclulde/path option with paths like /usr/include /usr/include/GL usr/include and the like, yet nothing wants to compile.
The Libraries that I'm using (or planning to) were installed using
#apt install libgl-dev libglew-dev libsdl2-dev
Any help would be very much appreciated (although I feel this is an incredibly easy fix that I'm just too stupid to figure out on my own)

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.