DanielChappuis / reactphysics3d

Open source C++ physics engine library in 3D
http://www.reactphysics3d.com
zlib License
1.54k stars 223 forks source link

ubuntu linux installation doesn't place .h files in correct subfolders #106

Closed nattydread69 closed 4 years ago

nattydread69 commented 5 years ago

On installing on ubuntu linux 18.04 I get the following install messages

Install the project... -- Install configuration: "Release" -- Installing: /usr/local/lib/libreactphysics3d.so.0.7.1 -- Installing: /usr/local/lib/libreactphysics3d.so.0.7 -- Installing: /usr/local/lib/libreactphysics3d.so -- Installing: /usr/local/include/reactphysics3d/configuration.h -- Installing: /usr/local/include/reactphysics3d/decimal.h -- Installing: /usr/local/include/reactphysics3d/reactphysics3d.h -- Installing: /usr/local/include/reactphysics3d/Body.h -- Installing: /usr/local/include/reactphysics3d/CollisionBody.h -- Installing: /usr/local/include/reactphysics3d/RigidBody.h -- Installing: /usr/local/include/reactphysics3d/ContactPointInfo.h -- Installing: /usr/local/include/reactphysics3d/ContactManifoldInfo.h -- Installing: /usr/local/include/reactphysics3d/BroadPhaseAlgorithm.h -- Installing: /usr/local/include/reactphysics3d/DynamicAABBTree.h -- Installing: /usr/local/include/reactphysics3d/CollisionDispatch.h -- Installing: /usr/local/include/reactphysics3d/DefaultCollisionDispatch.h -- Installing: /usr/local/include/reactphysics3d/VoronoiSimplex.h -- Installing: /usr/local/include/reactphysics3d/GJKAlgorithm.h -- Installing: /usr/local/include/reactphysics3d/SATAlgorithm.h -- Installing: /usr/local/include/reactphysics3d/NarrowPhaseAlgorithm.h -- Installing: /usr/local/include/reactphysics3d/SphereVsSphereAlgorithm.h -- Installing: /usr/local/include/reactphysics3d/CapsuleVsCapsuleAlgorithm.h -- Installing: /usr/local/include/reactphysics3d/SphereVsCapsuleAlgorithm.h -- Installing: /usr/local/include/reactphysics3d/SphereVsConvexPolyhedronAlgorithm.h -- Installing: /usr/local/include/reactphysics3d/CapsuleVsConvexPolyhedronAlgorithm.h -- Installing: /usr/local/include/reactphysics3d/ConvexPolyhedronVsConvexPolyhedronAlgorithm.h -- Installing: /usr/local/include/reactphysics3d/AABB.h -- Installing: /usr/local/include/reactphysics3d/ConvexShape.h -- Installing: /usr/local/include/reactphysics3d/ConvexPolyhedronShape.h -- Installing: /usr/local/include/reactphysics3d/ConcaveShape.h -- Installing: /usr/local/include/reactphysics3d/BoxShape.h -- Installing: /usr/local/include/reactphysics3d/CapsuleShape.h -- Installing: /usr/local/include/reactphysics3d/CollisionShape.h -- Installing: /usr/local/include/reactphysics3d/ConvexMeshShape.h -- Installing: /usr/local/include/reactphysics3d/SphereShape.h -- Installing: /usr/local/include/reactphysics3d/TriangleShape.h -- Installing: /usr/local/include/reactphysics3d/ConcaveMeshShape.h -- Installing: /usr/local/include/reactphysics3d/HeightFieldShape.h -- Installing: /usr/local/include/reactphysics3d/RaycastInfo.h -- Installing: /usr/local/include/reactphysics3d/ProxyShape.h -- Installing: /usr/local/include/reactphysics3d/TriangleVertexArray.h -- Installing: /usr/local/include/reactphysics3d/PolygonVertexArray.h -- Installing: /usr/local/include/reactphysics3d/TriangleMesh.h -- Installing: /usr/local/include/reactphysics3d/PolyhedronMesh.h -- Installing: /usr/local/include/reactphysics3d/HalfEdgeStructure.h -- Installing: /usr/local/include/reactphysics3d/CollisionDetection.h -- Installing: /usr/local/include/reactphysics3d/NarrowPhaseInfo.h -- Installing: /usr/local/include/reactphysics3d/ContactManifold.h -- Installing: /usr/local/include/reactphysics3d/ContactManifoldSet.h -- Installing: /usr/local/include/reactphysics3d/MiddlePhaseTriangleCallback.h -- Installing: /usr/local/include/reactphysics3d/BallAndSocketJoint.h -- Installing: /usr/local/include/reactphysics3d/ContactPoint.h -- Installing: /usr/local/include/reactphysics3d/FixedJoint.h -- Installing: /usr/local/include/reactphysics3d/HingeJoint.h -- Installing: /usr/local/include/reactphysics3d/Joint.h -- Installing: /usr/local/include/reactphysics3d/SliderJoint.h -- Installing: /usr/local/include/reactphysics3d/CollisionWorld.h -- Installing: /usr/local/include/reactphysics3d/ConstraintSolver.h -- Installing: /usr/local/include/reactphysics3d/ContactSolver.h -- Installing: /usr/local/include/reactphysics3d/DynamicsWorld.h -- Installing: /usr/local/include/reactphysics3d/EventListener.h -- Installing: /usr/local/include/reactphysics3d/Island.h -- Installing: /usr/local/include/reactphysics3d/Material.h -- Installing: /usr/local/include/reactphysics3d/OverlappingPair.h -- Installing: /usr/local/include/reactphysics3d/Timer.h -- Installing: /usr/local/include/reactphysics3d/Timer.cpp -- Installing: /usr/local/include/reactphysics3d/CollisionCallback.h -- Installing: /usr/local/include/reactphysics3d/OverlapCallback.h -- Installing: /usr/local/include/reactphysics3d/mathematics.h -- Installing: /usr/local/include/reactphysics3d/mathematics_functions.h -- Installing: /usr/local/include/reactphysics3d/Matrix2x2.h -- Installing: /usr/local/include/reactphysics3d/Matrix3x3.h -- Installing: /usr/local/include/reactphysics3d/Quaternion.h -- Installing: /usr/local/include/reactphysics3d/Transform.h -- Installing: /usr/local/include/reactphysics3d/Vector2.h -- Installing: /usr/local/include/reactphysics3d/Vector3.h -- Installing: /usr/local/include/reactphysics3d/Ray.h -- Installing: /usr/local/include/reactphysics3d/MemoryAllocator.h -- Installing: /usr/local/include/reactphysics3d/DefaultPoolAllocator.h -- Installing: /usr/local/include/reactphysics3d/DefaultSingleFrameAllocator.h -- Installing: /usr/local/include/reactphysics3d/DefaultAllocator.h -- Installing: /usr/local/include/reactphysics3d/MemoryManager.h -- Installing: /usr/local/include/reactphysics3d/Stack.h -- Installing: /usr/local/include/reactphysics3d/LinkedList.h -- Installing: /usr/local/include/reactphysics3d/List.h -- Installing: /usr/local/include/reactphysics3d/Map.h -- Installing: /usr/local/include/reactphysics3d/Set.h -- Installing: /usr/local/include/reactphysics3d/Pair.h -- Installing: /usr/local/include/reactphysics3d/Profiler.h -- Installing: /usr/local/include/reactphysics3d/Logger.h

However when linking the library into a project it expects the header files in the subdirectories. For example:

/usr/local/include/reactphysics3d/configuration.h:36:10: fatal error: containers/Pair.h: No such file or directory

include "containers/Pair.h"

Thanks!

alexbanks-git commented 5 years ago

Hi, I also faced such a problem. The fact is that: 1)Relative paths are written in headers. 2)the structure of folders and files is broken during installation in usr/local/include for quick fix unzip this in usr/local/include/reactphysics3d reactphysics3d.zip Снимок экрана от 2019-09-26 17-17-44 sorry for my english..

DanielChappuis commented 5 years ago

Thanks for reporting this.

Can I ask you how did you install the project on Ubuntu ? Did you install it with cmake install ?

alexbanks-git commented 5 years ago

first, yes, I installed it as it is written in readme, later manually changed the headers and moved it to usr / local / include. I'm not very good at cmake, maybe later I'll try to configure it to properly install your beautiful library.

joelhays commented 5 years ago

I have the exact same issue installing in WSL Ubuntu 18.04.2 LTS. Installed very simply following the install guide:

cmake -DCMAKE_BUILD_TYPE=Release -DRP3D_COMPILE_TESTBED=OFF -DRP3D_COMPILE_TESTS=OFF -DRP3D_DOUBLE_PRECISION_ENABLED=ON
make
sudo make install

No subfolders in /usr/local/include/reactphysics3d/

Related to this, when I manually create the folder structure, the program compiles, but fails during linking while using the libreactphysics3d.a installed to /usr/local/lib

Simulation.cpp.o:(.data.rel.ro._ZTVN14reactphysics3d12CapsuleShapeE[_ZTVN14reactphysics3d12CapsuleShapeE]+0x50): undefined reference to `reactphysics3d::CapsuleShape::computeLocalInertiaTensor(reactphysics3d::Matrix3x3&, float) const'

Simulation.cpp.o:(.data.rel.ro._ZTVN14reactphysics3d8BoxShapeE[_ZTVN14reactphysics3d8BoxShapeE]+0x50): undefined reference to `reactphysics3d::BoxShape::computeLocalInertiaTensor(reactphysics3d::Matrix3x3&, float) const'

UPDATE: The linking issue was resolved by setting RP3D_DOUBLE_PRECISION_ENABLED=OFF

aliasdevelopment commented 4 years ago

I use the following diff on the cmakefile of 0.7.1:

--- CMakeLists.txt  2019-07-01 08:46:59.000000000 +0200
+++ CMakeLists.txt  2019-11-15 10:30:12.058099294 +0100
@@ -265,5 +265,10 @@
         ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
         LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
         RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
-        PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/reactphysics3d
 )
+
+INSTALL( DIRECTORY src/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/reactphysics3d )
+if( WIN32 AND NOT ${CMAKE_HOST_SYSTEM} MATCHES "inux" )
+  SET_TARGET_PROPERTIES( reactphysics3d PROPERTIES LINK_FLAGS "/ignore:4514")
+  ADD_DEFINITIONS( "/W3 /D_CRT_SECURE_NO_WARNINGS /wd4005 /wd4996 /wd4514 /nologo" )
+ENDIF()

This provides both source and headers into the CMAKE INSTALL INCLUDEDIR. Changes this as needed

DanielChappuis commented 4 years ago

Thanks for your feedback. I will try to fix this for the next release.

DanielChappuis commented 4 years ago

Hello. Thanks everyone for reporting this issue.

Yes, the issue is that cmake will copy the headers in the ${CMAKE_INSTALL_INCLUDEDIR}/reactphysics3d/ in a flat way (without the subfolders) which is not working.

I have just pushed a fix in the "master" branch that will copy the headers in the ${CMAKE_INSTALL_INCLUDEDIR}/reactphysics3d/ with the correct hierarchy of subdirectories.

Note that you might need to add the ${CMAKE_INSTALL_INCLUDEDIR}/reactphysics3d/ directory as an "include directory" for your project so that the compiler correctly finds the ReactPhysics3D headers.

This is a temporary fix. For the next release of the library, I will change a little the structure of headers in the project so that it will be installed correctly with cmake.

tomazos commented 4 years ago

I think the correct solution would be to use file-relative include directives in each internal header. That is, rather than in, say, src/body/RigidBody.h:

#include "constaint/Joint.h"

you instead write:

#include "../constaint/Joint.h"

This would mean users would not need to add an include path for this library, and it would also mean not risking collisions with some other library of your top-level folder names (eg some other library might also have an "engine/" subdirectory.)

If you would like, I have the tools to execute this refactoring relatively quickly. Would you like me to make a PR?

DanielChappuis commented 4 years ago

Can you explain why

#include "../constraint/Joint.h"

would not need an include path ? I think this won't work because if the Joint.h header file is installed at /usr/local/include/reactphysics3d/constraint/Join.h". I think that in your example, the compiler will try to find the file /usr/local/include/../constraint/Joint.h" that does not exist. Am I wrong ?

According to me, the proper way to fix this is to have all the public headers of the library in a src/include/reactphysics3d directory.

and to include the header with:

#include <reactphysics3d/Joint.h>

The Joint.h header file will then be installed at /usr/local/include/reactphysics3d/Joint.h in Ubuntu. This way, we will not need an include path because the path <reactphysics3d/Joint.h> will be found from the default include directory (in /usr/local/include/ on Ubuntu for instance).

tomazos commented 4 years ago

Can you explain why

include "../constraint/Joint.h"

would not need an include path ?

Sure - so include directives are handled by the C preprocessor. There are two kinds of include directives:

#include "foo"   // quoted
#include <foo>   // angle-brackets

For the first (quoted) form, the first place the preprocessor looks for an included file is relative to the current file.

See: https://docs.microsoft.com/en-us/cpp/preprocessor/hash-include-directive-c-cpp?view=vs-2019

and: https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

Therefore when the line:

#include "../constraint/Joint.h"

is encountered in the file:

/usr/local/include/reactphysics3d/body/RigidBody.h

The first place it will search for it is at:

/usr/local/include/reactphysics3d/body/../constaint/Joint.h

(ie relative to the body subdirectory which is the parent of the origin source file RigidBody.h)

and it will find it there.

ie the .. is to go up from the body directory.

I think you'll be happier using this technique for internal includes (that's what it's there for) because it will mean you can preserve the nested header structure in both the git repository and in the installed include folder. It reduces the risk of conflicts and it also means that you don't have to add an include path for the library.

DanielChappuis commented 4 years ago

Ok I see but with your technique, how is a user of the library supposed to include the main header file reactphysics3d.h without an "include directory directive" ?

For instance with my proposition, the user will be able to do this:

#include <reactphysics3d/reactphysics3d.h>

The compiler will then find the file at /usr/local/include/reactphysics3d/reactphysics3d.h.

tomazos commented 4 years ago

Under my proposal the user is also able to do this:

#include <reactphysics3d/reactphysics3d.h>

and it will work, as the headers are installed into the include folder with the same hierarchical/nested structure as they are in the git-repo/src folder. So:

git-repo/src/reactphysics3d.h

is installed to

/usr/include/reactphysics3d/reactphysics3d.h

Yes there needs to be an implicit or explicit include path for that to work, and there is for /usr/include, but you don't need one especially for the library - it can be and is shared by all the libraries.

ie With the current structure of the internal include directives, if you install them hierarchically then you need to add an include path just for this library (-I "/usr/include/reactphysics3d") so that the internal includes (which are git-repo/src relative like #include "constraint/Joint.h") work. My point about the include path is that you don't need to add that path if you use the technique I described of using file-relative include paths for the internal include directives (#include "../constraint/Joint.h").

Hope that makes sense now?

DanielChappuis commented 4 years ago

The version v0.8.0 of ReactPhysics3D has been released. In this version, this issue is now fixed.

Note that this version contains some public API changes. Please read carefully the change log before upgrading to this new version and do not hesitate to take a look at the user manual.

Thanks a lot for reporting this issue. I am now closing this issue.