librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

QT Linking Issues

Open cardosoraph opened this issue 8 years ago • 11 comments

project_file.txt

Required Info
Camera Model SR300
Operating System & Version Windows 10
SDK Version 2.0

Hi, I have compiled the libraries from source in Windows 10 using VisualStudio. When I link the libraries in VisualStudio 2017, it works fine and runs the examples. However, I have created a simple qt project with an empty main function, where I'm only doing a "#include <librealsense2/rs.hpp>".

By doing that and hitting compile, I get many sintax errors from rs_frame.hpp, which don't really make any sense. I'm attaching my .pro file for reference.

Regards, Raphael.

cardosoraph avatar Jan 22 '18 19:01 cardosoraph

Hello @cardosoraph, I think I already had this problem. You have to include librealsense headers before any other QT header. This should be because QT uses a custom syntax for the foreach and it cause some problems with the one used in rs_frame.hpp

Jiloc avatar Jan 23 '18 07:01 Jiloc

Hi @callendorph and @Jiloc , Can you please check if changing the foreach(...) in rs_frame.hpp into: this->foreach(...) resolves the issue without reordering the include lines?

zivsha avatar Jan 23 '18 08:01 zivsha

Unfortunately It doesn't, just to be clear, the line is this. Unfortunately also the void foreach(T action) const definition causes problems

Jiloc avatar Jan 23 '18 10:01 Jiloc

Sounds strange as the functions is nested in the rs2 namespace, is the QT foreach a macro? (Sorry for the hassle, I don't have a QT project to test this with)

zivsha avatar Jan 23 '18 11:01 zivsha

The simplest way to solve this is to rename foreach in rs_frame.hpp. There are only two places where you have to rename 'foreach' to something like 'foreachRS'

line 542 template void foreachRS(T action) const { ... }

and line 484 frame first_or_default(rs2_stream s) const { frame result; foreachRS([&result, s](frame f){ if (!result && f.get_profile().stream_type() == s) ...

This will solve the Problem.

UweDorsch avatar Jan 23 '18 11:01 UweDorsch

@zivsha yes it is a macro

Jiloc avatar Jan 23 '18 12:01 Jiloc

I see. Makes sense that it is a macro, same issue as the infamous min/max of windows. We will consider changing the name of the function to avoid such issues in the future, thanks for the help guys!

zivsha avatar Jan 23 '18 13:01 zivsha

@cardosoraph , I assume this will resolve your issue so I closed it. Please feel free to open a new issue if you need further assistance

zivsha avatar Jan 23 '18 13:01 zivsha

I am working off master, and this is still an issue when trying to work with Qt5. Can we please keep this open until it is resolved by a PR -- or explicitly closed as a wontfix?

+1 for resolving by changing the name of foreach in rs_frame.hpp

(note: this is what we have done with our local builds)

daniel-packard avatar Feb 12 '18 23:02 daniel-packard

If this is part of a public interface that people outside the librealsense library are using, maybe we can disable the macro only within the region where it is being applied to librealsense: https://stackoverflow.com/questions/1543736/how-do-i-temporarily-disable-a-macro-expansion-in-c-c

daniel-packard avatar Feb 13 '18 18:02 daniel-packard

foreach name clash with qt MACRO still persists.

Renaming librealse-defined foreach to foreachRS in rs_frame.hpp solves the problem.

bellekci avatar Jul 03 '18 15:07 bellekci