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

Fixes for compiling in Windows #7

Merged
merged 7 commits into from
Oct 2, 2015
Merged

Fixes for compiling in Windows #7

merged 7 commits into from
Oct 2, 2015

Conversation

traversaro
Copy link
Contributor

In this PR there are three fixes for using the library in Windows (tested in Visual Studio 12/Windows 7):

  • If using Visual Studio define the M_PI constant, not defined by the C++98 standard.
  • If using Visual Studio define the round function, not defined by the C++98 standard.
  • Avoid polluting the source directory with generated files.

@hsu
Copy link
Contributor

hsu commented Feb 3, 2015

tested, works fine on ubuntu trusty.

+1

@scpeters
Copy link
Contributor

@traversaro can you resolve the conflicts? I think my changes in #14 interfere with some of your changes here.

//For using the M_PI macro in visual studio it
//is necessary to define _USE_MATH_DEFINES
#ifdef _MSC_VER
#ifndef _USE_MATH_DEFINE
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be #ifndef _USE_MATH_DEFINES? It's missing an S

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitly. Clearly it was also working with a wrong #ifndef clause, and this is the reason why I did not notice it.

@jslee02
Copy link
Contributor

jslee02 commented Sep 30, 2015

I would like to vote on this PR, and also on other fix for urdfdom.

@@ -49,6 +49,15 @@

namespace urdf{

//round is not defined in C++98
//So in Visual Studio is necessary to define it
#ifdef _MSC_VER
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that we should add a check of version on this. I guess that round was eventually implemented in some recent versions of Visual Studio for C++11 compatibility ( http://www.cplusplus.com/reference/cmath/round/ ).

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems std::round was implemented since VS2013. I found some posts that says it's not implemented until VS2012: 1, 2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember that I was developing this PR to compile a project depending on urdfdom in VS2012, so I think this is make sense.

@traversaro
Copy link
Contributor Author

I solved the conflicts (hope I did not messed up things, it is a bit late here), and I guess it is ok once we add a version check in the round and M_PI implementations.

At the moment I am bit in an hurry and I cannot solve the conflicts in the other PR, but I have added both of you @scpeters and @jslee02 as collaborators to both the forks repo, so feel free to solve the conflicts if you need this merged soon.

In Windows find_package(package) finds the PackageConfig.cmake following a set of path patterns [1]:
* <prefix>/ 
* <prefix>/(cmake|CMake)/  
* <prefix>/<name>*/ 
* <prefix>/<name>*/(cmake|CMake)/ 

This commit modifies the CMake config installation to install them in CMAKE_INSTALL_PREFIX/CMake on Windows (see for reference [2]).

[1] : https://cmake.org/cmake/help/v3.0/command/find_package.html
[2] : https://github.com/robotology/ycm/blob/master/modules/InstallBasicPackageFiles.cmake#L175
@traversaro
Copy link
Contributor Author

I also did a small modification to the directory of installation of CMake config file to make them easier to find for a default installation, see traversaro@bb40954 .

#include <string>
#include <sstream>
#include <vector>

#include <cmath>
Copy link
Contributor

Choose a reason for hiding this comment

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

<cmath> is already included on line 53

Copy link
Contributor

Choose a reason for hiding this comment

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

Removed the second one.

@scpeters
Copy link
Contributor

scpeters commented Oct 2, 2015

+1

#if (_MSC_VER <= 1700)
double round(double value)
{
return (value >= 0.0f)?(floor(value + 0.5f)):(ceil(value - 0.5f));
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of defining this, why not just add 0.5 to the arg of round and call floor() instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

they give different results:

round(0.5) = 1.0
round(-0.5) = -1.0
floor(0.5 + 0.5) = 1.0
floor(-0.5 + 0.5) = 0.0

Copy link
Contributor

Choose a reason for hiding this comment

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

good point, thanks! i guess we care about negative values :)

Copy link
Contributor

Choose a reason for hiding this comment

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

:)

isucan added a commit that referenced this pull request Oct 2, 2015
Fixes for compiling in Windows
@isucan isucan merged commit fa15fc2 into ros:master Oct 2, 2015
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.

5 participants