如何在 Visual Studio 2013 上使用 SDL 项目正确设置 CHAI3D

How to set up CHAI3D correctly with an SDL Project on Visual Studio 2013

我目前正在开发一个使用以下库的项目: SDL2、SDL_ttf、SDL_image、SDL_mixer 和 CHAI3D。 单独使用库,代码在 VS2013 上完美运行。但是,当我尝试在同一个项目中使用这两个库时,会出现很多错误。我设法通过将它们的包含和库文件添加到 VC++ 目录来设置 SDL 库。我尝试将 #include "chai3d.h" 添加到我放在 chai3d-3.1.0\examples....\Project\c++ 文件下的这个项目中。其中returns:

fatal error C1083: Cannot open include file: 'chai3d.h': No such file or directory

因此,我将包含 "chai3d.h" 文件的文件夹的路径 (../chai3d/src) 添加到属性>配置属性>VC++ 目录>包含目录。这会跳转到以下 2 个错误:

fatal error C1083: Cannot open include file: 'Eigen/Eigen': No such file or directory

我在 chai3d/external/(Eigen/Eigen) 下找到这个文件并将其添加到包含目录中,结果如下:

fatal error C1083: Cannot open include file: 'GL/glew.h': No such file or directory

请注意,注释包含行或从外部文件夹添加路径可以解决 C1083,但会导致 chai3d 对象无法识别,例如 cHapticDeviceHandler。 这是我的部分日志:

error C2062: type 'float' unexpected error C2146

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2086: 'int cVector3d' : redefinition see declaration of 'cVector3d'

error C2143: syntax error : missing ',' before '&'

error C2146: syntax error : missing ';' before identifier 'ch_computeForceSphere'

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2086: 'int cVector3d' : redefinition

error C2143: syntax error : missing ',' before '&'...

如能提供解决此问题的任何提示,我将不胜感激。

所以我不确定同时使用这两个库(SDL 和 CHAI3D)是否有用,因为将它们组合起来产生一个有用的代码似乎太复杂了。然而,经过一些研究,我设法找到了这样做的方法:

  1. 首先您需要设置一个 chai3d 项目,而不仅仅是使用 examples 文件夹中的项目,这可以按照 link 下的说明来完成: CHAI3D: creating an application.
  2. 然后您需要通过在属性>配置属性>VC++ 目录>包含目录/库目录下添加它们的包含和库文件,以通常的方式设置您的 SDL 库。

  3. 最后在Properties>Linker>Input>Additional Dependencies下添加依赖,例如SDL2你会添加如下:

SDL2.lib
SDL2Main.lib

尽量注意SDL路径,是否需要:

 #include <SDL.h>
 or
 #include <SDL2/SDL.h>