« first day (742 days earlier)      last day (2102 days later) » 

5:46 AM
I know that this chatroom is for C++, but is it okay to ask for aide with a something involving javascript?
 
 
2 hours later…
7:22 AM
no
@Rithaniel There's a perfectly good JS room
Now, if you have something that's bordering on JS-C++ interop (e.g. Node.js native modules), then yes, this could be asked here
 
8:15 AM
g++ -std=c++11 main.cpp -Ilibrealsense/examples/example.hpp -lrealsense -lrealsense2 -lopencv_core -lopencv_highgui -o PROJECT_NAME && ./PROJECT_NAME
is that correct?
if example.hpp is a headerfile that i use in main.cpp
 
The option -I usually only points to directories containing files you #include
so you can drop the filename
 
do you mean g++ -std=c++11 main.cpp -Ilibrealsense/examples/example.hpp -lrealsense -lrealsense2 -lopencv_core -lopencv_highgui -o PROJECT_NAME && ./PROJECT_NAME
and
g++ -std=c++11 main.cpp -Iexample.hpp -lrealsense -lrealsense2 -lopencv_core -lopencv_highgui -o PROJECT_NAME && ./PROJECT_NAME
are equivalent?
sorry im not sure which filename you're referring to
 
no, I mean you can write -Ilibrealsense/examples if you have a line #include "example.hpp" in your main.cpp
 
ahh i see
i have #include "librealsense/examples/example.hpp"
in my main.cpp
so i guess i can?
or it's better to just have "example.hpp" in my main.cpp
 
yes. You can then drop the -Ilibrealsense/examples completely, as you have given the full relative path to the file
 
8:21 AM
hmm, i see, thanks
example.hpp contains this:
#include <GLFW/glfw3.h>
 
All in all it doesn't matter if you put the paths into the `#include` statement, or just have the filenames and give the paths with `-I`.
Go with the option that lets you organize your code better
 
i'll do it in the main.cpp, i think that's better :)
do i need to mention that in the gcc command?
 
Are you referring to how the compiler finds GLFW/glfw3.h?
 
yes sir
 
clang and gcc have predefined search paths for header files
usually pointing to the system location of installed libraries
so if you install development files fo a library with your package manager, gcc will automaticall find the headers and libraries
There is also a way to print the standard search paths in the gcc manual if you are curious
 
8:35 AM
hmm, im just not sure if my error is one with the linker or not
my project looks something like this:
-librealsense # a library that i want to use methods from
-main.cpp #my code
-makefile
and inside librealsense is examples.hpp
which starts with:
#pragma once

#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>

#include <string>
#include <sstream>
#include <iostream>
and i think the linker is having issues with:
#include <GLFW/glfw3.h>
because i get the stack trace:
In file included from main.cpp:7:
./librealsense/examples/example.hpp:246:5: warning: 'gluPerspective' is deprecated: first deprecated in macOS 10.9 - "Use GLKMatrix4MakePerspective"
[-Wdeprecated-declarations]
gluPerspective(60, width / height, 0.01f, 10.0f);
^
/System/Library/Frameworks/OpenGL.framework/Headers/glu.h:278:13: note: 'gluPerspective' has been explicitly marked deprecated here
extern void gluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) OPENGL_DEPRECATED_MSG(10_0, 10_9, "Use GLKMatrix4M...
 
hm... let me explain a bit more about what you get
It's not a stack trace, its just warnings ad errors from different stages of preprocessing, compilation and linking
 
i see, yeah you're absolutely right
 
the warnings about deprecation stem from the preprocessor
the undefined symbols from the linker
 
what is the undefined symbol?
 
the methods missing are from the OpenGL and GLU libraries
 
8:40 AM
ahh interesting
hmmm
 
so when the compiler is compiling code you are naturally using functions from libraries. A header is giving you declarations for these - Just the function name and what parameters it takes
the compiler can work with these declarations - it generates calls and creates tables what functions you called for the linker to resolve (roughly speaking)
the linker takes these tables and every library you give him and matches your called functions with the functions from the library - if you called functions it can't find in the libraries you mentioned, it errors out with "undefined symbol"
 
hmmm
so it's failing because it cant find the glTexCoord2fv methods
and those are in the OpenGL and GLU libraries
what's the solution then? are they not correctly being imported from the headerfile?
or are my libraries out of date
 
you basically have to find out which library contain those functions. If I remember correctly -lgl -lglu should fix it, as the missing functions are standard OpenGL functions (prefix "gl") and some glu functions (prefix glu) (most C libraries prefix their functions to avoid nameing comflicts)
 
g++ -std=c++11 main.cpp -lrealsense -lrealsense2 -lopencv_core -lopencv_highgui -lglu -o PROJECT_NAME && ./PROJECT_NAME
 
Header files contian only declarations - the are relevant to the compiler, but the linker doesn't know about them. Errors from the linker usually revolve around missing libraries, or libraries in the wrong format, or libraries compiled with the wrong options
 
8:46 AM
so brew install glu and brew install gl?
then the above should work?
 
probably
 
at the moment it cannot find the -lgl and -lglu libraries
awesome
 
You might need to check the library names for your platform
 
btw how do you know the names?
 
I worked with opengl once. But they differ from system to system
 
8:48 AM
what's the best way to check library names?
 
hmmmm. Most packets have a documentation, and your package manager should give you a list of installed files
 
okay so i cant seem to brew install glu
but i do have a directory in the librealsense directory
which seems to have all the src code for the methods that we cant find
ahh darn
never mind
the -lrealsense2 flag means it exists on my system somewhere right?
 
yes. Library search paths can be given with the -L option, if needed
or at least your last error message didn't contained missing symbols besides OpenGL functions
 
hmmm, do you know where the linker searches for the -lrealsense2 flag?
i dont know the name of the OpenGL functions library
and im not sure how im supposed to figure it out
brew doesnt have a OpenGL or glu install
im on OSx if that helps
 
9:05 AM
I have never touched OSX, so I can't help you there. And it appears apple decided to throw out OpenGL in their latest version. But I can't imagine that it's now impossible to develop with openGL, there might be some way.
 
i know the method declarations can be found at /System/Library/Frameworks/OpenGL.framework/headers/gl.h
ahhh darn apple
im developing this for an upboard using linux anyway
hmmmmmm
you're incredibly knowledgable btw
im impressed :D
 
I once set up a Gentoo system for myself. That way I learned a lot about how systems come together. Also I'm not touching Gentoo anymore, because prepackaged systems are fine, too.
 
 
9 hours later…
5:54 PM
hey how can I find the preceding and following element in C++ map ?
by giving a key that doesn't exist
 
2 messages moved from Lounge<C++>
std::map::lower_bound and std::map::upper_bound
 
if the key doesn't exist than it returns map.end()
instead of the preceding and following
 
no, that's std::map::find which returns end()
lower_bound and upper_bound are what you're looking for
these functions need careful tweaking to not go out of bounds, not too fun to use, but they do their job
 
You can iterate over the data inside a map... What exactly are you trying to do?
 
6:48 PM
@milleniumbug
  const int val = 3;

  std::map<unsigned int, char> mymap = {
    {0, 'a'},
    {4, 'b'},
    {5, 'g'}
  };

  auto itlow = mymap.lower_bound(val);
  auto itup = mymap.upper_bound(val);
  std::cout << itlow->first << " => " << itlow->second << '\n';
  std::cout << itup->first << " => " << itup->second << '\n';
4 => b
4 => b
that's the output
shouldn't that be
0 => a
4 => b
preceding and following?
 
> Returns an iterator pointing to the first element that is not less than key.
> Returns an iterator pointing to the first element that is greater than key.
I mean, what would you return if you had called mymap.lower_bound(-1)
 
@Mikhail thank you, I am creating an interval map
 
there is no "preceding element" in that case
check if there's one, and get it
(also, upper_bound will return end() in case you do mymap.upper_bound(6) - you have to handle this case too)
for that matter, lower_bound will return end() in corner cases too
 
  const int val = 3;

  std::map<unsigned int, char> mymap = {
    {0, 'a'},
    {4, 'b'},
    {5, 'g'}
  };

  auto itlow = mymap.lower_bound(val);
  auto itup = mymap.upper_bound(val);

  if(mymap.lower_bound(val) != mymap.begin()) {
    itlow = std::prev(itlow);
  }

  std::cout << itlow->first << " => " << itlow->second << '\n';
  std::cout << itup->first << " => " << itup->second << '\n';
not it gets preceding and following
safely
 
you need to handle -1 and 6 too
 
7:08 PM
@milleniumbug but wouldn't the problem only arise if I do std::prev or std::next on a begin() or end() respectively?
 
@Nerva what's the preceding key of -1? there's no key like that
as in, preceding key of 4 is 0, preceding key of 3 is 0, but preceding key of 0 is...?
 
7:28 PM
  const int val = 6;

  std::map<unsigned int, char> m_map = {
    {0, 'a'},
    {4, 'b'},
    {5, 'g'}
  };

  auto itPrev = m_map.lower_bound(val);// first element >=
  auto itPost = m_map.upper_bound(val);// first element >

  std::cout << (m_map.begin() == itPrev) << '\n';
  std::cout << (m_map.end() == itPrev) << '\n';
  std::cout << (m_map.begin() == itPost) << '\n';
  std::cout << (m_map.end() == itPost) << '\n';

  if(
    itPrev != m_map.begin() && itPrev != m_map.end()
  ) {
    --itPrev;
thank you for your patience
 
ok, that handles "no previous element"
not sure if it handles "no next element" though
I'd probably isolate this complexity in a separate function
 
do you believe that is better to use --itPrev or std::prev ?
  if(itPrev == m_map.begin() || itPrev == m_map.end()) {
    std::cout << "no previous element" << "\n";
  }

  if(itPost == m_map.end()) {
    std::cout << "no next element" << "\n";
  }
@milleniumbug this should detect both cases
 
yeah, I think so too
If I were you, I'd subject this code to a lot of unit testing
 
8:07 PM
  std::map<unsigned int, char> m_map = {
    {0, 'a'}
  };

  auto itLow = m_map.lower_bound(1);// first element >=
  auto itUpp = m_map.upper_bound(2);// first element >
  bool hasPrev = itLow != m_map.begin() && itLow != m_map.end();
  bool hasNext = itUpp != m_map.end();

  std::cout << (m_map.begin() == itLow) << "\n";
  std::cout << (m_map.end() == itLow) << "\n";
  std::cout << (m_map.begin() == itUpp) << "\n";
  std::cout << (m_map.end() == itUpp) << "\n\n";

  if(hasPrev) {
    --itLow;
0
1
0
1

no previous element
no next element
in this case the previous of 1 should be {0, 'a'}
 
 
1 hour later…
9:13 PM
hello. Somebody could help me to deploy my Qt program?
 
 
2 hours later…

« first day (742 days earlier)      last day (2102 days later) »