Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for enabling/disabling debug error output to cerr #75

Merged
merged 5 commits into from
Dec 10, 2020

Conversation

kalj
Copy link
Contributor

@kalj kalj commented Nov 30, 2020

Possible fix of #74.

@kalj
Copy link
Contributor Author

kalj commented Nov 30, 2020

Don't quite understand what the problem on Windows is. Unfortunately, I don't have a windows toolchain set up so I cannot troubleshoot it currently. Any help would be very much appreciated.

@traversaro
Copy link
Member

Don't quite understand what the problem on Windows is. Unfortunately, I don't have a windows toolchain set up so I cannot troubleshoot it currently. Any help would be very much appreciated.

The problem is that you are defining a static global object in public headers, and then you are not exposing it appropriately to be visible. On Linux/macOS, everything works because the default visibility for this symbols is visible (see Section 2.2.2 of https://software.intel.com/sites/default/files/m/a/1/e/dsohowto.pdf for more info). To expose symbols in Windows shared library, we use the CMake property WINDOWS_EXPORT_ALL_SYMBOLS, that however does not work with global variables, see https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/ and robotology/how-to-export-cpp-library#41 . However, looking a bit more in the PR I am afraid there some preliminary problems, I will comment inline.

Copy link
Collaborator

@S-Dafarra S-Dafarra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Here some preliminary comments

CMakeLists.txt Show resolved Hide resolved
include/OsqpEigen/Data.tpp Outdated Show resolved Hide resolved
CMakeLists.txt Outdated
@@ -59,6 +59,11 @@ endif()
option(BUILD_TESTING "Create tests using CMake" OFF)
include(CTest)

option(DEBUG_OUTPUT "Print debug error messages to cerr" ON)
if(DEBUG_OUTPUT)
add_compile_definitions("DEBUG_OUTPUT")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there may be two problems with this definition:

  • It is not prefixed by any OSQP_EIGEN_ or similar prefix, so it could be prone to macro name collision, so probably it make sense to give to it a less generic name.
  • To avoid confusion for which target this compile definition is valid, I would suggest to use target_compile_definitions instead of add_compile_definitions

src/Debug.cpp Outdated
Comment on lines 5 to 9
class NullStream : public std::ostream {
public:
NullStream() : std::ostream(nullptr) {}
NullStream(const NullStream &) : std::ostream(nullptr) {}
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definition will pollute the global symbols of the osqp-eigen library with a symbol that is not in the OsqpEigen namespace, making it prone to collisions. Could it make sense to move this in the OsqpEigen namespace?

@traversaro
Copy link
Member

Don't quite understand what the problem on Windows is. Unfortunately, I don't have a windows toolchain set up so I cannot troubleshoot it currently. Any help would be very much appreciated.

The problem is that you are defining a static global object in public headers, and then you are not exposing it appropriately to be visible. On Linux/macOS, everything works because the default visibility for this symbols is visible (see Section 2.2.2 of https://software.intel.com/sites/default/files/m/a/1/e/dsohowto.pdf for more info). To expose symbols in Windows shared library, we use the CMake property WINDOWS_EXPORT_ALL_SYMBOLS, that however does not work with global variables, see https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/ and robotology/how-to-export-cpp-library#41 . However, looking a bit more in the PR I am afraid there some preliminary problems, I will comment inline.

To clarify, probably the easiest solution is just to have a regular function that returns a reference to the std::ostream &, instead of using a global variable. Using a function instead of a global variable is also more convenient from the point of view of ABI maintenance.

@traversaro
Copy link
Member

Furthermore, can you please accept the CLA in https://cla-assistant.io/robotology/idyntree?pullRequest=700 ? Sorry for the request, but it is for internal policies.

@kalj
Copy link
Contributor Author

kalj commented Dec 3, 2020

Furthermore, can you please accept the CLA in https://cla-assistant.io/robotology/idyntree?pullRequest=700 ? Sorry for the request, but it is for internal policies.

Done!

@kalj
Copy link
Contributor Author

kalj commented Dec 3, 2020

@traversaro & @S-Dafarra Thanks for your suggestions and comments. I will prepare a fix.

@kalj
Copy link
Contributor Author

kalj commented Dec 3, 2020

The pushed commit contains fixes to the issues highlighted. I agree that a function std::ostream& debugStream() is a better solution in all regards..

@kalj kalj force-pushed the allow-disabling-debug-output branch from 345ba23 to 1c6ae06 Compare December 3, 2020 12:27
@kalj
Copy link
Contributor Author

kalj commented Dec 3, 2020

Just noted that I had tabs instead of spaces, and fixed it.

src/Settings.cpp Outdated Show resolved Hide resolved
@kalj
Copy link
Contributor Author

kalj commented Dec 9, 2020

Are we missing something here?

Copy link
Collaborator

@S-Dafarra S-Dafarra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! If @traversaro and @GiulioRomualdi agree we can move on to the merge for me.

@traversaro
Copy link
Member

Are we missing something here?

Note that depending on the notifications settings, it is possible that reviewers do not get notified if you push commits to a PR, so if you did not received feedback it may be due to that.

@GiulioRomualdi
Copy link
Member

@kalj thank you for the contribution

@GiulioRomualdi GiulioRomualdi merged commit 64cfeb6 into robotology:master Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants