New to OpenGL - how to compile? - c++

I have a file with the following imports:
// Include standard headers
#include <stdio.h>
#include <stdlib.h>
#include <vector>
// Include GLEW
#include <GL/glew.h>
// Include GLFW
#include <glfw3.h>
GLFWwindow* window;
// Include GLM
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <glm/gtx/norm.hpp>
using namespace glm;
// Include AntTweakBar
#include <AntTweakBar.h>
#include <common/shader.hpp>
#include <common/texture.hpp>
#include <common/controls.hpp>
#include <common/objloader.hpp>
#include <common/vboindexer.hpp>
#include <common/quaternion_utils.hpp> // See quaternion_utils.cpp for RotationBetweenVectors, LookAt and RotateTowards
However, when I try to compile it with
g++ -lglut -lGLU -lGL rotatetest.cpp -o hello.o
I get the following errors:
rotatetest.cpp:7:23: error: GLUT/glew.h: No such file or directory
rotatetest.cpp:10:19: error: glfw3.h: No such file or directory
rotatetest.cpp:14:23: error: glm/glm.hpp: No such file or directory
rotatetest.cpp:15:40: error: glm/gtc/matrix_transform.hpp: No such file or directory
rotatetest.cpp:16:34: error: glm/gtc/quaternion.hpp: No such file or directory
rotatetest.cpp:17:34: error: glm/gtx/quaternion.hpp: No such file or directory
rotatetest.cpp:18:36: error: glm/gtx/euler_angles.hpp: No such file or directory
rotatetest.cpp:19:28: error: glm/gtx/norm.hpp: No such file or directory
rotatetest.cpp:23:25: error: AntTweakBar.h: No such file or directory
I know this code works because a) it's from a tutorial and b) I can successfully run it when it is part of an XCode project, just not as a standalone file.
I am on Mac OS X 10.8.5. Can anyone suggest to me how I can compile this?

The include<> directives in your file ask for OpenGL-related headers in your system include directory. g++ on the command line may be using a different system include directory than XCode is.
Make sure that the extra OpenGL headers (GLFW, GLM, GLUT) are placed in your g++ installation as well.
You probably will also have to do this for the static libraries as well.

Related

Can't include SDL_ttf.h using MinGW

I'm trying to make a cookie clicker clone and when I include the SDL_ttf header file, I get an error. How do I resolve this error?
#include <iostream>
#include <SDL2\SDL.h>
#include "..\SDL2_ttf-2.0.15\i686-w64-mingw32\include\SDL2\SDL_ttf.h"
I compile with:
g++ -o test test.cpp -I../SDL2-2.0.16/i686-w64-mingw32/include -L../SDL2-2.0.16/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2
I got this error message:
In file included from test.cpp:3:0:
..\SDL2_ttf-2.0.15\i686-w64-mingw32\include\SDL2\SDL_ttf.h:34:17: fatal error: SDL.h: No such file or directory
#include "SDL.h"
I'm on a windows machine (windows 10) and using sublime.
Put the -lSDL2_ttf flag in the compile line

include botan 2 in compilation

i try include some botan header in compilation process
#include <botan/rng.h>
#include <botan/auto_rng.h>
#include <botan/cipher_mode.h>
#include <botan/hex.h>
#include <iostream>
int main(int argc, char** argv)
{
return 0;
}
I found that i need to compile with following command in order to build successfully
g++ app.cpp -I/usr/local/include/botan-2
i saw some folks execute
g++ app.cpp -lbotan-2
i tried it out but i get a error
'app.cpp:1:10: fatal error: botan/rng.h: No such file or directory
#include <botan/rng.h>
Am i missing anything ?
The following command:
g++ app.cpp -lbotan-2
links botan-2 with app.cpp but you still need to specify where to find the headers:
g++ app.cpp -I/usr/local/include/botan-2 -lbotan-2
Under my system, the headers for botan-2 are in /usr/include/botan-2. So, make sure you are giving the right path.

emscripten and boost library: how to compile existing project for webassembly?

I have an existing project written on C++ that I would like to compile for webassembly using emscripten. The code calls boost library:
#include <boost/program_options.hpp>
#include <iostream>
#include <string>
#include <exception>
#include <algorithm>
#include <iterator>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/thread/thread.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/assign.hpp>
I have compiled the necessary parts of boost library using emscripten as static libraries and converted them from bc to a-files using emar. Now I'm trying to compile the project feeding the compiler with the precompiled libraries:
(part of Makefile)
C_OPTIONS= -O3 -DNDEBUG -g \
/home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/cmdline.bc.a \
/home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/config_file.bc.a \
/home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/convert.bc.a \
/home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/libboost_program_options.bc.a \
However make still complains on the very first occurrence of boost in the code:
main.cpp:1:10: fatal error: 'boost/program_options.hpp' file not found
#include <boost/program_options.hpp>
^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
shared:ERROR: compiler frontend failed to generate LLVM bitcode, halting
The question may sound little bit naive, but how do I correctly do this? The project compiles perfectly fine with g++, but not em++
All I had to do is to make sure that boost lib presents in emscripten include directory. In my case that was emsdk/fastcomp/emscripten/system/include/ I made a symlink to system' boost library there and everything worked like a charm.
You have to add the include directories to use boost.
That would be an argument that look like this:
... -I/home/hiisi/workspace/boost_libs/include ...

C++ Shared library: Creation and usage

I am trying to build a shared object to later use a function DoSomethingUseful() from the shared object in other projects.
It uses external libraries as well as a bunch of headers that I am using across multiple projects.
Using CMake, I created a project MySharedLib with a header file called
library.h:
#ifndef MYSHAREDLIB_LIBRARY_H
#define MYSHAREDLIB_LIBRARY_H
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstdio>
// own header files
#include <header1.h>
#include <header2.h>
#define PI 3.14159265
//tesseract
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
//openCV
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
//face detection
#include "opencv2/objdetect.hpp"
#include "opencv2/imgproc.hpp"
void DoSomethingUseul(int[] inparray);
#endif
With library.cpp as
#include "library.h"
void DoSomethingUseful(int[] inparray){...}
My CMake file is as such:
cmake_minimum_required(VERSION 3.10)
project(MYSHAREDLIB)
find_package( OpenCV REQUIRED )
set(CMAKE_CXX_STANDARD 11)
set(MY_INCLUDE_DIR ../source/)
set(MY_OPENCV_CASCADES /opencvpath/openCV34/opencv/sources/data/haarcascades/)
include_directories(${MY_INCLUDE_DIR} ${MY_OPENCV_CASCADES} /usr/include)
link_directories(${MY_INCLUDE_DIR})
add_library(MYSHAREDLIB SHARED library.cpp library.h
${MY_INCLUDE_DIR}header1.cpp
${MY_INCLUDE_DIR}header1.h
${MY_INCLUDE_DIR}header2.cpp
${MY_INCLUDE_DIR}header2.h
)
set_target_properties(MYSHAREDLIB PROPERTIES VERSION 3.10)
set_target_properties(MYSHAREDLIB PROPERTIES SOVERSION 1)
target_link_libraries(MYSHAREDLIB lept tesseract ${OpenCV_LIBS})
The *.so file is created sucessfully, i. e. using Clion, no errors are thrown and the file libMySharedLib.so is there.
However, when I want to use the function DoSomethingUseful() in another file DoSomething.cpp:
#include <iostream>
#include "library.h"
using namespace std;
int main()
{
int[2] myarray; myarray[0]=1; myarray[1] =2;
DoSomethingUseful(myarray);
return 0;
}
And
g++ -g -Wall -o DoSomething DoSomething.cpp -I ../source/ -L. libMYSHAREDLIB.so
When I execute
./DoSomething
I get:
./DoSomething: error while loading shared libraries: libMYSHAREDLIB.so: cannot open shared object file: No such file or directory
Before, I compiled without -I ../source/ yielding:
In file included from DoSomething.cpp:8:0:
library.h:19:10: fatal error: header1.h: No such file or directory
#include <header1.h>
I find many threads dealing with this issue in general, and I gathered already a lot of knowledge about shared objects from those issues, also suceeding in getting examples from various tutorials running.
However, I do not suceed with my own project.
This is just one of many questions, but I hope I can get help here and maybe also general hints. Thank you a lot for any help.
Assuming Linux (amend question if wrong). When running an executable, shared libraries are loaded from paths listed in /etc/ld.so.conf only. If you want to load from somewhere else (.) , you have to set the LD_LIBRARY_PATH environment variable, e.g. LD_LIBRARY_PATH=. ./DoSomething

Compile error : fatal error: 'boost/numeric/ublas/matrix.hpp' file not found

These are the header files and libraries
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <numeric>
#include <strings.h>
#include <assert.h>
#include <dirent.h>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/c_array.hpp>
#include "mail.h"
I am trying to compile this c++ file I got using
g++ -O3 -DNDEBUG -o evaluate_object evaluate_object.cpp
The compile output
evaluate_object.cpp:13:10: fatal error: 'boost/numeric/ublas/matrix.hpp' file
not found
#include <boost/numeric/ublas/matrix.hpp>
^
1 error generated.
Ps: I run on macos sierra 10.12
I have tried install boost by these ways:
sudo port install boost
brew install boost
sudo port install boost +universal
But I still got the same problem.
I would be happy to get out of this noob zone.
I am a macos newbie too.
It seems that your "boost" includes directory is not present within environment defined include directories. You might want to specify one by passing "-I" argument to g++ command, i.e.
g++ -O3 -DNDEBUG -I/usr/local/Cellar/blahblah -o evaluate_object evaluate_object.cpp
Also your code is incomplete and perhaps if you actually call some of the boost functions you might need to add some objects for linking and then you will face "undefined reference to" error. To overcome such you need to specify "-L" flag for your g++ command.