c++ - 使用 clang++ 和 SDL 包含路径

标签 c++ sdl clang++

我有一个 SDL 程序,我需要在我的 Mac 上使用以下行进行编译:

#include <SDL.h>

我使用 MacPorts 安装了 libsdl,并且 sdl-config --cflags 的输出是:

-I/opt/local/include/SDL -D_GNU_SOURCE=1 -D_THREAD_SAFE

这确实是 SDL header 所在的位置:

$ ls /opt/local/include/SDL
SDL.h               SDL_cpuinfo.h           SDL_keyboard.h          SDL_rwops.h
...

然后我的 Makefile 调用编译器 (clang++):

CXXFLAGS=`sdl-config --cflags`

使用 -v 调用编译器表明它被包含在搜索路径中:

#include "..." search starts here:
#include <...> search starts here:
 /opt/local/include/SDL
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

但是编译器错误:

./drawable.h:4:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
         ^

如果我将其更改为 #include <SDL/SDL.h>,它可以正常编译,但是程序需要在其上编译的其他 (Linux) 机器不会那样指定。我对如何设置包含路径有什么不了解?

编辑:

这是一个最小的例子:

$ cat main.cpp
#include <SDL.h>
int main(int argc, char *argv[]) { }

$ sdl-config --cflags
-I/opt/local/include/SDL -D_GNU_SOURCE=1 -D_THREAD_SAFE

$ ls /opt/local/include/SDL/SDL.h
/opt/local/include/SDL/SDL.h

$ clang++ -v `sdl-config --cflags` main.cpp
...
#include "..." search starts here:
#include <...> search starts here:
 /opt/local/include/SDL
....
main.cpp:1:10: fatal error: 'SDL.h' file not found
#include <SDL.h>
         ^
1 error generated.

回答:

SDL.h原来是一个损坏的符号链接(symbolic link),我自己的错。

最佳答案

我认为在您的 Makefile 中,CXXFLAGS 未包含在编译命令中。

你的 Makefile 应该是这样的:

$(CXX) $(CXXFLAGS) $(SRC) -o $(EXE)

关于c++ - 使用 clang++ 和 SDL 包含路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32588643/

相关文章:

c++ - 为什么我的递归函数按降序打印,然后按升序打印?

c++ - 如何判断两个 LARGE unordered_map 是否相等?

c++ - 如何在 C++ 中构建包含主要入口点(如 SDL)的库

c++ - PIMPL 无法在 macOS 上编译

c++ - 与 clang++ 和 scons 链接的正确方法

c++ - 在 OpenGL 中渲染网格多边形 - 非常慢

c++ - 从 SDL_Texture 访问像素颜色

opengl - 第一次调用 opengl 时出现 sdl/opengl 段错误(macbook pro/macports)

c++ - clang++ 3.1 但在 Lion Xcode 4.3.3 上没有 `cxx_lambdas`

c++ - 引用与设置局部变量