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

Use relative path in an urdf include to avoid confusion between internal and system headers #1259

Merged
merged 5 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/urdf/urdf_parser/check_urdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/* Author: Wim Meeussen */
#pragma warning(push, 0)

#include "urdf_parser/urdf_parser.h"
#include "../urdf_parser/urdf_parser.h"
#include <iostream>
#include <fstream>

Expand Down
2 changes: 1 addition & 1 deletion src/urdf/urdf_parser/joint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <urdf_model/joint.h>
// #include <console_bridge/console.h>
#include <tinyxml2.h>
#include <urdf_parser/urdf_parser.h>
#include "../urdf_parser/urdf_parser.h"

namespace urdf{

Expand Down
2 changes: 1 addition & 1 deletion src/urdf/urdf_parser/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/* Author: Wim Meeussen */
#pragma warning(push, 0)

#include <urdf_parser/urdf_parser.h>
#include "../urdf_parser/urdf_parser.h"
#include <urdf_model/link.h>
#include <fstream>
#include <sstream>
Expand Down
6 changes: 5 additions & 1 deletion src/urdf/urdf_parser/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
#pragma warning(push, 0)

#include <vector>
#include "urdf_parser/urdf_parser.h"
// Use relative path to avoid confusion with urdf system headers (if present).
// The change to the relative path is only required to be present in this
// file given how MSVC include headers. See:
// https://github.com/gazebosim/sdformat/pull/1259/files#r1149821498
#include "../urdf_parser/urdf_parser.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

There are places (e.g., link.cpp) that have #include "urdf_parser/urdf_parser.h". Do those need to change as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it is a private copy and we don't expect anyone to use these headers outside of our code, probably we don't need to. The compilation is working since the way for MSVC to include headers is curious: for the quoted form, the second priority after the same directory of the header, is

  1. In the directories of the currently opened include files, in the reverse order in which they were opened. The search begins in the directory of the parent include file and continues upward through the directories of any grandparent include files.

So if I'm not wrong the first file in the mix when compiling the library is model.cpp and it opens the right directory. That is the reason why we don't need to change more. Might be a good idea anyway to change other occurrences just in case that we (or the compiler) modifies the order of object code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is interesting and curious indeed. We should definitely add your comment in the file (maybe just model.cpp) for future readers.

Copy link
Member

Choose a reason for hiding this comment

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

+1 to a comment about why this is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done ad05aa6

// #include <console_bridge/console.h>
#include <fstream>

Expand Down
2 changes: 1 addition & 1 deletion src/urdf/urdf_parser/pose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <algorithm>
// #include <console_bridge/console.h>
#include <tinyxml2.h>
#include <urdf_parser/urdf_parser.h>
#include "../urdf_parser/urdf_parser.h"

namespace urdf_export_helpers {

Expand Down
2 changes: 1 addition & 1 deletion src/urdf/urdf_parser/urdf_to_graphiz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/* Author: Wim Meeussen */
#pragma warning(push, 0)

#include "urdf_parser/urdf_parser.h"
#include "../urdf_parser/urdf_parser.h"
#include <iostream>
#include <fstream>

Expand Down
2 changes: 1 addition & 1 deletion src/urdf/urdf_parser/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include <urdf_world/world.h>
#include <urdf_model/model.h>
#include <urdf_parser/urdf_parser.h>
#include "../urdf_parser/urdf_parser.h"
#include <fstream>
#include <sstream>
#include <algorithm>
Expand Down